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

Equivalent usage of Simpleclient in micrometer-registry-prometheus 1.13.x #1226

Open
siddhant16 opened this issue Dec 10, 2024 · 3 comments
Open

Comments

@siddhant16
Copy link

siddhant16 commented Dec 10, 2024

Hi Team! We are migrating our project from micrometer-registry-prometheus:1.12.8 to version 1.13.8 . I see that the io.prometheus:simpleclient:jar:0.16.0 has been deprecated.

We have few scenarios which I do not see in the migration guide.

Here are few scenarios,

  1. What is the equivalent of io.prometheus.client.Collector.MetricFamilySamples and the MetricFamilySamples.Sample
   PrometheusMeterRegistry instance = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
   MetricFamilySamples samples =  instance.getPrometheusRegistry().metricFamilySamples()
 if (sample == null || sample.name == null || sample.labelNames == null || sample.labelValues == null) {
      LOGGER.error("The provided Sample object is either null or one of its fields is null: {}", sample);
      throw new IllegalArgumentException("The provided Sample object is either null or one of its fields is null: " + sample);
    }
  1. Is the import io.prometheus.metrics.model.registry.Collector a replacement of io.prometheus.client.Collector, however, I couldn't find the below in the new Collector.
Enumeration<Collector.MetricFamilySamples> metricFamilySamples;
  1. Similarly how we can replace the io.prometheus.client.exporter.common.TextFormat?

Could you please help me with the code changes. Also, can you share any additional docs available that we can follow for migrating from the usage of simpleclient.

@fstab
Copy link
Member

fstab commented Dec 10, 2024

Hi @siddhant16, could you provide more context on what you would like to achieve?

MetricFamilySamples samples =  instance.getPrometheusRegistry().metricFamilySamples()

Sounds like you are manually collecting metrics in code. I'm wondering why you do that rather than just using Micrometer to expose a Prometheus endpoint?

@siddhant16
Copy link
Author

siddhant16 commented Dec 10, 2024

Thank you for the response. So, the MetricFamilySamples that are collected in the above code is to be used for custom metric generation and filtering. We filter the provided MetricsFamilySamples with the endpoint processor and also generate additional metrics for provided PrometheusMetrics using provided MetricFamilySample.

Using the MetricFamilySamples to apply filtering,

...
...
   TextFormat.writeFormat(TextFormat.CONTENT_TYPE_004, writer,
       applySourceFiltering(configToProcessor, metricsFamilySamples));

@siddhant16
Copy link
Author

siddhant16 commented Dec 12, 2024

Hi @fstab In addition to above I also wanted to know how we can get the names based on the type of metric, the MetricFamilySamples use to have getNames() like below,

    public String[] getNames() {
      switch (this.type) {
        case COUNTER:
          return new String[]{this.name + "_total", this.name + "_created", this.name};
        case SUMMARY:
          return new String[]{this.name + "_count", this.name + "_sum", this.name + "_created", this.name};
        case HISTOGRAM:
          return new String[]{this.name + "_count", this.name + "_sum", this.name + "_bucket", this.name + "_created", this.name};
        case GAUGE_HISTOGRAM:
          return new String[]{this.name + "_gcount", this.name + "_gsum", this.name + "_bucket", this.name};
        case INFO:
          return new String[]{this.name + "_info", this.name};
        default:
          return new String[]{this.name};
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants