nacos icon indicating copy to clipboard operation
nacos copied to clipboard

Prometheus-sd add namespace and service api

Open Joey777210 opened this issue 1 year ago • 15 comments

Is your feature request related to a problem? Please describe. If use Nacos for Prometheus http sd. Prometheus will get all services in Nacos. But in many scene, Nacos is use by a lot system. So prometheus sd support Namespace and service dimention insulate are important.

Describe the solution you'd like Add two api.

Describe alternatives you've considered Add two interfaces, and specify the Namespace and the service

Joey777210 avatar Jun 18 '23 08:06 Joey777210

Is prometheus sd protocol support specify the Namespace and the service?

KomachiSion avatar Jun 19 '23 01:06 KomachiSion

Actually, prometheus do not support Nacos as service discovery directly. Currently, we can only use Prometheus Http SD config for Nacos, see this issue: https://github.com/prometheus/prometheus/issues/7539 . And prometheus don't really care what api path you give, so we can config namespace and service through path variable.

Prometheus http sd: https://prometheus.io/docs/prometheus/latest/http_sd/

Joey777210 avatar Jun 19 '23 02:06 Joey777210

我的想法是做一个@PrometheusParam的注解,然后value可以是${namespace}|${group}的占位符,用AspectJ去做切面替换占位符,然后以参数形式注入到不同的prometheus监控中,这样别的接口也可以使用,扩展起来方便,是否可行 @KomachiSion

985492783 avatar Jun 19 '23 03:06 985492783

我的想法是做一个@PrometheusParam的注解,然后value可以是${namespace}|${group}的占位符,用AspectJ去做切面替换占位符,然后以参数形式注入到不同的prometheus监控中,这样别的接口也可以使用,扩展起来方便,是否可行 @KomachiSion

没必要这么复杂, 如果prometheus sd 不关心具体的uri是什么,那完全可以提供全量的,命名空间级别,服务级别的接口精确控制, 甚至应该限制使用命名空间级别,服务级别,减少全量接口的使用。

KomachiSion avatar Jun 21 '23 01:06 KomachiSion

Actually, prometheus do not support Nacos as service discovery directly. Currently, we can only use Prometheus Http SD config for Nacos, see this issue: prometheus/prometheus#7539 . And prometheus don't really care what api path you give, so we can config namespace and service through path variable.

Prometheus http sd: https://prometheus.io/docs/prometheus/latest/http_sd/

I don't know much about the prometheus sd protocol. From the documentation, I can only see that target hosts are required to be configured, so I always thought it was a fixed uri. Not sure how to configure the uri.

If it is the uri that can be customized, then specifying the namespace and serviceName should be the recommended practice

KomachiSion avatar Jun 21 '23 01:06 KomachiSion

我的想法是做一个@PrometheusParam的注解,然后value可以是${namespace}|${group}的占位符,用AspectJ去做切面替换占位符,然后以参数形式注入到不同的prometheus监控中,这样别的接口也可以使用,扩展起来方便,是否可行 @KomachiSion

没必要这么复杂, 如果prometheus sd 不关心具体的uri是什么,那完全可以提供全量的,命名空间级别,服务级别的接口精确控制, 甚至应该限制使用命名空间级别,服务级别,减少全量接口的使用。

get

985492783 avatar Jun 21 '23 02:06 985492783

Actually, prometheus do not support Nacos as service discovery directly. Currently, we can only use Prometheus Http SD config for Nacos, see this issue: prometheus/prometheus#7539 . And prometheus don't really care what api path you give, so we can config namespace and service through path variable. Prometheus http sd: https://prometheus.io/docs/prometheus/latest/http_sd/

I don't know much about the prometheus sd protocol. From the documentation, I can only see that target hosts are required to be configured, so I always thought it was a fixed uri. Not sure how to configure the uri.

If it is the uri that can be customized, then specifying the namespace and serviceName should be the recommended practice

sry, posted wrong doc, see this: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config

Joey777210 avatar Jun 21 '23 03:06 Joey777210

Actually, prometheus do not support Nacos as service discovery directly. Currently, we can only use Prometheus Http SD config for Nacos, see this issue: prometheus/prometheus#7539 . And prometheus don't really care what api path you give, so we can config namespace and service through path variable. Prometheus http sd: https://prometheus.io/docs/prometheus/latest/http_sd/

I don't know much about the prometheus sd protocol. From the documentation, I can only see that target hosts are required to be configured, so I always thought it was a fixed uri. Not sure how to configure the uri. If it is the uri that can be customized, then specifying the namespace and serviceName should be the recommended practice

sry, posted wrong doc, see this: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config

So when users config __meta_url for each target, prometheus will call the specifed url replace the fixed one?

KomachiSion avatar Jun 26 '23 01:06 KomachiSion

Actually, prometheus do not support Nacos as service discovery directly. Currently, we can only use Prometheus Http SD config for Nacos, see this issue: prometheus/prometheus#7539 . And prometheus don't really care what api path you give, so we can config namespace and service through path variable. Prometheus http sd: https://prometheus.io/docs/prometheus/latest/http_sd/

I don't know much about the prometheus sd protocol. From the documentation, I can only see that target hosts are required to be configured, so I always thought it was a fixed uri. Not sure how to configure the uri. If it is the uri that can be customized, then specifying the namespace and serviceName should be the recommended practice

sry, posted wrong doc, see this: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config

So when users config __meta_url for each target, prometheus will call the specifed url replace the fixed one?

I think users should config url.

Joey777210 avatar Jun 26 '23 02:06 Joey777210

I don't found the config url, can you provide a demo configuration?

What's more, the usage of prometheus sd document is leak. Would you mind try to add the docuement of usage after the issue completed?

KomachiSion avatar Jun 28 '23 01:06 KomachiSion

I don't found the config url, can you provide a demo configuration?

What's more, the usage of prometheus sd document is leak. Would you mind try to add the docuement of usage after the issue completed?

Here is a demo

- job_name: 'http_sd_example'
  metrics_path: /metrics
  scheme: http
  http_sd_configs:
  - url: https://example.com/targets.json
    timeout: 5s

And for document,for sure I will write one.

Joey777210 avatar Jun 29 '23 02:06 Joey777210

OK, I understand, I will review the PR and comment in PR some request changes. If no, PR will be merged.

After this, Please help community add an usage document in nacos-group/

KomachiSion avatar Jun 30 '23 02:06 KomachiSion

PR merged, Please help to submit usage document.

KomachiSion avatar Jul 17 '23 03:07 KomachiSion

@KomachiSion I will write a document after solving this security issue #10752

Joey777210 avatar Jul 23 '23 06:07 Joey777210

This issue only waiting the relative usage document, Any community contributors prefer to contribute?

KomachiSion avatar Feb 27 '24 02:02 KomachiSion