-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 metrics to range mapper #6030
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package logql | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
// expression type used in metrics | ||
const ( | ||
StreamsKey = "streams" | ||
MetricsKey = "metrics" | ||
) | ||
|
||
// parsing evaluation result used in metrics | ||
const ( | ||
SuccessKey = "success" | ||
FailureKey = "failure" | ||
NoopKey = "noop" | ||
) | ||
|
||
// MapperMetrics is the metrics wrapper used in logql mapping (shard and range) | ||
type MapperMetrics struct { | ||
DownstreamQueries *prometheus.CounterVec // downstream queries total, partitioned by streams/metrics | ||
ParsedQueries *prometheus.CounterVec // parsed ASTs total, partitioned by success/failure/noop | ||
DownstreamFactor prometheus.Histogram // per request downstream factor | ||
} | ||
|
||
func newMapperMetrics(registerer prometheus.Registerer, mapper string) *MapperMetrics { | ||
return &MapperMetrics{ | ||
DownstreamQueries: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "loki", | ||
Name: "query_frontend_shards_total", | ||
Help: "Number of downstream queries by expression type", | ||
ConstLabels: prometheus.Labels{"mapper": mapper}, | ||
}, []string{"type"}), | ||
ParsedQueries: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "loki", | ||
Name: "query_frontend_sharding_parsed_queries_total", | ||
Help: "Number of parsed queries by evaluation type", | ||
ConstLabels: prometheus.Labels{"mapper": mapper}, | ||
}, []string{"type"}), | ||
DownstreamFactor: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: "loki", | ||
Name: "query_frontend_shard_factor", | ||
Help: "Number of downstream queries per request", | ||
Buckets: prometheus.LinearBuckets(0, 16, 4), | ||
ConstLabels: prometheus.Labels{"mapper": mapper}, | ||
}), | ||
} | ||
} | ||
|
||
// downstreamRecorder wraps a vector & histogram, providing an easy way to increment downstream counts. | ||
// and unify them into histogram entries. | ||
// NOT SAFE FOR CONCURRENT USE! We avoid introducing mutex locking here | ||
// because AST mapping is single threaded. | ||
type downstreamRecorder struct { | ||
done bool | ||
total int | ||
*MapperMetrics | ||
} | ||
|
||
// downstreamRecorder constructs a recorder using the underlying metrics. | ||
func (m *MapperMetrics) downstreamRecorder() *downstreamRecorder { | ||
return &downstreamRecorder{ | ||
MapperMetrics: m, | ||
} | ||
} | ||
|
||
// Add increments both the downstream count and tracks it for the eventual histogram entry. | ||
func (r *downstreamRecorder) Add(x int, key string) { | ||
r.total += x | ||
r.DownstreamQueries.WithLabelValues(key).Add(float64(x)) | ||
} | ||
|
||
// Finish idemptotently records a histogram entry with the total downstream factor. | ||
func (r *downstreamRecorder) Finish() { | ||
if !r.done { | ||
r.done = true | ||
r.DownstreamFactor.Observe(float64(r.total)) | ||
} | ||
} |
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.
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.
Since these metric names are now shared amongst all mappers, the names should be updated to make them more general, i.e., replacing "shards" with "downstream". However, this would result in a breaking change. This is my preferred option, but don't know if there is a process for "deprecating" metric names as well as the real impact this might have on current users (e.g., dashboards would stop working, ...)
An alternative would be to remove this generalization by keeping the shard and the range mapper (and future mappers) metrics with their own exclusive names. Wdyt?
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.
We can create a PR or an issue for that and merge it during a 3.0.