Skip to content

Commit

Permalink
Fix a few missing ending newlines; MetricsFeature4 now extends Metric…
Browse files Browse the repository at this point in the history
…sFeature and builder method chooses which builder to return
  • Loading branch information
tjquinno committed Aug 18, 2023
1 parent 77d9f73 commit 67336ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public Optional<MeterRegistryFormatter> formatter(MediaType mediaType,
.build())
: Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ private MetricsFeature(Builder builder) {
SystemTagsManager.create(metricsSettings);
}

protected MetricsFeature(System.Logger logger, Builder builder, String serviceName) {
super(logger, builder, serviceName);
metricsSettings = null;
registryFactory = null;
}

/**
* Create an instance to be registered with WebServer with all defaults.
*
Expand Down Expand Up @@ -117,7 +123,10 @@ public static MetricsFeature create(Config config) {
* @return a new builder instance
*/
public static Builder builder() {
return new Builder();
// return new Builder();
return System.getProperty("newMetricsAPI") == null
? new Builder()
: MetricsFeature4.builder();
}

@Override
Expand Down Expand Up @@ -297,14 +306,19 @@ private void setUpDisabledEndpoints(HttpRules rules) {
/**
* A fluent API builder to build instances of {@link MetricsFeature}.
*/
public static final class Builder extends HelidonFeatureSupport.Builder<Builder, MetricsFeature> {
//public static final class Builder extends HelidonFeatureSupport.Builder<Builder, MetricsFeature> {
public static class Builder extends HelidonFeatureSupport.Builder<Builder, MetricsFeature> {
private LazyValue<RegistryFactory> registryFactory;
private MetricsSettings.Builder metricsSettingsBuilder = MetricsSettings.builder();

private Builder() {
super("metrics");
}

protected Builder(String serviceName) {
super(serviceName);
}

@Override
public MetricsFeature build() {
if (registryFactory == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@
* req.context().get(MetricRegistry.class).ifPresent(reg -> reg.counter("myCounter").inc());
* }</pre>
*/
public class MetricsFeature4 extends HelidonFeatureSupport {
// TODO change back to extend HFS
//public class MetricsFeature4 extends HelidonFeatureSupport {
public class MetricsFeature4 extends MetricsFeature {
private static final System.Logger LOGGER = System.getLogger(MetricsFeature.class.getName());
private static final Handler DISABLED_ENDPOINT_HANDLER = (req, res) -> res.status(NOT_FOUND_404)
.send("Metrics are disabled");
Expand Down Expand Up @@ -368,8 +370,9 @@ private void setUpDisabledEndpoints(HttpRules rules) {
/**
* A fluent API builder to build instances of {@link MetricsFeature}.
*/
public static final class Builder extends HelidonFeatureSupport.Builder<Builder, MetricsFeature4> {

// TODO change back to normal extends clause
// public static final class Builder extends HelidonFeatureSupport.Builder<Builder, MetricsFeature4> {
public static final class Builder extends MetricsFeature.Builder {
private LazyValue<MetricsFactory> metricsFactory;
private MeterRegistry meterRegistry;
private MetricsConfig.Builder metricsConfigBuilder = MetricsConfig.builder();
Expand Down Expand Up @@ -424,4 +427,4 @@ public Builder meterRegistry(MeterRegistry meterRegistry) {
return this;
}
}
}
}

0 comments on commit 67336ce

Please sign in to comment.