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

chore: [k190] fix: promtail; clean up metrics generated from logs after a config reload. #12938

Merged
merged 1 commit into from
May 10, 2024

Conversation

grafanabot
Copy link
Collaborator

Backport 39a7181 from #11882


It is possible to generate metrics from log lines in Promtail. If the config file is reloaded, those metrics are currently not cleaned up. This causes a few issues:

  • If a metric is not necessary anymore, it is still visible on the /metrics endpoint.
  • A metric with the same name might have a different meaning after the config file reload, so it'd make sense to clean these up.

This will help us fix a bug reported in the Grafana Agent.

I suppose no changelog entry is required because PromQL is already designed to handle counter resets? But if you think it's appropriate, I could add a changelog entry?

I tested this change locally using a config file like this:

Promtail config
server:
  http_listen_port: 9080
  grpc_listen_port: 0
  enable_runtime_reload: true
positions:
  filename: /Users/paulintodev/Desktop/log_metrics_bug/tmp_promtail/positions
clients:
  - url: "https://logs-prod-008.grafana.net/loki/api/v1/push"
    basic_auth:
      username: ""
      password: ""
scrape_configs:
- job_name: log files
  static_configs:
  - labels:
      __path__: /Users/paulintodev/Desktop/log_metrics_bug/*.log
  pipeline_stages:
    - metrics:
        log_lines_total:
          type: Counter
          description: "total number of log lines"
          prefix: my_promtail_custom_
          max_idle_duration: 24h
          config:
            match_all: true
            action: inc
        log_lines_total2:
          type: Counter
          description: "total number of log lines"
          prefix: my_promtail_custom2_
          max_idle_duration: 24h
          config:
            match_all: true
            action: inc

Then I'd do a curl localhost:9080/reload and check http://localhost:9080/metrics.

I didn't add a whole lot of unit tests because TBH we should probably focus on adding tests in the Agent, given that we're sunsetting Promtail over time.

@grafanabot grafanabot requested a review from a team as a code owner May 10, 2024 18:12
@grafanabot grafanabot added backport size/L type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories labels May 10, 2024
@grafanabot grafanabot requested a review from cstyan May 10, 2024 18:12
Copy link
Contributor

Snyk scan found the following vulnerabilities:

  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
  • high - [CVE-2023-45288] Allocation of Resources Without Limits or Throttling in golang.org/x/net/http2 v0.17.0. Fixed in ["0.23.0"]
    \nTo see more details on these vulnerabilities, and how/where to fix them, please run docker build -t grafana/loki:HEAD-1ded2f6 -f cmd/loki/Dockerfile .
    ./tools/ensure-buildx-builder.sh on your branch. If these were not introduced by your PR, please considering fixing them in via a subsequent PR. Thanks!

Copy link
Contributor

Trivy scan found the following vulnerabilities:

@MasslessParticle MasslessParticle merged commit cef4c28 into k190 May 10, 2024
14 checks passed
@MasslessParticle MasslessParticle deleted the backport-11882-to-k190 branch May 10, 2024 18:37
ptodev added a commit to grafana/alloy that referenced this pull request May 13, 2024
thampiotr pushed a commit to grafana/alloy that referenced this pull request May 14, 2024
* Update Loki dependency.

* Clean up metrics generated from logs after a config reload.

Synced from:
grafana/loki#12938
ptodev added a commit to grafana/agent that referenced this pull request May 14, 2024
ptodev added a commit to grafana/agent that referenced this pull request May 15, 2024
ptodev added a commit to grafana/agent that referenced this pull request May 15, 2024
* Update Loki dependency.

* Clean up metrics generated from logs after a config reload.

Synced from:
grafana/loki#12938

* Update README
ptodev added a commit to grafana/agent that referenced this pull request May 15, 2024
* Update Loki dependency.

* Clean up metrics generated from logs after a config reload.

Synced from:
grafana/loki#12938

* Update README
ptodev added a commit to grafana/agent that referenced this pull request May 15, 2024
* azure_exporter: Fix bug which prevents subscription scope from working with only a single region (#6719)

* Update postgres exporter (#6780)

* Update postgres exporter
* Make collector work with first DSN
* Enhance docs and test
* Update depcheck

* Update SNMP exporter (#6904)

* Update SNMP exporter

* Fix build issues

* Update Windows exporter

* Update Loki dependency (#6905)

* Update Loki dependency.

* Clean up metrics generated from logs after a config reload.

Synced from:
grafana/loki#12938

* Update README

* Update changelog

* Update loki dep to k190 (#6543)

* Update loki dep to k190

* port renames

* fix loki push api

* Update vmware_exporter

* Update prom encoder

---------

Co-authored-by: kgeckhart <[email protected]>
Co-authored-by: Piotr <[email protected]>
ptodev added a commit that referenced this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 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