-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Change config.Retrieved to allow retrieving different types, map, string, etc. #5198
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5198 +/- ##
==========================================
- Coverage 90.60% 90.56% -0.05%
==========================================
Files 187 188 +1
Lines 11061 11082 +21
==========================================
+ Hits 10022 10036 +14
- Misses 820 825 +5
- Partials 219 221 +2
Continue to review full report at Codecov.
|
@mx-psi feedback is welcome. I think this change gives us flexibility in the future and probably we should do it anyway. |
I will have a look tomorrow morning :) I saw this and it looks reasonable at a first glance, but I haven't had time to give it a proper look |
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.
This makes sense to me, I think my only objection is that it can be a bit cryptic to figure out how it works by just looking at the code, so we probably want more docs/explicitness.
The detail about the ""
path in particular should be documented; I wonder if we should have a Path
type alias with an RootPath = ""
constant and make it MergeTo(dest *Map, destPath Path)
ad3e004
to
000bb88
Compare
@mx-psi thanks for the feedback. I did revert the change to make |
4889649
to
242a043
Compare
242a043
to
164b1bc
Compare
164b1bc
to
793d283
Compare
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.
LGTM as a first step
config/mapprovider.go
Outdated
func NewRetrievedFromMap(cfgMap *Map, close CloseFunc) Retrieved { | ||
return Retrieved{Map: cfgMap, CloseFunc: close} | ||
} |
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.
@mx-psi last question here, should we go with "close" as "RetrievedOption" because literally is optional here? so we will define a "Option" and we will have WithClose
, instead of asking users to pass nil when no close needed?
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.
Sounds better, yes, it's also how we pass the function pointers on the component helpers, so we already have the precedent there.
0e79d1e
to
24c09ce
Compare
@mx-psi per the feedback from the expand PR (#4742), I changed this to "AsMap" instead of the merge. The problem with the "Merge" like patter, is that is impossible to merge (parse into a location) if the expanded value is part of an array, so in order to not have to suffer and limit the functionality to not work on arrays, I decided to go with the pattern where we return the value. |
Retrieved would have a |
Ah, I think I understand now, let me spell it out loud to confirm. Say we have: receivers:
otlp:
protocols:
grpc:
exporters:
nop
processors:
transform:
traces:
queries:
- ${env:MY_QUERY}
- keep_keys(resource.attributes, "service.name", "service.namespace", "cloud.region")
- set(name, attributes["http.route"])
service:
pipelines:
traces:
receivers: [otlp]
processors: [transform]
exporters: [nop] We then don't have a way to specify the path to the environment variable, we can't do something like |
Indeed, unless we invent a path format like you proposed, we cannot reference that env variable in the array. We can also go that path, but I feel is too hacky |
@bogdandrutu How does something like this (naming issues aside) sound? type Segment struct {
key string
index int
}
func Key(key string) Segment {return Segment{key: key, index: -1}}
func Index(idx int) Segment {return Segment{key: "", index: idx}}
type Path struct{
segments []string
}
func NewPath(segments ...Segment) Path {return Path{segments}} and then have func (r Retrieved) MergeToAt(dest *Map, path Path) {
// ...
} We don't need to support
There is still the problem of something like:
which I am not sure how/if it will be supported, even if solving the array problem. |
The last example is a substring in a string from what I understand. With the return of interface... We may be able to solve that, since we can check if it is a value that we can stringify and concat it. With the merge we need to have a way to say merge in this string between this index and that index |
I am curious about this requirement |
Yes, that's it.
So this was mentioned by @Aneurysm9 on #4742 (comment). I agree that whenever possible avoiding I think the alternatives have been explored here and at #4742 at length and in my mind, unless the "substring in a string" case is handled in some special way, it seems like the only one that does not seem prohibitively complex or limited is returning an |
To be honest, because we need to unmarshal these values into the config, there is no way you will catch errors at compilation, unless I am missing something. Also the return value depends on external sources like what you have in zookeeper, voltdb, etc.... |
That is a fair point. I still feel like it's generally better to have explicit types but because of our discussion above, I am happy with the The only missing thing in my mind to merge this PR is to deal with the Close function as an option from #5198 (comment) |
Will do that... Wanted to finish the debate about the API |
…ing, etc. Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
24c09ce
to
56b42b3
Compare
@mx-psi done, PTAL one more time if you have time before your day ends :) |
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.
Looks good!
Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com