forked from openrewrite/rewrite-micrometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Micrometer 1.13.x migration recipe (openrewrite#11)
* Add Micrometer 1.13.x migration recipe The migration from `io.prometheus.client.CollectorRegistry` to `io.prometheus.metrics.model.registry.PrometheusRegistry` is probably not covering _all_ cases. But for many code bases simply changing the type might be sufficient because `CollectorRegistry` and `PrometheusRegistry` have a very similar (and small) public api that essentially only offers a singleton - exposed as constant with equal names - and a constructor Partially resolves openrewrite#8 * Update src/test/java/org/openrewrite/micrometer/UpgradeMicrometer13Test.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/test/java/org/openrewrite/micrometer/UpgradeMicrometer13Test.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Loop in 1.13.x upgrade with the existing UpgradeMicrometer --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tim te Beek <[email protected]>
- Loading branch information
1 parent
3218cd5
commit 844e000
Showing
4 changed files
with
138 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# Copyright 2024 the original author or authors. | ||
# <p> | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# <p> | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# <p> | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.micrometer.UpgradeMicrometer13 | ||
displayName: Migrate to Micrometer 1.13 | ||
description: > | ||
Migrate applications to the latest Micrometer 1.13 release. This recipe will modify an | ||
application's build files, make changes to deprecated/preferred APIs, and migrate configuration settings that have | ||
changes between versions as described in the [Micrometer 1.13 migration guide](https://github.com/micrometer-metrics/micrometer/wiki/1.13-Migration-Guide) | ||
tags: | ||
- micrometer | ||
recipeList: | ||
- org.openrewrite.java.dependencies.UpgradeDependencyVersion: | ||
groupId: io.micrometer | ||
artifactId: '*' | ||
newVersion: 1.13.x | ||
- org.openrewrite.java.ChangePackage: | ||
oldPackageName: io.micrometer.prometheus | ||
newPackageName: io.micrometer.prometheusmetrics | ||
- org.openrewrite.java.ChangeType: | ||
oldFullyQualifiedTypeName: io.prometheus.client.CollectorRegistry | ||
newFullyQualifiedTypeName: io.prometheus.metrics.model.registry.PrometheusRegistry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/org/openrewrite/micrometer/UpgradeMicrometer13Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.micrometer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class UpgradeMicrometer13Test implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipeFromResource( | ||
"/META-INF/rewrite/micrometer-13.yml", | ||
"org.openrewrite.micrometer.UpgradeMicrometer13"); | ||
} | ||
|
||
@Test | ||
@DocumentExample | ||
void shouldChangePackage() { | ||
// language=java | ||
rewriteRun( | ||
java( | ||
""" | ||
import io.micrometer.prometheus.PrometheusConfig; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
class MicrometerConfig { | ||
PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); | ||
} | ||
""", | ||
""" | ||
import io.micrometer.prometheusmetrics.PrometheusConfig; | ||
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; | ||
class MicrometerConfig { | ||
PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldMigrateToPrometheusMeterRegistry() { | ||
// language=java | ||
rewriteRun( | ||
java( | ||
""" | ||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.prometheus.PrometheusConfig; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
import io.prometheus.client.CollectorRegistry; | ||
class MicrometerConfig { | ||
PrometheusMeterRegistry prometheusMeterRegistry = | ||
new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, CollectorRegistry.defaultRegistry, Clock.SYSTEM); | ||
} | ||
""", | ||
""" | ||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.prometheusmetrics.PrometheusConfig; | ||
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; | ||
import io.prometheus.metrics.model.registry.PrometheusRegistry; | ||
class MicrometerConfig { | ||
PrometheusMeterRegistry prometheusMeterRegistry = | ||
new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, PrometheusRegistry.defaultRegistry, Clock.SYSTEM); | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |