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

Add armeria-prometheus1 module for Prometheus version 1 and deprecate older classes. #5698

Merged
merged 7 commits into from
Jun 3, 2024

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented May 24, 2024

Motivation:
Micrometer 1.13.0 updates its Prometheus dependency from 0.x to 1.x. In Prometheus 1.x, the package of PrometheusMeterRegistry has changed and CollectorRegistry is no longer used. More details can be found in the migration guide.

Modifications:

  • Updated Micrometer from 1.12.4 to 1.13.0.
  • Removed the Micrometer 1.3 integration test module.
  • Updated Prometheus from 0.16.0 to 1.3.0.
  • Added armeria-prometheus1 module.
    • PrometheusMeterRegistries, PrometheusVersion1ExpositionService, and its builder classes are added.
  • Deprecated PrometheusMeterRegistries, PrometheusExpositionService, and its builder classes.

Result:

  • The older PrometheusMeterRegistries, PrometheusExpositionService, and its builders are deprecated.
    • Use the same classes in the armeria-prometheus1.

Motivation:
Micrometer 1.13.0 updates its Prometheus dependency from 0.x to 1.x.
In Prometheus 1.x, the package of `PrometheusMeterRegistry` has changed and `CollectorRegistry` is no longer used.
More details can be found in the [migration guide](https://github.com/micrometer-metrics/micrometer/wiki/1.13-Migration-Guide).

Modifications:
- Updated Micrometer from 1.12.4 to 1.13.0.
- Removed the Micrometer 1.3 integration test module.
  - We dropped supporting Micrometer <= 1.5 already: line#5661
- Updated Prometheus from 0.16.0 to 1.3.0.
- Added `PrometheusVersion1MeterRegistries`, `PrometheusVersion1ExpositionService`, and its builder classes.
- Deprecated `PrometheusMeterRegistries`, `PrometheusExpositionService`, and its builder classes.

Result:
- New Prometheus version 1 classes are added to support the updated Micrometer dependency.
- The older `PrometheusMeterRegistries`, `PrometheusExpositionService`, and its builders are deprecated.
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of minor comments, but looks good to me 👍 Thanks @minwoox 🙇 👍 🙇

Comment on lines 948 to 950
[libraries.prometheus]
module = "io.prometheus:simpleclient_common"
version.ref = "prometheus-legacy"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question) Is this used?

Suggested change
[libraries.prometheus]
module = "io.prometheus:simpleclient_common"
version.ref = "prometheus-legacy"

If it is used, should the version.ref be prometheus instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot to remove it. Thanks!

* Provides the convenient factory methods for {@link PrometheusMeterRegistry}.
*/
@UnstableApi
public final class PrometheusVersion1MeterRegistries {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional) It is not easy to find this new class to use the new API.
How about removing public static methods and adding an accessor to PrometheusMeterRegistries?

For example:

PrometheusMeterRegistries.V0.defaultRegistry()
PrometheusMeterRegistries.V1.defaultRegistry()

We may deprecate all static methods in PrometheusMeterRegistries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason. 😉
#5698 (comment)

Comment on lines 97 to 102
try (ByteBufOutputStream byteBufOutputStream = new ByteBufOutputStream(buffer)) {
final ExpositionFormatWriter writer = expositionFormats.findWriter(accept);
format = writer.getContentType();
writer.write(byteBufOutputStream, prometheusRegistry.scrape());
success = true;
} finally {
Copy link
Contributor

@ikhoon ikhoon May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of consolidating this class with the original one? This will help users perform a more smooth migration.

class PrometheusExpositionService {

    @Deprecate
    public static PrometheusExpositionServiceBuilder builder(CollectorRegistry collectorRegistry) {
        ...
    }

    public static PrometheusExpositionServiceBuilder builder(PrometheusRegistry prometheusRegistry) {
        ...
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of consolidating this class with the original one?

If so, users have to add two different modules even though they want the new one or the old one.
That's why I have created a separate class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, it would be clearer to split PrometheusExpositionService and PrometheusMeterRegistries as a separate module such as :prometheus1. This direction is an Armeria way to support multiple versions for a library like other dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, so you prefer @jrhee17's opinion: #5698 (comment)

@minwoox minwoox changed the title Add Prometheus classes for Version 1 and deprecate older classes. Add armeria-prometheus1 module for Prometheus version 1 and deprecate older classes. May 29, 2024
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good 👍 Left a minor question 🙇

@@ -48,7 +48,7 @@
import com.linecorp.armeria.common.logging.RequestLogAccess;
import com.linecorp.armeria.common.logging.RequestLogProperty;
import com.linecorp.armeria.common.metric.MeterIdPrefix;
import com.linecorp.armeria.common.metric.PrometheusMeterRegistries;
import com.linecorp.armeria.common.prometheus.PrometheusMeterRegistries;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question) I'm wondering if to minimize breaking changes, we could keep the package structure the same. I think this could be done by also declaring a separate prometheus0 module.

The upside would be:

  • Guaranteed one-line breaking change for users since they only need to add a dependency. (no need to touch java code)
  • The symmetry between prometheus0 and prometheus1 is just easier to reason about.
  • Users using prometheus1 don't need code for prometheus0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be done by also declaring a separate prometheus0 module.

Had a chat about this and I don't want to add prometheus0 right now because we have to maintain the same classes in the core module and prometheus0 module.
Having said this, we might introduce prometheus0 later if we want to keep supporting Prometheus 0 dependency when we reach Armeria v2.0.

we could keep the package structure the same.

We can't do this without breaking change for now. 😢

final boolean hasPrometheus = hasAllClasses(
prometheusMeterRegistryClassName,
"io.prometheus.client.CollectorRegistry");
"io.prometheus.metrics.model.registry.PrometheusRegistry");
Copy link
Contributor

@ikhoon ikhoon May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:prometheus1 is a compile scope that we need to check in runtime if it exists.

Suggested change
"io.prometheus.metrics.model.registry.PrometheusRegistry");
"io.prometheus.metrics.model.registry.PrometheusRegistry",
"com.linecorp.armeria.server.prometheus.PrometheusExpositionService");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this. Added thanks! 😉

@@ -3,8 +3,8 @@ dependencies {
api libs.jakarta.inject
compileOnly libs.jakarta.validation

// TODO(anuraaga): Consider removing these since this module does not have related functionality.
optionalApi libs.micrometer.prometheus
optionalApi project(':prometheus1')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users may not know they have to add :prometheus1 dependency to use Prometheus exposition. What do you think of advertising for prometheus1 where PrometheusExpositionService is linked in ArmeriaSettings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. 👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@minwoox minwoox merged commit 00d421f into line:main Jun 3, 2024
15 checks passed
@minwoox minwoox deleted the update_deps branch June 3, 2024 01:03
Dogacel pushed a commit to Dogacel/armeria that referenced this pull request Jun 8, 2024
… older classes. (line#5698)

Motivation:
Micrometer 1.13.0 updates its Prometheus dependency from 0.x to 1.x. In Prometheus 1.x, the package of `PrometheusMeterRegistry` has changed and `CollectorRegistry` is no longer used. More details can be found in the [migration guide](https://github.com/micrometer-metrics/micrometer/wiki/1.13-Migration-Guide).

Modifications:
- Updated Micrometer from 1.12.4 to 1.13.0.
- Removed the Micrometer 1.3 integration test module.
  - We dropped supporting Micrometer <= 1.5 already: line#5661
- Updated Prometheus from 0.16.0 to 1.3.0.
- Added `armeria-prometheus1` module.
  -  `PrometheusMeterRegistries`, `PrometheusVersion1ExpositionService`, and its builder classes are added.
- Deprecated `PrometheusMeterRegistries`, `PrometheusExpositionService`, and its builder classes.

Result:
- The older `PrometheusMeterRegistries`, `PrometheusExpositionService`, and its builders are deprecated.
  - Use the same classes in the `armeria-prometheus1`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants