Skip to content

Commit

Permalink
Add more factory methods to PrometheusExpositionService (#5134)
Browse files Browse the repository at this point in the history
Motivation:

It is very common for users to specify
`CollectorRegistry.defaultRegistry` when creating a
`PrometheusExpositionService` or its builder.

Modifications:

- Added two shortcut methods:
  - `of()` -> `of(CollectorRegistry.defaultRegistry)`
  - `builder()` -> `builder(CollectorRegistry.defaultRegistry)`

Result:

- Much more convenient and less verbose when creating a
`PrometheusExpositionService`
  • Loading branch information
trustin authored Aug 22, 2023
1 parent e0b1f0f commit a50ddd3
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.linecorp.armeria.server.metric;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -46,6 +45,14 @@
*/
public final class PrometheusExpositionService extends AbstractHttpService implements TransientHttpService {

/**
* Returns a new {@link PrometheusExpositionService} that exposes Prometheus metrics from
* {@link CollectorRegistry#defaultRegistry}.
*/
public static PrometheusExpositionService of() {
return of(CollectorRegistry.defaultRegistry);
}

/**
* Returns a new {@link PrometheusExpositionService} that exposes Prometheus metrics from the specified
* {@link CollectorRegistry}.
Expand All @@ -54,6 +61,14 @@ public static PrometheusExpositionService of(CollectorRegistry collectorRegistry
return new PrometheusExpositionService(collectorRegistry, Flags.transientServiceOptions());
}

/**
* Returns a new {@link PrometheusExpositionServiceBuilder} created with
* {@link CollectorRegistry#defaultRegistry}.
*/
public static PrometheusExpositionServiceBuilder builder() {
return builder(CollectorRegistry.defaultRegistry);
}

/**
* Returns a new {@link PrometheusExpositionServiceBuilder} created with the specified
* {@link CollectorRegistry}.
Expand Down

0 comments on commit a50ddd3

Please sign in to comment.