-
Notifications
You must be signed in to change notification settings - Fork 853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metric exporter REUSABLE_DATA memory mode configuration options #6304
Changes from 4 commits
81aff57
a52fc64
bf56ddd
e204ff3
df8a3fe
be86995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import static io.opentelemetry.api.internal.Utils.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import io.opentelemetry.sdk.common.export.MemoryMode; | ||
import io.prometheus.metrics.model.registry.PrometheusRegistry; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.function.Predicate; | ||
|
@@ -18,13 +19,26 @@ public final class PrometheusHttpServerBuilder { | |
|
||
static final int DEFAULT_PORT = 9464; | ||
private static final String DEFAULT_HOST = "0.0.0.0"; | ||
private static final MemoryMode DEFAULT_MEMORY_MODE = MemoryMode.IMMUTABLE_DATA; | ||
|
||
private String host = DEFAULT_HOST; | ||
private int port = DEFAULT_PORT; | ||
private PrometheusRegistry prometheusRegistry = new PrometheusRegistry(); | ||
private boolean otelScopeEnabled = true; | ||
@Nullable private Predicate<String> allowedResourceAttributesFilter; | ||
@Nullable private ExecutorService executor; | ||
private MemoryMode memoryMode = DEFAULT_MEMORY_MODE; | ||
|
||
PrometheusHttpServerBuilder() {} | ||
|
||
PrometheusHttpServerBuilder(PrometheusHttpServerBuilder builder) { | ||
this.host = builder.host; | ||
this.port = builder.port; | ||
this.prometheusRegistry = builder.prometheusRegistry; | ||
this.otelScopeEnabled = builder.otelScopeEnabled; | ||
this.allowedResourceAttributesFilter = builder.allowedResourceAttributesFilter; | ||
this.executor = builder.executor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you want to copy the memory mode as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point |
||
} | ||
|
||
/** Sets the host to bind to. If unset, defaults to {@value #DEFAULT_HOST}. */ | ||
public PrometheusHttpServerBuilder setHost(String host) { | ||
|
@@ -79,6 +93,13 @@ public PrometheusHttpServerBuilder setAllowedResourceAttributesFilter( | |
return this; | ||
} | ||
|
||
/** Set the {@link MemoryMode}. */ | ||
public PrometheusHttpServerBuilder setMemoryMode(MemoryMode memoryMode) { | ||
requireNonNull(memoryMode, "memoryMode"); | ||
this.memoryMode = memoryMode; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link PrometheusHttpServer} with the configuration of this builder which can be | ||
* registered with a {@link io.opentelemetry.sdk.metrics.SdkMeterProvider}. | ||
|
@@ -91,17 +112,7 @@ public PrometheusHttpServer build() { | |
executor, | ||
prometheusRegistry, | ||
otelScopeEnabled, | ||
allowedResourceAttributesFilter); | ||
} | ||
|
||
PrometheusHttpServerBuilder() {} | ||
|
||
PrometheusHttpServerBuilder(PrometheusHttpServerBuilder builder) { | ||
this.host = builder.host; | ||
this.port = builder.port; | ||
this.prometheusRegistry = builder.prometheusRegistry; | ||
this.otelScopeEnabled = builder.otelScopeEnabled; | ||
this.allowedResourceAttributesFilter = builder.allowedResourceAttributesFilter; | ||
this.executor = builder.executor; | ||
allowedResourceAttributesFilter, | ||
memoryMode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,11 +72,18 @@ The OpenTelemetry SDK can be disabled entirely. If disabled, `AutoConfiguredOpen | |
|
||
The following configuration properties are common to all exporters: | ||
|
||
| System property | Environment variable | Purpose | | ||
|-----------------------|-----------------------|----------------------------------------------------------------------------------------------------------------------------| | ||
| otel.traces.exporter | OTEL_TRACES_EXPORTER | List of exporters to be used for tracing, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| otel.metrics.exporter | OTEL_METRICS_EXPORTER | List of exporters to be used for metrics, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| otel.logs.exporter | OTEL_LOGS_EXPORTER | List of exporters to be used for logging, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| System property | Environment variable | Purpose | | ||
|---------------------------------------------|---------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| otel.traces.exporter | OTEL_TRACES_EXPORTER | List of exporters to be used for tracing, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| otel.metrics.exporter | OTEL_METRICS_EXPORTER | List of exporters to be used for metrics, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| otel.logs.exporter | OTEL_LOGS_EXPORTER | List of exporters to be used for logging, separated by commas. Default is `otlp`. `none` means no autoconfigured exporter. | | ||
| otel.java.experimental.exporter.memory_mode | OTEL_JAVA_EXPERIMENTAL_EXPORTER_MEMORY_MODE | If `reusable_data`, enable reusable memory mode (on exporters which support it) to reduce allocations. Default is `immutable_data`. This option is experimental and subject to change or removal.**[1]** | | ||
|
||
**[1]**: NOTE: The exporters which adhere | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like me to add documentation to the website about memory mode? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's an issue open somewhere to move all this autoconfigure docs to the website. For the moment, opentelemetry.io just links to this page for anything related to SDK environment variables. I think that's fine for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'm asking if we should elaborate more on the memory mode, or the configuration description suffices? |
||
to `otel.java.experimental.exporter.memory_mode=reusable_data` | ||
are `OtlpGrpcMetricExporter`, `OtlpHttpMetricExporter`, and `PrometheusHttpServer`. Support for | ||
additional exporters may be added in the future. | ||
|
||
|
||
#### OTLP exporter (span, metric, and log exporters) | ||
|
||
|
@@ -122,7 +129,6 @@ The [OpenTelemetry Protocol (OTLP)](https://github.com/open-telemetry/openteleme | |
| otel.exporter.otlp.metrics.temporality.preference | OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE | The preferred output aggregation temporality. Options include `DELTA`, `LOWMEMORY`, and `CUMULATIVE`. If `CUMULATIVE`, all instruments will have cumulative temporality. If `DELTA`, counter (sync and async) and histograms will be delta, up down counters (sync and async) will be cumulative. If `LOWMEMORY`, sync counter and histograms will be delta, async counter and up down counters (sync and async) will be cumulative. Default is `CUMULATIVE`. | | ||
| otel.exporter.otlp.metrics.default.histogram.aggregation | OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION | The preferred default histogram aggregation. Options include `BASE2_EXPONENTIAL_BUCKET_HISTOGRAM` and `EXPLICIT_BUCKET_HISTOGRAM`. Default is `EXPLICIT_BUCKET_HISTOGRAM`. | | ||
| otel.experimental.exporter.otlp.retry.enabled | OTEL_EXPERIMENTAL_EXPORTER_OTLP_RETRY_ENABLED | If `true`, enable [experimental retry support](#otlp-exporter-retry). Default is `false`. | | ||
| otel.java.experimental.exporter.otlp.metrics.memory_mode | OTEL_JAVA_EXPERIMENTAL_EXPORTER_OTLP_METRICS_MEMORY_MODE | If `reusable_data`, enable reusable memory mode to reduce allocations. Default is `immutable_data`. This option is experimental and subject to change or removal. | | ||
|
||
To configure the service name for the OTLP exporter, add the `service.name` key | ||
to the OpenTelemetry Resource ([see below](#opentelemetry-resource)), e.g. `OTEL_RESOURCE_ATTRIBUTES=service.name=myservice`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference I see in PrometheusHttpServer compared with PeriodMetricReader is that in Prometheus, multiple threads can call the metric producer collect(). I think if the mode is turned at REUSABLE_DATA, we should protect and make it only one request at a time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lock preventing concurrent reads from a particular meter here, but its not enough: A meter could be read from sequentially, but PrometheusHttpServer might still be serializing the MetricData from the first read when the second read begins and overwrites the data. So yes, a lock is needed when PrometheusHttpServer has reusable data enabled. This is interesting because it makes the tradeoff really clear: Do you want reduced memory allocation but no concurrent reads? Or higher memory allocation w/ concurrent reads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think we can place that in the javaDoc of the memory mode setter of the builder, once we fix the bug. Do we have place we write documentation of exporters in general ?