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

Node metadata #2643

Merged
merged 9 commits into from
Jan 12, 2017
Merged

Node metadata #2643

merged 9 commits into from
Jan 12, 2017

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Jan 9, 2017

Still missing documentation, but this covers the initial stuff with filtering on /catalog/nodes and /catalog/services.

Closes #154.

Copy link
Contributor

@slackpad slackpad left a comment

Choose a reason for hiding this comment

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

This is looking great! Noted some small stuff and a couple questions.

config.Meta = map[string]string{
"": "value1",
}
if err := agent.loadMetadata(config); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good in these error cases to make sure it's failing for the reason you expect (check some part of the error string)

}

func TestAgent_validateMetaPair(t *testing.T) {
longKey := fmt.Sprintf(fmt.Sprintf("%%%ds", metaKeyMaxLength+1), "")
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a strings.Repeat() that might be a little simpler here

Success bool
}{
// valid pair
{"key", "value", true},
Copy link
Contributor

Choose a reason for hiding this comment

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

same for these - might be good to have a string that should be in the returned err (empty could mean no error)

@@ -1081,8 +1081,12 @@ func (c *Command) handleReload(config *Config) (*Config, error) {
errs = multierror.Append(errs, fmt.Errorf("Failed unloading checks: %s", err))
return nil, errs
}
if err := c.agent.unloadMetadata(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this properly roll back if an error is encountered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now this just resets the metadata map so it can't actually get an error; i'll change it to not return anything for simplicity

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that'll work though - there are other error paths in here as well, so we need a way to save the old meta, unload + reload, and restore the old meta if anything goes wrong with any part of the reload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we doing anything like that with the checks/services during the reload? it seems like they have the same problem at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait - I thought that's what the snapshot was for, but it's just for checks. Reload depends on the config read finding the errors before it starts changing state but it doesn't roll back once it starts to apply the changes. We should have readConfig() validate the metadata so it's caught early.

@@ -342,6 +342,9 @@ type Config struct {
// they are configured with TranslateWanAddrs set to true.
TaggedAddresses map[string]string

// Node metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expand this comment to explain why we elide this from the JSON (since it might be stale). This will be confusing later as to why we did this :-)

// parseMetaFilter is used to parse the ?node-meta=key:value query parameter, used for
// filtering results to nodes with the given metadata key/value
func (s *HTTPServer) parseMetaFilter(req *http.Request, key *string, value *string) {
if filter, ok := req.URL.Query()["node-meta"]; ok && len(filter) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm - wonder if we should plumb multiple queries down but have the lower-level return an error if there's more than 1 thing in the list. Might be good if we want to expand it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So for the moment, just give an error message back to be clear that only one filter at a time can be used? That seems like a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah exactly - I think the error could come from all the way down in the state store so we can support it later with just a server-side change.

NodeMetaValue: "somevalue",
}
var out structs.IndexedNodes
err := msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
Copy link
Contributor

Choose a reason for hiding this comment

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

This gets called but you don't look at the results.

NodeMetaValue: "somevalue",
}
var out structs.IndexedServices
err := msgpackrpc.CallWithCodec(codec, "Catalog.ListServices", &args, &out)
Copy link
Contributor

Choose a reason for hiding this comment

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

This gets called but you don't look at the results.


RaftIndex
}
type Nodes []*Node

// Used for filtering nodes by metadata key/value pairs
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete this struct.

@slackpad
Copy link
Contributor

LGTM - just one unused struct to remove and this is good to go (also needs doc updates).

@kyhavlov kyhavlov force-pushed the f-node-metadata branch 2 times, most recently from 6ff54b6 to 0879b89 Compare January 12, 2017 00:25
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