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

[api] support zone/env overrides in ns handler #1427

Merged
merged 3 commits into from
Mar 6, 2019

Conversation

schallert
Copy link
Collaborator

The placement APIs support zone/environment overrides via HTTP headers.
This adds that functionality to the namespace APIs so users can manage
multiple M3DB clusters from a single coordinator.

@codecov
Copy link

codecov bot commented Mar 4, 2019

Codecov Report

Merging #1427 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1427     +/-   ##
========================================
+ Coverage    70.8%   70.8%   +<.1%     
========================================
  Files         834     835      +1     
  Lines       71487   71498     +11     
========================================
+ Hits        50660   50676     +16     
+ Misses      17522   17521      -1     
+ Partials     3305    3301      -4
Flag Coverage Δ
#aggregator 82.3% <ø> (-0.1%) ⬇️
#cluster 85.8% <ø> (-0.1%) ⬇️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80.8% <ø> (ø) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74.2% <ø> (-0.1%) ⬇️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.9% <ø> (ø) ⬆️
#query 65.8% <84.6%> (ø) ⬆️
#x 76% <ø> (ø) ⬆️

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 4a8bf4a...f8508a4. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 4, 2019

Codecov Report

Merging #1427 into master will increase coverage by <.1%.
The diff coverage is 84.6%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1427     +/-   ##
========================================
+ Coverage    70.8%   70.8%   +<.1%     
========================================
  Files         834     835      +1     
  Lines       71487   71498     +11     
========================================
+ Hits        50645   50676     +31     
+ Misses      17534   17521     -13     
+ Partials     3308    3301      -7
Flag Coverage Δ
#aggregator 82.3% <ø> (ø) ⬆️
#cluster 85.8% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 80.8% <ø> (ø) ⬆️
#m3em 73.2% <ø> (ø) ⬆️
#m3ninx 74.2% <ø> (-0.1%) ⬇️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.6% <ø> (ø) ⬆️
#msg 74.9% <ø> (ø) ⬆️
#query 65.8% <84.6%> (ø) ⬆️
#x 76% <ø> (ø) ⬆️

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 d78eee5...f911a3e. Read the comment docs.

@@ -205,7 +205,8 @@ func (h *createHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

nsRegistry, err = h.namespaceAddHandler.Add(namespaceRequest)
opts := handler.NewServiceOptions("kv", r.Header, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you passing "kv" as the service name? Shouldn't it be M3DB?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't quite know what to pass here. The namespace handler doesn't really use the service value it gets passed (only placement cares about that), as namespaces are stored at _kv/$env/$key. Because it's controlling KV flags I passed kv as the "service name" but can change this to m3db if it reads less awkwardly. Even "" would probably be fine

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the reason the namespace handler doesn't use a service value is because the only service that has namespaces is M3DB. Still I think it would read a little more cleanly if we passed the M3DB constant here, and then maybe a guard statement in the namespace handler to make sure the service is set to M3DB or return an error


// Validate ensures the service options are valid.
func (opts *ServiceOptions) Validate() error {
if opts.ServiceName == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a slice of allowed service names and do that validation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble with this as well. We have the concept of "allowed services" in the placement handler: https://github.com/m3db/m3/blob/f8508a401e1055c7d7fdaee22982fd48858b3e37/src/query/api/v1/handler/placement/common.go#L151

I tried moving this to the common handler package, but it's used in a few other places in the placement handler. Since it turns out that the placement handler is the only thing that cares about service name (see above comment), I left it there since namespace doesn't need it and I didn't want to have to expose it. Can change that depending on how we feel about having to expose it or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add a new slice in this package called ValidServices or something and put every M3Coordinator/M3Aggregator/M3DB in it and call it a day. It would just be nice to know that anywhere we're using this thing that value won't be garbage

Copy link
Contributor

@richardartoul richardartoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to unblock after two nits

@schallert
Copy link
Collaborator Author

@richardartoul good call, refactored the allowed services part

func AllowedServices() []string {
svcs := make([]string, 0, len(allowedServices))
for svc, allowed := range allowedServices {
if allowed {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a little weird to me that in IsAllowedService you ignore the value of the boolean, but here you care about it? Maybe never check the boolean or use struct{}{} as the value to avoid the issue

The placement APIs support zone/environment overrides via HTTP headers.
This adds that functionality to the namespace APIs so users can manage
multiple M3DB clusters from a single coordinator.
@schallert schallert force-pushed the schallert/namespace_http_headers branch from 7a2c64e to f911a3e Compare March 6, 2019 17:29
@schallert schallert merged commit 7a38e92 into master Mar 6, 2019
@schallert schallert deleted the schallert/namespace_http_headers branch March 6, 2019 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants