Skip to content

Commit

Permalink
NH-93485: export metrics via otlp
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverchuk committed Oct 30, 2024
1 parent ed24d89 commit 7ec894b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ protected MetricsMonitor buildMetricsMonitor() {
new TracingReporterMetricsCollector(
ReporterProvider.getEventReporter()));

String collector =
(String) ConfigManager.getConfig(ConfigProperty.AGENT_COLLECTOR);
if (collector != null && !collector.contains("appoptics.com")) {
Boolean enabled =
(Boolean)
ConfigManager.getConfig(
ConfigProperty.AGENT_EXPORT_METRICS_ENABLED);
if (enabled == null || enabled) {
metricsCollector.removeCollector(MetricsCategory.TRACING_REPORTER);
}

return MetricsMonitor.buildInstance(configs, metricsCollector);
} catch (InvalidConfigException | ClientException e) {
logger.debug(String.format("Error creating MetricsCollector: %s", e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ public boolean isEndRequired() {

private static class OpenTelemetryInboundMeasurementReporter extends MetricSpanReporter {
public static final String MEASUREMENT_NAME_OLD = "TransactionResponseTime";
public static final String MEASUREMENT_NAME = "ResponseTime";

// cannot use Guava cache here, jboss issue...
private final Map<MetricKey, SummaryLongMeasurement> measurements =
new ConcurrentHashMap<MetricKey, SummaryLongMeasurement>();
// private final String measurementName;

protected OpenTelemetryInboundMeasurementReporter() {}
protected OpenTelemetryInboundMeasurementReporter() {
// super(TRANSACTION_LATENCY_METRIC_NAME);
}

@Override
public List<MetricsEntry<?>> consumeMetricEntries() {
Expand Down Expand Up @@ -186,6 +190,9 @@ private void reportMetrics(SpanData spanData) {
if (collector != null && collector.contains("appoptics.com")) {
logger.debug("Sending metrics to AO");
recordMeasurementEntryForAo(aoPrimaryKeys, aoSecondaryKey, duration);
} else {
logger.debug("Sending metrics to SWO");
recordMeasurementEntryForSwo(swoTags, duration);
}
}

Expand All @@ -206,11 +213,24 @@ protected void recordMeasurementEntryForAo(
.recordValue(duration);
}
}

protected void recordMeasurementEntryForSwo(Map<String, String> tags, long duration) {
Boolean enabled =
(Boolean) ConfigManager.getConfig(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED);
if (enabled == null || enabled) {
return;
}
MetricKey measurementKey = new MetricKey(MEASUREMENT_NAME, new HashMap<>(tags));
this.measurements
.computeIfAbsent(measurementKey, k -> new SummaryLongMeasurement())
.recordValue(duration);
}
}

// TODO copied from Core, should improve to avoid code duplication
private static class OpenTelemetryInboundHistogramReporter extends MetricSpanReporter {
public static final String TRANSACTION_LATENCY_METRIC_NAME = "TransactionResponseTime";
public static final String TRANSACTION_NAME_TAG_KEY = "TransactionName";
private static final HistogramFactory.HistogramType HISTOGRAM_TYPE =
HistogramFactory.HistogramType.HDR;

Expand Down Expand Up @@ -243,16 +263,12 @@ public Map<MetricKey, Histogram> consumeHistograms() {
}

public void reportMetrics(SpanData spanData) {
String collector = (String) ConfigManager.getConfig(ConfigProperty.AGENT_COLLECTOR);
if (collector != null && !collector.contains("appoptics.com")) {
return;
}

final MetricKey serviceHistogramKey =
new MetricKey(
TRANSACTION_LATENCY_METRIC_NAME,
null); // globally for all transactions within this service
final Histogram serviceHistogram =
final Histogram serviceHistogram;
serviceHistogram =
histograms.computeIfAbsent(
serviceHistogramKey,
k -> HistogramFactory.buildHistogram(HISTOGRAM_TYPE, MAX_DURATION));
Expand Down

0 comments on commit 7ec894b

Please sign in to comment.