Skip to content
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

feat: Collect duplicate log line metrics #13084

Merged
merged 21 commits into from
Jun 26, 2024

Conversation

paul1r
Copy link
Collaborator

@paul1r paul1r commented May 30, 2024

What this PR does / why we need it:
This PR is for adding support to collect metrics and information about duplicate logs that are ingested. Previously, duplicate logs are just discarded, with no way to actually see the fact that duplicates were received, nor the quantity of the data that was discarded.

This PR adds two runtime configuration options for a tenant:
log_duplicate_metrics: To output an ingester metric named duplicate_log_bytes_total, by tenant id, which counts how many bytes were discarded due to log line(s) being duplicates.
log_duplicate_stream_info: To output details about duplicate logs to insight logs.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@paul1r paul1r requested a review from a team as a code owner May 30, 2024 15:40
@slim-bean
Copy link
Collaborator

I think rather than incrementing the metric in 2 places, is it possible instead to increment it inside the unordered head block? this is the "source of truth" if you will for if we store an exact dupe or not.

Also then we can avoid returning an error from that function which I think is changing some existing behaviors in Loki

@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label May 30, 2024
@paul1r paul1r changed the title feature: First pass at getting duplicate log line metrics feat: First pass at getting duplicate log line metrics May 30, 2024
@paul1r paul1r changed the title feat: First pass at getting duplicate log line metrics feat: Collect duplicate log line metrics Jun 7, 2024
Copy link
Contributor

@DylanGuedes DylanGuedes left a comment

Choose a reason for hiding this comment

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

sounds good, just a few small suggestions and one change necessary (the one regarding not logging anything on the manager if the new arg is false)

pkg/ingester/stream.go Outdated Show resolved Hide resolved
if dup {
if s.configs != nil {
if s.configs.LogDuplicateMetrics(s.tenant) {
s.metrics.duplicateLogBytesTotal.WithLabelValues(s.tenant).Add(float64(len(entries[i].Line)))
Copy link
Contributor

Choose a reason for hiding this comment

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

this PR adds two CLI configs, one for the metric and one for the logs. WDYT of making both working behind a single one? Asking because I can't think of a scenario were I'd want only one of them. But having both means another CLI flag to Loki.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@slim-bean Argues that we need two, which is why we added it

pkg/distributor/writefailures/manager.go Outdated Show resolved Hide resolved
Comment on lines +3781 to +3787
# Log metrics for duplicate lines received.
# CLI flag: -operation-config.log-duplicate-metrics
[log_duplicate_metrics: <boolean> | default = false]

# Log stream info for duplicate lines received
# CLI flag: -operation-config.log-duplicate-stream-info
[log_duplicate_stream_info: <boolean> | default = false]
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto: I think it makes sense to unify both into a single config.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think i would leave these separate, I think generally just the metric is useful?

pkg/ingester/stream.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@slim-bean slim-bean left a comment

Choose a reason for hiding this comment

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

LGTM!

I think my only nit would be to add a comment to each of the Append implementations which explains what the bool does

@paul1r paul1r merged commit 40ee766 into main Jun 26, 2024
61 checks passed
@paul1r paul1r deleted the paul1r/add_metrics_for_duplicate_log_line_bytes branch June 26, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants