-
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
Changes from all commits
3732667
8625b5f
c979702
b990eb5
e283f00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ func AppendAll(f *builder.File, promConfig *prom_config.Config) diag.Diagnostics | |
// pipeline. Additional options can be provided overriding the job name, extra | ||
// scrape targets, and predefined remote write exports. | ||
func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToCompLabelsFunc func(string) string, extraScrapeTargets []discovery.Target, remoteWriteExports *remotewrite.Exports) diag.Diagnostics { | ||
pb := newPrometheusBlocks() | ||
pb := NewPrometheusBlocks() | ||
|
||
if remoteWriteExports == nil { | ||
labelPrefix := "" | ||
|
@@ -92,7 +92,7 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC | |
scrapeForwardTo = []storage.Appendable{promMetricsRelabelExports.Receiver} | ||
} | ||
|
||
scrapeTargets := appendServiceDiscoveryConfigs(pb, scrapeConfig.ServiceDiscoveryConfigs, label) | ||
scrapeTargets := AppendServiceDiscoveryConfigs(pb, scrapeConfig.ServiceDiscoveryConfigs, label) | ||
scrapeTargets = append(scrapeTargets, extraScrapeTargets...) | ||
|
||
promDiscoveryRelabelExports := appendDiscoveryRelabel(pb, scrapeConfig.RelabelConfigs, scrapeTargets, label) | ||
|
@@ -106,15 +106,15 @@ func AppendAllNested(f *builder.File, promConfig *prom_config.Config, jobNameToC | |
diags := validate(promConfig) | ||
diags.AddAll(pb.getScrapeInfo()) | ||
|
||
pb.appendToFile(f) | ||
pb.AppendToFile(f) | ||
|
||
return diags | ||
} | ||
|
||
// appendServiceDiscoveryConfigs will loop through the service discovery | ||
// AppendServiceDiscoveryConfigs will loop through the service discovery | ||
// configs and append them to the file. This returns the scrape targets | ||
// and discovery targets as a result. | ||
func appendServiceDiscoveryConfigs(pb *prometheusBlocks, serviceDiscoveryConfig prom_discover.Configs, label string) []discovery.Target { | ||
func AppendServiceDiscoveryConfigs(pb *prometheusBlocks, serviceDiscoveryConfig prom_discover.Configs, label string) []discovery.Target { | ||
var targets []discovery.Target | ||
labelCounts := make(map[string]int) | ||
for _, serviceDiscoveryConfig := range serviceDiscoveryConfig { | ||
|
@@ -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 commentThe 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. |
||
} | ||
|
||
return targets | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"golang.org/x/exp/maps" | ||
|
||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/agent/component/prometheus/scrape" | ||
"github.com/grafana/agent/converter/diag" | ||
|
@@ -68,7 +70,9 @@ func getScrapeTargets(staticConfig prom_discovery.StaticConfig) []discovery.Targ | |
for _, labelSet := range target.Targets { | ||
for labelName, labelValue := range labelSet { | ||
targetMap[string(labelName)] = string(labelValue) | ||
targets = append(targets, targetMap) | ||
newMap := map[string]string{} | ||
maps.Copy(newMap, targetMap) | ||
targets = append(targets, newMap) | ||
Comment on lines
+73
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a subtle bug where the |
||
} | ||
} | ||
} | ||
|
This file was deleted.
This file was deleted.
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.