Grafana Cloud Metrics Endpoint error for WordPress plugin

Hello,

I’ve added a REST API plugin in WordPress that returns data in Prometheus format (wp_posts_total{status=“draft”} 0) at the link: /wp-json/metrics, without authentication. This works from the browser.

I’ve tried to connect using a Metric Endpoint from Grafana Cloud, but I have the error: The request to the provided endpoint did not return a valid response. Please ensure your URL is correctly setup to handle authentication credentials.

In section: Enter the URL to scrape, and the necessary Auth Credentials, I’ve added some mandatory random user/password and the link: /wp-json/metrics.

Could you please specify which is the reason of the error ?

Thank you,
Mihai

Did you solve this issue?

I have a similar problem with Metrics Endpoint.

I have a public /metrics endpoint serving well-formed Prometheus metrics (that I can scrape with Prometheus) but, like you, when I try to configure Metrics Endpoint with the URL and with arbitrary “Bearer Token” (which should work since the /metrics endpoint will respond with|without the header), I get the same error.

There appears to be no way to debug this configuration either. It would be helpful if the service presented request|response messages for debugging.

I’m able to make the request using curl directly and it returns a 200 and well-formed Prometheus text-based exposition format content.

I have the totally same issue with Metric Endpoint, too.

Bumping for continued visibility. I am having the same issue when authenticating with a bearer token using the Metrics Endpoint. I can also exactly the same url and token in Postman and I can access the metrics successfully.

I am using a long token (72 chars IIRC) so I wonder if there is not some truncation taking place…

As an update, I tried with a significantly shorter token and that made no difference.

To close the loop on this case for my particular problem:

It turns out that, even when using Bearer auth, the Metrics Endpoint HTTP makes the initial request without any Authorization header. Only once the the host responds with a 401 will Metrics Endpoint make a second request that includes the Authorization header.

I initially diagnosed this using webhook.site and I was able to change the behaviour of our application to respond with a 401 when the Bearer token was absent and that resolved the issue in our case.