Skip to content

[8.19](backport #44493) [Metricbeat] [Prometheus] Add proper error handling for query dataset when the auth/ssl is misconfigured#44531

Merged
mykola-elastic merged 1 commit into8.19from
mergify/bp/8.19/pr-44493
May 29, 2025
Merged

[8.19](backport #44493) [Metricbeat] [Prometheus] Add proper error handling for query dataset when the auth/ssl is misconfigured#44531
mykola-elastic merged 1 commit into8.19from
mergify/bp/8.19/pr-44493

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented May 28, 2025

Proposed commit message

[Metricbeat] [Prometheus] Query dataset: make understandable error messages in case for http error codes

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

No impact

Author's Checklist

  • [ ]

How to test this PR locally

My test environment:

  • Metricbeat built locally
  • Prometheus running in docker, configured to listen on HTTPS with local self-signed certs
  • Cloud deployment of Elastic stack

Related issues

Screenshots & Logs

When running Metricbeat with wrong Prometheus' username and password the error message looks like that now:

Screenshot 2025-05-26 at 15 58 40

and the debug message to the logs

{"log.level":"debug","@timestamp":"2025-05-26T16:07:31.937+0300","log.logger":"prometheus.query","log.origin":{"function":"github.com/elastic/beats/v7/metricbeat/module/prometheus/query.(*MetricSet).Fetch","file.name":"query/query.go","file.line":101},"message":"error received from prometheus endpoint: Unauthorized\n","service.name":"metricbeat","ecs.version":"1.6.0"}

When the protocol is HTTP but the Prometheus is configured to use HTTPS:

Screenshot 2025-05-26 at 16 01 44

and the debug message to the logs:

{"log.level":"debug","@timestamp":"2025-05-26T16:06:09.560+0300","log.logger":"prometheus.query","log.origin":{"function":"github.com/elastic/beats/v7/metricbeat/module/prometheus/query.(*MetricSet).Fetch","file.name":"query/query.go","file.line":101},"message":"error received from prometheus endpoint: Client sent an HTTP request to an HTTPS server.\n","service.name":"metricbeat","ecs.version":"1.6.0"}

Which is now the same behavior as of collector submodule


This is an automatic backport of pull request #44493 done by [Mergify](https://mergify.com).

… when the auth/ssl is misconfigured (#44493)

* [prometheus] query.go: check error response codes

* [prometheus] query.go: log error response body to debug log instead of repoter

* add entry to the changelog

* add unit test

* specify which endpoint failed

(cherry picked from commit ba454d5)
@mergify mergify bot requested a review from a team as a code owner May 28, 2025 13:26
@mergify mergify bot added the backport label May 28, 2025
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 28, 2025
@github-actions github-actions bot added enhancement Metricbeat Metricbeat Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team prometheus labels May 28, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 28, 2025
@mykola-elastic mykola-elastic merged commit 70c70b1 into 8.19 May 29, 2025
45 checks passed
@mykola-elastic mykola-elastic deleted the mergify/bp/8.19/pr-44493 branch May 29, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport enhancement Metricbeat Metricbeat prometheus Team:Obs-InfraObs Label for the Observability Infrastructure Monitoring team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants