Skip to content

fix(aggregated-metrics): correctly create logfmt string - #14124

Merged
trevorwhitney merged 6 commits into
mainfrom
svennergr/fix-bytes-in-aggregation
Sep 12, 2024
Merged

fix(aggregated-metrics): correctly create logfmt string#14124
trevorwhitney merged 6 commits into
mainfrom
svennergr/fix-bytes-in-aggregation

Conversation

@svennergr

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

The aggregated metrics added in #13731 currently create the entry to be logged in logfmt format. This PR correctly adds quotes to strings being added, and adds a util function to humanize bytes without whitespaces. Basically it moves the implementation from metrics.go to metrics_helper.go.

Aggregated metrics entries currently look like:

ts=1726132612901000000 bytes=107 B count=1 service_name=service-name

Especially notice the 107 B which breaks the "correct" logfmt format.

With this PR the entry will look like:

ts=1726132612901000000 bytes=107B count=1 service_name="service-name"
@svennergr
svennergr requested a review from a team as a code owner September 12, 2024 10:14
Comment thread pkg/logql/metrics.go
Comment on lines -246 to -249
func humanizeBytes(val uint64) string {
return strings.Replace(humanize.Bytes(val), " ", "", 1)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically just moved this to utils.HumanizeBytes

@trevorwhitney trevorwhitney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@trevorwhitney
trevorwhitney merged commit 63e84b4 into main Sep 12, 2024
@trevorwhitney
trevorwhitney deleted the svennergr/fix-bytes-in-aggregation branch September 12, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants