Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make RR embeddable in other programs #1214

Merged
merged 15 commits into from
Jul 15, 2022

Conversation

khepin
Copy link
Contributor

@khepin khepin commented Jul 14, 2022

Reason for This PR

Where I work, go based apps run inside a go service container. This is a set of middleware, libraries, framework like constructs that are shared across all go apps within the organization. It handles a great deal of authn / authz concerns, shipping logs to the right place, basic telemetry etc....

On the way out, it also enhances the response with some required headers.

To do all these things it assumes that it is first in line when an HTTP request arrives.

We're trying to enable PHP / RoadRunner apps in this infrastructure while still benefitting from the years of company specific work, built into this Go container. To do this we need to

  • embed RoadRunner inside of this company service container and run it from that process
  • get hold of the HTTP plugin so we can use it to pass *http.Request instances to it and get the responses

Looking for feedback
At this point, I'm looking for feedback from the RR team on this. Because of this, I have not yet added documentation etc...
I would first like to validate that this approach is acceptable for the team before I put more effort into it.

Description of Changes

Changes here

  • bring a new type roadrunner.RoadRunner (to be changed?) that holds everything required to start and stop a roadrunner instance from code.
  • The rr serve command is updated to make use of this new code
  • The list of plugins to be used is passed as an argument to roadrunner.New this allows the caller to hold on to some of the plugins that need to be accessed in other parts of the application.
rrHttp := &httpPlugin.Plugin{}
plugins := []interface{}{
    &informer.Plugin{},
    &resetter.Plugin{},
    &logger.Plugin{},
    &metrics.Plugin{},
    &rpcPlugin.Plugin{},
    &server.Plugin{},
    &service.Plugin{},

    // http server plugin
    rrHttp,
}
rr, err := roadrunner.NewRR(*cfgFile, override, plugins)
if err != nil {
    fmt.Println("could not start RR %w", err)
}
go func () {
    rr.Serve()
}()

mockRequest := &http.Request{/*...*/}
responseRecorder := httptest.NewRecorder()
rrHttp.ServeHTTP(responseRecorder, mockRequest)

// ...
// From here on, the Go framework / service container is free to enhance / transform the 
// response in whatever way it needs

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

@rustatian rustatian changed the title Make RR embeddable in other programs feat: make RR embeddable in other programs Jul 14, 2022
@rustatian rustatian self-requested a review July 14, 2022 11:29
@rustatian rustatian added the C-enhancement Category: enhancement. Meaning improvements of current module, transport, etc.. label Jul 14, 2022
@codecov
Copy link

codecov bot commented Jul 14, 2022

Codecov Report

Merging #1214 (867b8d1) into master (bb4a2bf) will increase coverage by 1.88%.
The diff coverage is 60.31%.

@@            Coverage Diff             @@
##           master    #1214      +/-   ##
==========================================
+ Coverage   43.00%   44.89%   +1.88%     
==========================================
  Files          13       14       +1     
  Lines         658      715      +57     
==========================================
+ Hits          283      321      +38     
- Misses        354      367      +13     
- Partials       21       27       +6     
Impacted Files Coverage Δ
container/config.go 74.54% <ø> (ø)
container/container.go 100.00% <ø> (ø)
container/plugins.go 100.00% <ø> (ø)
internal/cli/serve/command.go 5.88% <0.00%> (+0.16%) ⬆️
lib/roadrunner.go 64.40% <64.40%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb4a2bf...867b8d1. Read the comment docs.

@rustatian
Copy link
Member

rustatian commented Jul 14, 2022

Hey @khepin 👋🏻 . Thanks for the PR. That is a good idea to have a RR embeddable in other apps. Some notes here:

  1. Since this is standalone functionality, could you please revert the changes in the cli.serve.command.go ? Some other apps (octane for example) depend on silent mode, which you removed (why?).
  2. You must install a golangci-lint and fix warnings: https://golangci-lint.run/usage/install/

@rustatian
Copy link
Member

rustatian commented Jul 14, 2022

Since this is an entirely standalone package inside the roadrunner repo, could you please add go.mod/sum to the roadrunner/roadrunner folder?

EDIT: not needed.

@rustatian
Copy link
Member

Ok, that was my bad idea to use a separate go.mod/sum, you won't be able to reuse the internal packages and version with build_time (which is in meta).
Version and buildtime set via -ldflags on the linking phase. But if we use a different package, we won't be able to put them. Sorry for the confusion, but let's remove the go.mod/sum.

@rustatian rustatian marked this pull request as draft July 14, 2022 15:10
@khepin khepin force-pushed the embeddable branch 2 times, most recently from 0fe8b6b to efea8cd Compare July 15, 2022 11:26
khepin and others added 10 commits July 15, 2022 13:27
- fix error style
- create module with own go.mod / go.sum
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
Signed-off-by: Seb <khepin@gmail.com>
@khepin khepin marked this pull request as ready for review July 15, 2022 12:40
- channel with the proper size

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added this to the v2.11.0 milestone Jul 15, 2022
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian self-requested a review July 15, 2022 15:15
@rustatian rustatian merged commit ee688b7 into roadrunner-server:master Jul 15, 2022
@rustatian rustatian mentioned this pull request Jul 18, 2022
6 tasks
@rustatian rustatian mentioned this pull request Aug 18, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: enhancement. Meaning improvements of current module, transport, etc..
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants