-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add feature that can disable traffic generator metrics. #807
Merged
cody-littley
merged 3 commits into
Layr-Labs:master
from
cody-littley:metrics-blacklist
Oct 16, 2024
Merged
Changes from all commits
Commits
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
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
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"github.com/prometheus/client_golang/prometheus/collectors" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// Metrics allows the creation of metrics for the traffic generator. | ||
|
@@ -31,22 +32,39 @@ type metrics struct { | |
|
||
httpPort string | ||
logger logging.Logger | ||
|
||
metricsBlacklist []string | ||
metricsFuzzyBlacklist []string | ||
} | ||
|
||
// NewMetrics creates a new Metrics instance. | ||
func NewMetrics(httpPort string, logger logging.Logger) Metrics { | ||
func NewMetrics( | ||
httpPort string, | ||
logger logging.Logger, | ||
metricsBlacklist []string, | ||
metricsFuzzyBlacklist []string) Metrics { | ||
|
||
namespace := "eigenda_generator" | ||
reg := prometheus.NewRegistry() | ||
reg.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})) | ||
reg.MustRegister(collectors.NewGoCollector()) | ||
|
||
if metricsBlacklist == nil { | ||
metricsBlacklist = []string{} | ||
} | ||
if metricsFuzzyBlacklist == nil { | ||
metricsFuzzyBlacklist = []string{} | ||
} | ||
Comment on lines
+52
to
+57
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. nit: I don't think these are needed |
||
|
||
metrics := &metrics{ | ||
count: buildCounterCollector(namespace, reg), | ||
latency: buildLatencyCollector(namespace, reg), | ||
gauge: buildGaugeCollector(namespace, reg), | ||
registry: reg, | ||
httpPort: httpPort, | ||
logger: logger.With("component", "GeneratorMetrics"), | ||
count: buildCounterCollector(namespace, reg), | ||
latency: buildLatencyCollector(namespace, reg), | ||
gauge: buildGaugeCollector(namespace, reg), | ||
registry: reg, | ||
httpPort: httpPort, | ||
logger: logger.With("component", "GeneratorMetrics"), | ||
metricsBlacklist: metricsBlacklist, | ||
metricsFuzzyBlacklist: metricsFuzzyBlacklist, | ||
} | ||
return metrics | ||
} | ||
|
@@ -71,6 +89,7 @@ func (metrics *metrics) NewLatencyMetric(description string) LatencyMetric { | |
return &latencyMetric{ | ||
metrics: metrics, | ||
description: description, | ||
disabled: metrics.isBlacklisted(description), | ||
} | ||
} | ||
|
||
|
@@ -79,6 +98,7 @@ func (metrics *metrics) NewCountMetric(description string) CountMetric { | |
return &countMetric{ | ||
metrics: metrics, | ||
description: description, | ||
disabled: metrics.isBlacklisted(description), | ||
} | ||
} | ||
|
||
|
@@ -87,5 +107,21 @@ func (metrics *metrics) NewGaugeMetric(description string) GaugeMetric { | |
return &gaugeMetric{ | ||
metrics: metrics, | ||
description: description, | ||
disabled: metrics.isBlacklisted(description), | ||
} | ||
} | ||
|
||
// isBlacklisted returns true if the metric name is blacklisted. | ||
func (metrics *metrics) isBlacklisted(metricName string) bool { | ||
for _, blacklisted := range metrics.metricsBlacklist { | ||
if metricName == blacklisted { | ||
return true | ||
} | ||
} | ||
for _, blacklisted := range metrics.metricsFuzzyBlacklist { | ||
if strings.Contains(metricName, blacklisted) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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.
why do we need both flags?
could we just use
MetricsFuzzyBlacklist
? not sure what use cases there are where we want exact matching vs. fuzzy matching (fuzzy matching can cover all use cases we need for exact matching)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.
Fuzzy matching is needed to handle metric labels that contain DA node IDs. Exact matching is needed to disable metrics where one metric is a substring of another. For example, there are two metrics labeled
read
andread_success
. Without exact matching, we couldn't disable theread
metric without also disabling theread_success
metric.The only straight forward way to avoid having two lists would be to interpret each entry as a regex. In your opinion, would you prefer to have a single list of regex blacklist arguments, or the current pattern?
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 see. That makes sense. I think the current pattern is simpler in that case