Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Dynamic Metadata #1077

Closed
wants to merge 4 commits into from
Closed

Dynamic Metadata #1077

wants to merge 4 commits into from

Conversation

epipho
Copy link

@epipho epipho commented Dec 25, 2014

Updated 2/28/2015

  • Added new PATCH method to the machines collection endpoint to allow changing a machines metadata via the http endpoint.
  • API uses the jsonpatch format. Multiple machines can be modified at once, including machines that are not currently part of the cluster. "add", "replace", and "remove" operations are available.
  • Metadata modified via the api is retained even if the machine leaves and rejoins the cluster.
  • Dynamic metadata (metadata set by the user via the api) is merged with Machine metadata (metadata defined by the fleet config, env variables, or flags) using the following rules
    • Any keys that exist in only one of the two collections are added to the final collection as-is
    • Any keys that exist in both, the value set in the dynamic metadata is added to the final collection.
    • Any keys that are the string zero-value in the dynamic metadata are considered deleted and are not included in the final collection. This lets a user persistently delete a value set at configuration time, even if the machine leaves and rejoins the cluster.
  • The reconcile will reschedule any units on machines that no longer meet the metadata requirements (pre-existing functionality)

Known Issues:

  • Docs not complete

@epipho
Copy link
Author

epipho commented Dec 25, 2014

TODO:

  • Change TTL to int (seconds) instead of time.Duration (ns)
  • Tests tests tests tests

@epipho
Copy link
Author

epipho commented Jan 5, 2015

I think this is ready for the first pass of reviews.

@bcwaldon
Copy link
Contributor

bcwaldon commented Jan 8, 2015

I haven't looked too far into the actual code, but I wanted to share some high-level feedback since this is likely to change some things around:

I'd like to see the PATCH endpoint implemented using JSON patch [0] rather than a custom request format. Additionally, we should consider implementing the PATCH at the root of the machines collection rather than per-machine.

What utility does the TTL on a specific key provide?

[0] http://jsonpatch.com/

@epipho
Copy link
Author

epipho commented Jan 12, 2015

Switching to JSONPatch is easy enough as is moving the PATCH at the root level to allow multiple machines to be updated at once. I'll have the changes made in a couple of days.

The original idea was to use it as kind of a health check, a process could check a node to see if it was suitable for a specific type of job and set the TTL'ed metadata. Furthur thoughts make it seem like the TTL idea is half baked / gold plating and maybe doesn't deserve to live, particularly with the new request format.

@bcwaldon
Copy link
Contributor

@epipho I do like the idea, but I'm not sure if we should try to squeeze it in right now.

@epipho
Copy link
Author

epipho commented Jan 15, 2015

@bcwaldon

  • Updated to use jsonpatch on the machines collection level. Metadata is now updated with the path format /machineid/metadata/key using the add/remove/replace ops.
[{"op": "add", "path": "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/metadata/foo", "value": "bar"},
     {"op": "replace", "path": "/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/metadata/ping", "value": "splat"}]
  • TTL feature has been stashed away for another day
  • Error handling: Currently the handler does as much as it can to validate the patch data before doing any work. Invalid ops, bad path format, or missing values will cause the request to fail with no effect on the data. If an error occurs during the apply phase, the request terminates immediately and returns the error. Because the changes cannot be made atomic as the metadata keys are split apart this could (rarely) result in a partial patch being applied. Any suggestions on how to handle this or what information should be returned to the caller when this happens?

@epipho epipho changed the title [WIP] Dynamic Metadata Dynamic Metadata Jan 28, 2015
@epipho
Copy link
Author

epipho commented Jan 28, 2015

Removing WIP. Ready for initial review and comments.

@umiller
Copy link

umiller commented Jan 29, 2015

How do I test the dynamic metadata?
I am looking for a safe way to change the CoreOs machine metadata in run-time
Is this feature is the only way? (I blocked CoreOs updates on my cluster..)

@@ -39,6 +39,8 @@ type Registry interface {
SetUnitTargetState(name string, state job.JobState) error
SetMachineState(ms machine.MachineState, ttl time.Duration) (uint64, error)
UnscheduleUnit(name, machID string) error
UpdateMachineMetadata(machID string, key string, value string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call this SetMachineMetadata, since Update can mean the key must already exist in some contexts.

And there's no need to respecify string three times, just use SetMachineMetadata(machID, key, value string)

@bcwaldon
Copy link
Contributor

@epipho In addition to the inline comments, I have a concern about how the metadata is initially making it into etcd. Machines leave and rejoin the cluster frequently, so metadata that was manually added by someone through etcd will get blown away. I wonder if the metadata published by a given machine should be managed independently from the metadata added through etcd? I think it makes sense for metadata manually added through etcd directly should persist until it is manually removed.

@epipho
Copy link
Author

epipho commented Jan 30, 2015

@bcwaldon Thank you for taking the time to do a very thorough review. I will address all the small stuff this weekend.

As for your question above:

Wouldn't that be true today since a machine leaving the cluster removes the /machineid/object value that currently holds the metadata?

I'm not sure how to best handle your request, I outlined a few possibilities below.

  1. Metadata that is configured via fleet config (file, env variable, cloud config) is automatic, removed by machine leave, and cannot be manipulated at all. All other metdata values are untouched.

  2. Metadata configured by fleet config can be manipulated, but will be reset by the machine rejoining. All metadata values are untouched when a machine leaves.

  3. Metadata configured by fleet config is only added if the machine does not exist in the registry at all. All metadata values are untouched when a machine leaves.

  4. Same as 3, but all metadata is removed when a machine leaves (as currently written).

I worry that separating the metadata will be confusing as some will be able to be manipulated via the api and some will not. Of all the suggestions outlined I like 3, treating the configured values as defaults if the machine has never been seen before but leaving it untouched otherwise.

@bcwaldon
Copy link
Contributor

@epipho It's not clear to me how it should work, so I'd like to get an opinion from @jonboulle on this.

@Telvary
Copy link

Telvary commented Jul 29, 2015

+1 !

@rushmorem
Copy link

@epipho @bcwaldon @jonboulle What's the status on this?

@chr0n1x
Copy link

chr0n1x commented Sep 8, 2015

bump

@SamuelMarks
Copy link

👍

@dalbani
Copy link
Contributor

dalbani commented May 23, 2016

It has been a while since this issue has seen some activity.
This feature would be of great use!

@dongsupark dongsupark force-pushed the master branch 2 times, most recently from 14580b0 to 63b20dc Compare June 22, 2016 10:22
@dalbani
Copy link
Contributor

dalbani commented Jun 25, 2016

Hi @epipho, I've been running your code for a month now and it works just fine. Thanks for your contribution!
I was wondering where I could find the code where you implemented the support for TTL?

@dalbani
Copy link
Contributor

dalbani commented Jun 28, 2016

There's one point I was wondering about lately: the inability to set a property with an empty value.
For example, sending a PATCH request as:
[ { "op": "add", "path": "/e7afc665c2dc4a4b82082cd654fc6555/metadata/test", "value": "" } ]
Returns:
{"error":{"code":400,"message":"invalid value: add and replace require a value"}}

Aren't empty properties valid if configured via /etc/fleet/fleet.conf?

@dongsupark dongsupark force-pushed the master branch 3 times, most recently from 23d4b13 to 6fb1256 Compare July 1, 2016 11:07
@dongsupark dongsupark force-pushed the master branch 2 times, most recently from 54409ab to a1a21b8 Compare July 8, 2016 11:38
@dongsupark
Copy link
Contributor

Just a short note:
My thought about this PR is simply, "sure, why not?".
It sounds good in general. With code reviews and writing additional tests, we might merge it. I don't think anyone is against this one.
But when I tried to rebase it on top of current master, I somehow gave up. It's a little messy. Especially the newline characters at the end of every line in the document... OMG.
If someone could rebase it for me, I would really appreciate, be happy to review the code, and test it too.

@dalbani
Copy link
Contributor

dalbani commented Jul 14, 2016 via email

@dalbani
Copy link
Contributor

dalbani commented Jul 15, 2016

Well, easier said than done, not being a GitHub expert...
I have imported this PR's code into a branch in my own repo, and made it up to date with master: https://github.com/dalbani/fleet/tree/dynamic-metadata
Am I supposed to submit a new pull request then?

@dongsupark
Copy link
Contributor

@dalbani Yes, please create a new PR. That would be appropriate, as the original author doesn't seem to be active any more. I'll try to review & test that next week.
Actually what I wanted was rebasing this branch on top of master, not merging master into the branch. Anyway let's discuss about that, looking into the new PR.

@dalbani
Copy link
Contributor

dalbani commented Jul 16, 2016

I have rebased on top of master, instead of merging, and created the new PR #1642.

@dongsupark
Copy link
Contributor

Closed in favor of #1642. Thanks.

@dongsupark dongsupark closed this Jul 20, 2016
dongsupark pushed a commit to dongsupark/fleet that referenced this pull request Nov 10, 2016
dongsupark pushed a commit to dongsupark/fleet that referenced this pull request Nov 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet