-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Loki: Add backend functionality to parse structured metadata from Loki #77361
Conversation
Backend code coverage report for PR #77361
|
Frontend code coverage report for PR #77361 |
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.
Very nice! Added some comments but nothing major.
pkg/tsdb/loki/api.go
Outdated
@@ -30,6 +30,8 @@ type LokiAPI struct { | |||
url string | |||
log log.Logger | |||
tracer tracing.Tracer | |||
|
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.
Does this new line has any particular purpose?
pkg/tsdb/loki/api.go
Outdated
} | ||
|
||
func makeDataRequest(ctx context.Context, lokiDsUrl string, query lokiQuery) (*http.Request, error) { | ||
func makeDataRequest(ctx context.Context, lokiDsUrl string, query lokiQuery, requestStructuredMetadata bool) (*http.Request, error) { |
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.
No need to change anything, but given the flag we set calls to "categorize labels", maybe this could have been called categorizeLabels
too?
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.
Good call!
pkg/util/converter/prom.go
Outdated
return rspErr(err) | ||
} | ||
|
||
plabelsMap, clabelsMap, err := readCategorizedStreamField(iter) |
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.
plabel
and clabel
are just too bad to read. Could these names be improved so they are easier to understand?
What is this feature?
Copy of #76350.
Loki has recently added functionality for structured metadata. This PR adds the correct parsing of structured metadata to Grafana's data source.
When the
lokiStructuredMetadata
feature flag is set, the datasource will add aX-Loki-Response-Encoding-Flags
HTTP header with the value ofcategorize-labels
. That will tell Loki to respond with structured metadata attached to each logline. Grafana's parser will parse the response into a new DataFrame field calledlabelTypes
. That field stores a JSON object for each log line containing the label name and a single character to distinguish between label types:I
will be indexed labelsP
will be parsed labelsS
will be structured metadataWhy do we need this feature?
To support structured metadata.
Special notes for your reviewer:
go build ./cmd/loki
./loki -config.file=../grafana/devenv/docker/blocks/loki/loki-config.yaml
grafana
directory:node devenv/docker/blocks/loki/data/data.js http://localhost:3100
lokiStructuredMetadata
feature flag enabled.