Skip to content

Commit

Permalink
fix(store): skip initializing StreamMetricsManager when exporter disa…
Browse files Browse the repository at this point in the history
…bled

1. skip initializing StreamMetricsManager when exporter disabled

Signed-off-by: TheR1sing3un <[email protected]>
  • Loading branch information
TheR1sing3un committed Nov 6, 2023
1 parent 6abb4c9 commit edbca63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ private void initDynamicMetrics() {

@Override
public void start() {
initDynamicMetrics();
MetricsExporterType metricsExporterType = MetricsExporterType.valueOf(metricsConfig.exporterType());
if (metricsExporterType != MetricsExporterType.DISABLE) {
initDynamicMetrics();
}
this.started = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.automq.stream.s3.metrics.Counter;
import com.automq.stream.s3.metrics.Gauge;
import com.automq.stream.s3.metrics.Histogram;
import com.automq.stream.s3.metrics.NoopS3StreamMetricsGroup;
import com.automq.stream.s3.metrics.S3StreamMetricsGroup;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.metrics.Meter;
Expand All @@ -31,6 +32,7 @@ public class StreamMetricsManager implements MetricsManager, S3StreamMetricsGrou

private static Supplier<AttributesBuilder> attributesBuilderSupplier;
private static Meter meter;
private static NoopS3StreamMetricsGroup noopS3StreamMetricsGroup = new NoopS3StreamMetricsGroup();

@Override
public void initAttributesBuilder(Supplier<AttributesBuilder> attributesBuilderSupplier) {
Expand All @@ -49,16 +51,26 @@ public void initDynamicMetrics(Meter meter) {

@Override
public Counter newCounter(String name, Map<String, String> tags) {
return new StreamMetricsCounter(name, tags, meter, attributesBuilderSupplier);
if (meter != null && attributesBuilderSupplier != null) {
return new StreamMetricsCounter(name, tags, meter, attributesBuilderSupplier);
}
return noopS3StreamMetricsGroup.newCounter(name, tags);
}

@Override
public Histogram newHistogram(String name, Map<String, String> tags) {
return new StreamMetricsHistogram(name, tags, meter, attributesBuilderSupplier);
if (meter != null && attributesBuilderSupplier != null) {
return new StreamMetricsHistogram(name, tags, meter, attributesBuilderSupplier);
}
return noopS3StreamMetricsGroup.newHistogram(name, tags);
}

@Override
public void newGauge(String name, Map<String, String> tags, Gauge gauge) {
new StreamMetricsGauge(name, tags, meter, attributesBuilderSupplier, gauge);
if (meter != null && attributesBuilderSupplier != null) {
new StreamMetricsGauge(name, tags, meter, attributesBuilderSupplier, gauge);
return;
}
noopS3StreamMetricsGroup.newGauge(name, tags, gauge);
}
}

0 comments on commit edbca63

Please sign in to comment.