Skip to content

Commit

Permalink
Save changes for safekeeping; also share it
Browse files Browse the repository at this point in the history
  • Loading branch information
tjquinno committed Aug 30, 2023
1 parent 039c332 commit db10c3f
Show file tree
Hide file tree
Showing 17 changed files with 659 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,33 @@ interface Builder extends Wrapper, io.helidon.common.Builder<Builder, Distributi
* @return updated builder
*/
Builder buckets(Iterable<Double> buckets);

/**
* Returns the minimum expected value setting.
*
* @return min expected value
*/
Optional<Double> minimumExpectedValue();

/**
* Returns the maximum expected value setting.
*
* @return max expected value
*/
Optional<Double> maximumExpectedValue();

/**
* Returns the percentiles.
*
* @return percentiles
*/
Iterable<Double> percentiles();

/**
* Returns the buckets.
*
* @return buckets
*/
Iterable<Double> buckets();
}
}
7 changes: 7 additions & 0 deletions metrics/api/src/main/java/io/helidon/metrics/api/Gauge.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,12 @@ static <N extends Number> Builder<N> builder(String name, Supplier<N> numberSupp
* @param <N> specific subtype of {@code Number} for the gauge this builder will produce
*/
interface Builder<N extends Number> extends Meter.Builder<Builder<N>, Gauge<N>> {

/**
* Returns a {@link java.util.function.Supplier} for the values the gauge will produce.
*
* @return supplier for the values
*/
Supplier<N> supplier();
}
}
8 changes: 8 additions & 0 deletions metrics/api/src/main/java/io/helidon/metrics/api/Meter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ default B identity() {
return (B) this;
}

// /**
// * Use the settings in the current builder to prepare the target builder.
// *
// * @param target other builder to set up
// * @return updated other builder
// */
// <T extends Meter.Builder<?, ?>> T copyTo(T target);

/**
* Sets the tags to use in identifying the build meter.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import io.helidon.common.Builder;

/**
* Manages the look-up and registration of meters.
*/
Expand Down Expand Up @@ -219,4 +221,46 @@ default Optional<Timer> timer(String name, Iterable<Tag> tags) {
* @return the meter registry
*/
MeterRegistry onMeterRemoved(Consumer<Meter> onRemoveListener);

/**
* Builder for creating a new meter registry.
*
* @param <B> builder type
* @param <R> meter registry type
*/
interface Builder<B extends Builder<B, R>, R extends MeterRegistry> extends io.helidon.common.Builder<B, R> {

/**
* Assigns the clock to be used within the meter registry (e.g., in timers), defaulting to a system clock.
*
* @param clock the {@link io.helidon.metrics.api.Clock} to be used
* @return updated builder
*/
B clock(Clock clock);

/**
* Sets the {@link io.helidon.metrics.api.MetricsConfig} for the meter registry, defaulting to the
* metrics config with which the {@link io.helidon.metrics.api.MetricsFactory} was created.
*
* @param metricsConfig metrics config to control the meter registry
* @return updated builder
*/
B metricsConfig(MetricsConfig metricsConfig);

/**
* Records a subscriber to meter-added events.
*
* @param addListener listener for meter-added events
* @return updated builder
*/
B onMeterAdded(Consumer<Meter> addListener);

/**
* Records a subscriber to meter-removed events.
*
* @param removeListener listener for meter-removal events
* @return updated builder
*/
B onMeterRemoved(Consumer<Meter> removeListener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ static MetricsFactory getInstance(Config rootConfig) {
*/
MetricsConfig metricsConfig();

/**
* Returns a builder for creating a new {@link io.helidon.metrics.api.MeterRegistry}.
*
* @return the new builder
* @param <B> specific type of the builder
* @param <M> specific type of the registry
*/
<B extends MeterRegistry.Builder<B, M>, M extends MeterRegistry> B meterRegistryBuilder();

/**
* Creates a new {@link io.helidon.metrics.api.MeterRegistry} using the provided metrics config.
*
Expand Down Expand Up @@ -264,16 +273,48 @@ MeterRegistry createMeterRegistry(Clock clock,
*/
HistogramSnapshot histogramSnapshotEmpty(long count, double total, double max);

// /**
// * Returns a no-op {@link io.helidon.metrics.api.Meter} of the type implied by the builder's type, initialized with
// * the builder's name and other required parameters.
// *
// * @param builder original builder
// * @param <B> type of the builder
// * @param <M> type of the meter the builder produces
// * @return corresponding no-op meter
// */
// default <M extends Meter, B extends Meter.Builder<B, M>> Meter noOpMeter(B builder) {
// if (builder instanceof Counter.Builder cb) {
// return NoOpMeter.Counter.builder(cb.name()).build();
// }
// if (builder instanceof FunctionalCounter.Builder fcb) {
// return NoOpMeter.FunctionalCounter.builder(fcb.name(), fcb.stateObject(), fcb.fn()).build();
// }
// if (builder instanceof DistributionSummary.Builder sb) {
// return NoOpMeter.DistributionSummary.builder(sb.name()).build();
// }
// // if (builder instanceof Gauge.FunctionBasedBuilder gb) {
// // return NoOpMeter.Gauge.builder(gb.name(), gb.stateObject(), gb.fn()).build();
// // }
// // if (builder instanceof Gauge.NumberBasedBuilder<?> nb) {
// // return NoOpMeter.Gauge.builder(nb.name(), nb.number());
// // }
// // if (builder instanceof Gauge.SupplierBased<? extends Number> sb) {
// // return NoOpMeter.Gauge.builder(sb.name(), sb.supplier());
// // }
// if (builder instanceof Timer.Builder tb) {
// return NoOpMeter.Timer.builder(tb.name()).build();
// }
// throw new IllegalArgumentException("Unrecognized meter builder type " + builder.getClass().getName());
// }

/**
* Returns a no-op {@link io.helidon.metrics.api.Meter} of the type implied by the builder's type, initialized with
* Returns a no-op {@link io.helidon.metrics.api.Meter} of the type implied by the builder's runtime type, initialized with
* the builder's name and other required parameters.
*
* @param builder original builder
* @param <B> type of the builder
* @param <M> type of the meter the builder produces
* @return corresponding no-op meter
*/
default <M extends Meter, B extends Meter.Builder<B, M>> Meter noOpMeter(B builder) {
default Meter noOpMeter(Meter.Builder<?, ?> builder) {
if (builder instanceof Counter.Builder cb) {
return NoOpMeter.Counter.builder(cb.name()).build();
}
Expand Down
34 changes: 34 additions & 0 deletions metrics/api/src/main/java/io/helidon/metrics/api/NoOpMeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ public Counter build() {
return new NoOpMeter.Counter(this);
}

// @Override
// public <T extends Meter.Builder<?, ?>> T copyTo(T target) {
// return target;
// }
}
}

Expand Down Expand Up @@ -487,6 +491,11 @@ public Double value() {
}
};
}

@Override
public Supplier<Double> supplier() {
return () -> fn.applyAsDouble(stateObject);
}
}

static class SupplierBased<N extends Number> extends Builder<SupplierBased<N>, N> {
Expand All @@ -506,6 +515,11 @@ public N value() {
}
};
}

@Override
public Supplier<N> supplier() {
return supplier;
}
}
}
}
Expand Down Expand Up @@ -738,6 +752,26 @@ public io.helidon.metrics.api.DistributionStatisticsConfig.Builder buckets(doubl
public io.helidon.metrics.api.DistributionStatisticsConfig.Builder buckets(Iterable<Double> buckets) {
return identity();
}

@Override
public Optional<Double> minimumExpectedValue() {
return Optional.empty();
}

@Override
public Optional<Double> maximumExpectedValue() {
return Optional.empty();
}

@Override
public Iterable<Double> percentiles() {
return Set.of();
}

@Override
public Iterable<Double> buckets() {
return Set.of();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
*/
class NoOpMeterRegistry implements MeterRegistry, NoOpWrapper {

static Builder builder() {
return new Builder();
}

@Override
public List<Meter> meters() {
return List.of();
Expand Down Expand Up @@ -115,6 +119,34 @@ public MeterRegistry onMeterRemoved(Consumer<Meter> listener) {
return this;
}

static class Builder implements MeterRegistry.Builder<Builder, NoOpMeterRegistry> {

@Override
public NoOpMeterRegistry build() {
return new NoOpMeterRegistry();
}

@Override
public Builder clock(Clock clock) {
return identity();
}

@Override
public Builder metricsConfig(MetricsConfig metricsConfig) {
return identity();
}

@Override
public Builder onMeterAdded(Consumer<Meter> addListener) {
return identity();
}

@Override
public Builder onMeterRemoved(Consumer<Meter> removeListener) {
return identity();
}
}

private <M extends Meter> Optional<M> find(Meter.Id id, Class<M> mClass) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public MetricsConfig metricsConfig() {
return metricsConfig;
}

@Override
public NoOpMeterRegistry.Builder meterRegistryBuilder() {
return NoOpMeterRegistry.builder();
}

@Override
public MeterRegistry createMeterRegistry(MetricsConfig metricsConfig) {
return new NoOpMeterRegistry();
Expand Down
Loading

0 comments on commit db10c3f

Please sign in to comment.