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: Add ingester_chunks_flush_failures_total #12925

Merged
merged 1 commit into from
May 29, 2024

Conversation

grobinson-grafana
Copy link
Contributor

@grobinson-grafana grobinson-grafana commented May 9, 2024

What this PR does / why we need it:

This commit adds a new metric to pkg/ingester/metrics.go to count the total number of flush failures. Loki operators should create alerts on this metric to avoid periods of recurring failures from increasing memory-pressure on ingesters due to buffering of chunks.

Which issue(s) this PR fixes:
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

@CLAassistant
Copy link

CLAassistant commented May 9, 2024

CLA assistant check
All committers have signed the CLA.

@grobinson-grafana grobinson-grafana force-pushed the grobinson/add-flush-failures-counter branch from faaeb6e to 9d8a623 Compare May 9, 2024 09:51
@grobinson-grafana grobinson-grafana changed the title Add ingester_chunks_flush_failures_total feat: Add ingester_chunks_flush_failures_total May 9, 2024
@grobinson-grafana grobinson-grafana force-pushed the grobinson/add-flush-failures-counter branch from 9d8a623 to 86a749b Compare May 29, 2024 08:11
@grobinson-grafana
Copy link
Contributor Author

I tested this in dev with the following change to force the store to fail after 5 minutes:

 // If the flush isn't successful, the operation for this userID is requeued allowing this and all other unflushed
 // chunk to have another opportunity to be flushed.
 func (i *Ingester) flushChunk(ctx context.Context, ch *chunk.Chunk) error {
-       if err := i.store.Put(ctx, []chunk.Chunk{*ch}); err != nil {
+       putFunc := func(ctx context.Context, chunks []chunk.Chunk) error {
+               if time.Since(i.startedAt) > 5*time.Minute {
+                       return errors.New("failed to flush: 5 minutes have elapsed")
+               }
+               return i.store.Put(ctx, chunks)
+       }
+       if err := putFunc(ctx, []chunk.Chunk{*ch}); err != nil {
+               i.metrics.chunksFlushFailures.Inc()
                return fmt.Errorf("store put chunk: %w", err)
        }
Screenshot 2024-05-29 at 11 43 58 AM

@grobinson-grafana grobinson-grafana marked this pull request as ready for review May 29, 2024 10:44
@grobinson-grafana grobinson-grafana requested a review from a team as a code owner May 29, 2024 10:44
This commit adds a new metric to pkg/ingester/metrics.go to count
the total number of flush failures. Loki operators should create
alerts on this metric to avoid periods of recurring failures
from increasing memory-pressure on ingesters due to buffering of
chunks.

Signed-off-by: George Robinson <george.robinson@grafana.com>
@grobinson-grafana grobinson-grafana force-pushed the grobinson/add-flush-failures-counter branch from 86a749b to 2db1844 Compare May 29, 2024 10:45
@grobinson-grafana grobinson-grafana self-assigned this May 29, 2024
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit cc3694e into main May 29, 2024
59 checks passed
@cyriltovena cyriltovena deleted the grobinson/add-flush-failures-counter branch May 29, 2024 11:12
grobinson-grafana added a commit that referenced this pull request Jun 20, 2024
Signed-off-by: George Robinson <george.robinson@grafana.com>
grobinson-grafana added a commit that referenced this pull request Jul 2, 2024
…#12925) (#13274)

Signed-off-by: George Robinson <george.robinson@grafana.com>
Co-authored-by: Trevor Whitney <trevorjwhitney@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants