pjhampton / kibana-prometheus-exporter

Prometheus metrics for Kibana
Apache License 2.0
114 stars 37 forks source link

Internal Server Error with basePath and rewriteBasePath #233

Closed MaxenceAdnot closed 3 years ago

MaxenceAdnot commented 3 years ago

Hello,

We operate a Kibana 7.12.1 with your plugin installed (with the same version)

We have defined in our kibana.yml:

server.basePath: /kibana_mom
server.rewriteBasePath: true

Unfortunately when we hit http://localhost:5601/kibana_mom/_prometheus/metrics we are getting an HTTP 500 error. We looked at the logs and we've seen that the call made by axios is going to /kibana/api/status instead of /kibana_mom/api/status.

Is there a way to fix this ?

pjhampton commented 3 years ago

Opps, nice bug find.

      let reqUrl = `${reqProto}//${reqHost}:${reqPort}/api/status`;

      if (request.headers !== undefined
          && request.headers.authorization !== undefined) {
        reqHeaders = { 'Authorization': request.headers.authorization };
      }

The reqUrl isn't taking into account a basePath deviation. I will try get it fixed by the end of week and ping you.

faust64 commented 3 years ago

https://www.elastic.co/guide/en/kibana/7.x/kibana-navigation.html#_prepending_a_proper_basepath

I couldn't test this yet, though it might be fixable with something like:

-      let reqUrl = `${reqProto}//${reqHost}:${reqPort}/api/status`;
+      let discoverUrl = core.http.basePath.prepend(`/api/status`);
+      let reqUrl = `${reqProto}//${reqHost}:${reqPort}${discoverUrl}`;

Searching GitHub for similar commits: did not find any yet. I suspect we would need to import something as well ...

pjhampton commented 3 years ago

@MaxenceAdnot Apologies for going momentarily dark.

Please see the new release here: https://github.com/pjhampton/kibana-prometheus-exporter/releases/tag/7.12.1 I can't delete / swap out the v1 because I could break downstream users as I now provide the artifact checksums. Plus it wouldn't be a very good release eddiquite. Please use the 7.12.1-v2 version.

I couldn't test this yet, though it might be fixable with something like:

@faust64 ❤️ Yep, that was a good way of approaching the problem. I think I might double down here rather than rebuild the URL on every request. This would probably be much more secure too. Although the requesting user (kibana_system) doesn't have a lot of access anyway.

Thanks for reporting this!