-
Notifications
You must be signed in to change notification settings - Fork 103
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
[KATC] Update config schema, including overlays #1772
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
88097df
Rename source column to path
RebeccaMahany 93aa764
Rename Source to SourcePaths and support multiple paths
RebeccaMahany 77a31a6
Rename query to source_query
RebeccaMahany b3f251c
Fix typos in test
RebeccaMahany 5fa2de9
Rename Platform to Filter
RebeccaMahany 03777f0
Move name inside config and make config a list of tables instead of a…
RebeccaMahany 4d68485
Merge remote-tracking branch 'upstream/main' into becca/katc-cfg-update
RebeccaMahany 2367637
Rename sourceConstraints to pathConstraints in function signature
RebeccaMahany 479571c
Add comment
RebeccaMahany e2c93da
Implement overlays
RebeccaMahany b698ac7
Cleanup
RebeccaMahany cef7a88
Merge remote-tracking branch 'upstream/main' into becca/katc-overlay
RebeccaMahany 2d276fd
Merge remote-tracking branch 'upstream/main' into becca/katc-overlay
RebeccaMahany 2efd17e
dataFunc should take queryContext instead of constraint list for grea…
RebeccaMahany 50b478e
Standardize log messages a little
RebeccaMahany 8894bc2
Add config consumer that can handle non-string values
RebeccaMahany 70ec1c9
Merge remote-tracking branch 'upstream/main' into becca/katc-overlay
RebeccaMahany 4b9b56b
Update comments for clarity
RebeccaMahany 428a872
Remove source paths from logs to avoid overly verbose logs
RebeccaMahany 8c46927
Fix comments
RebeccaMahany 606ade6
Combine table definition structs
RebeccaMahany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package keyvalueconsumer | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/kolide/launcher/ee/agent/types" | ||
) | ||
|
||
type ConfigConsumer struct { | ||
updater types.Updater | ||
} | ||
|
||
func NewConfigConsumer(updater types.Updater) *ConfigConsumer { | ||
c := &ConfigConsumer{ | ||
updater: updater, | ||
} | ||
|
||
return c | ||
} | ||
|
||
func (c *ConfigConsumer) Update(data io.Reader) error { | ||
if c == nil { | ||
return errors.New("key value consumer is nil") | ||
} | ||
|
||
var kvPairs map[string]any | ||
if err := json.NewDecoder(data).Decode(&kvPairs); err != nil { | ||
return fmt.Errorf("failed to decode key-value json: %w", err) | ||
} | ||
|
||
kvStringPairs := make(map[string]string) | ||
for k, v := range kvPairs { | ||
b, err := json.Marshal(v) | ||
if err != nil { | ||
return fmt.Errorf("unable to marshal value for `%s`: %w", k, err) | ||
} | ||
kvStringPairs[k] = string(b) | ||
} | ||
|
||
// Turn the map into a slice of key, value, ... and send it to the thing storing this data | ||
_, err := c.updater.Update(kvStringPairs) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discovered when testing with @jbeker that the existing KV consumer in this package does not work for this config because Golang won't unmarshal the config as a
map[string]string
since it's a more complex object, which makes sense.This is a quick fix, but maybe we want something cleverer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud....
Hrm. To be honest, I had to pull them down and diff them to understand the difference.
If I read this right, the difference is that in the new case, k2 is sending
map[string]any
, while the old case ismap[string]string
.The thing that seems weird, is that this is then
json.Marshal
back down tomap[string]string
I assume because the underlying ~everything expects that.So I wonder... If we're going to
json.Marshal
down to strings anyhow, is it cleaner if K2 does that for us? It might not be, it's sorta of nice of the API is just the json, and not marshalled json. But I want to ask...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this handles the error that Jeremy and I were seeing:
failed to decode key-value json: json: cannot unmarshal object into Go value of type string
.I wasn't sure if it would be cleaner for K2 to update or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going to be pretty trivial on the k2 side. And I think it's pretty trivial here.
So I think we get to decide what feels like a cleaner protocol.
Having everything as a string feels clean, but having the KATC definitions marshalled into strings feels kinda weird. 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I like it this way a little better, then -- it feels tidy that k2 doesn't need to know about the marshalling and unmarshalling to a string; launcher handles that itself for ease of storage in bucket/startup_settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's step towards a more structured interface and API between k2 and launcher. (vs what we have now, which feels like it requires a very complete knowledge of all the parts)