-
Notifications
You must be signed in to change notification settings - Fork 478
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
refactor promtail converter sd configs so they reuse prometheus conve… #5069
Conversation
…rter functionality Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
…vert package Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@@ -13,14 +13,14 @@ import ( | |||
) | |||
|
|||
func appendDiscoveryAzure(pb *prometheusBlocks, label string, sdConfig *prom_azure.SDConfig) discovery.Exports { | |||
discoveryAzureArgs := ToDiscoveryAzure(sdConfig) |
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.
these lower level functions do not need be public anymore. we can bring this back later if we need to.
@@ -154,7 +154,7 @@ func appendServiceDiscoveryConfigs(pb *prometheusBlocks, serviceDiscoveryConfig | |||
exports = appendDiscoveryLightsail(pb, common.LabelWithIndex(labelCounts["lightsail"]-1, label), sdc) | |||
} | |||
|
|||
targets = append(exports.Targets, targets...) | |||
targets = append(targets, exports.Targets...) |
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 fixes a backwards ordering that was not a functional problem but weird. Discovered when leveraging this for promtail.
@@ -53,27 +53,6 @@ func NewScrapeConfigBuilder( | |||
} | |||
} | |||
|
|||
func (s *ScrapeConfigBuilder) Validate() { |
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 is covered by the prometheus service discovery validation function and catches all unsupported sd configs not just explicitly coded ones.
pb.AppendToFile(s.f) | ||
|
||
for _, target := range targets { | ||
s.allTargetsExps = append(s.allTargetsExps, target["__expr__"]) |
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.
maybe promtail should be using the targets in the same way as prometheus but I'm not going to tackle that in this PR.
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 could, but at the same time promtail has other types that are handled as strings, so it would make it more consistent with prometheus, but less consistent with itself.
I generally prefer the method with strings rather than having a special __expr__
label or mandating the type to be an interface so that it can implement Tokenizer
. Some export types like type Rules []*Config
can not implement Tokenizer
(without a bigger refactor) so we can only do it with strings right now. The downside of strings is lack of type safety, but tests cover some of this.
But it's a more general comment, I'm happy with the implementation in this PR.
s.diags.AddAll(prometheusconvert.ValidateServiceDiscoveryConfigs(sdConfigs)) | ||
} | ||
|
||
func toDiscoveryConfig(cfg *scrapeconfig.Config) prom_discover.Configs { |
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.
let's turn the promtail SD configs into a type compatible with the current prometheus API
converter/internal/promtailconvert/internal/build/consul_agent.go
Outdated
Show resolved
Hide resolved
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! Thanks for this, I'm very happy to see the boilerplate get lighter :)
pb.AppendToFile(s.f) | ||
|
||
for _, target := range targets { | ||
s.allTargetsExps = append(s.allTargetsExps, target["__expr__"]) |
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 could, but at the same time promtail has other types that are handled as strings, so it would make it more consistent with prometheus, but less consistent with itself.
I generally prefer the method with strings rather than having a special __expr__
label or mandating the type to be an interface so that it can implement Tokenizer
. Some export types like type Rules []*Config
can not implement Tokenizer
(without a bigger refactor) so we can only do it with strings right now. The downside of strings is lack of type safety, but tests cover some of this.
But it's a more general comment, I'm happy with the implementation in this PR.
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, let's merge this once @thampiotr has had a chance to take a look.
newMap := map[string]string{} | ||
maps.Copy(newMap, targetMap) | ||
targets = append(targets, newMap) |
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 was a subtle bug where the targetMap
was being mutated. We need a copy here. This is why some test cases have the __address__
label changed. I believe this is the correct behaviour now.
Instead of adding a TODO for the static SD configs, I've implemented the conversion for them - this should work now. |
186a472
to
e283f00
Compare
#5069) * refactor promtail converter sd configs so they reuse prometheus converter functionality Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * cleanup words Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * unexport a bunch of stuff that isn't needed outside the prometheusconvert package Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * don't do SD targets in backwards order during converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * get rid of static SD boilerplate --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Co-authored-by: Piotr Gwizdala <17101802+thampiotr@users.noreply.github.com> (cherry picked from commit 89b334e)
* add tracking and comparison of latest healthy content before loading a module (#5054) * add tracking and comparison of latest healthy content before loading a module * add tracking and check for arguments in module loaders Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> (cherry picked from commit 597bb6b) * add changelog version header Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * fix(http): allow override default user-agent header for http.remote (#5059) (cherry picked from commit 1eb5817) * fix(agentctl): prevent panic when validating integration-included cfg file (#5070) * fix(agentctl): prevent panic when validating integration-included cfg file Also add unit tests to prevent regression * doc(changelog): add new BUGFIXES entry (cherry picked from commit acc06f6) * loki.process: fix deadlock in case of frequent updates (#5065) Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> (cherry picked from commit 501cf69) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * loki.process: make deadlock test condition less sensitive (#5096) Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> (cherry picked from commit 7b15144) * integrations/eventhandler: remove double-logging of events (#5100) This removes the info-level log line indicating that an event is logged. When agent logs are being collected, this makes the event appear as if it was double-collected, as the event appears both in the logs sent directly to Loki and in the agent logs. (cherry picked from commit 276355e) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * Operator: update default reloader version * misc: use github.com/grafana/river (#4949) (cherry picked from commit 9a12485) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * add more complete river identifier validation and sanitization (#4998) * use river functions to validate and sanitize river identifiers Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> (cherry picked from commit ce3fe1c) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * Converter fix identifiers (#5102) * catch some places missing river label sanitization Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> (cherry picked from commit 6991ff2) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * refactor promtail converter sd configs so they reuse prometheus conve… (#5069) * refactor promtail converter sd configs so they reuse prometheus converter functionality Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * cleanup words Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * unexport a bunch of stuff that isn't needed outside the prometheusconvert package Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * don't do SD targets in backwards order during converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * get rid of static SD boilerplate --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Co-authored-by: Piotr Gwizdala <17101802+thampiotr@users.noreply.github.com> (cherry picked from commit 89b334e) * update test for older go version ordering Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> * Add a couple more unsupported fields to the prometheus converter Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --------- Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com> Co-authored-by: Đỗ Trọng Hải <41283691+hainenber@users.noreply.github.com> Co-authored-by: Paschalis Tsilias <tpaschalis@users.noreply.github.com> Co-authored-by: Robert Fratto <robertfratto@gmail.com> Co-authored-by: Craig Peterson <192540+captncraig@users.noreply.github.com>
…rter functionality
PR Description
Use higher level functions from the prometheusconvert API for generating the service discovery river in the promtail converter. Some future work may be done to improve consuming the prometheusconvert API but this gets it all wired up in one place and saves us from modifying the promtail converter when implementing new flow discovery components.
Which issue(s) this PR fixes
Notes to the Reviewer
PR Checklist