Skip to content
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

Use dynamic headers for otel-dc-llm #68

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0-rc1")
implementation("org.snmp4j:snmp4j-agent:3.8.1")
implementation(files("libs/otel-dc-0.9.9.jar"))
implementation(files("libs/otel-dc-0.10.0.jar"))
implementation(files("libs/simp-snmp-0.1.3.jar"))

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
Expand Down
Binary file added host/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed host/libs/otel-dc-0.9.9.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion internal/otel-dc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.instana.dc"
version = "0.9.9"
version = "0.10.0"

repositories {
mavenCentral()
Expand Down
22 changes: 13 additions & 9 deletions internal/otel-dc/src/main/java/com/instana/dc/AbstractDc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.instana.dc;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import static com.instana.dc.DcUtil.getCert;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter;
Expand All @@ -10,13 +17,6 @@
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.resources.Resource;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import static com.instana.dc.DcUtil.getCert;

public abstract class AbstractDc implements IDc {
private final Map<String, Meter> meters = new ConcurrentHashMap<>();
private final Map<String, RawMetric> rawMetricsMap;
Expand Down Expand Up @@ -63,8 +63,10 @@ public static OtlpGrpcMetricExporter createOtlpGrpcMetricExporter(String otelBac
.setEndpoint(otelBackendUrl)
.setTimeout(timeout, TimeUnit.SECONDS);

HeadersSupplier supplier = HeadersSupplier.INSTANCE;
builder.setHeaders(supplier::getHeaders);
if (headers != null) {
builder.setHeaders(() -> headers);
supplier.updateHeaders(headers);
}
if (cert != null) {
builder.setTrustedCertificates(cert);
Expand All @@ -78,8 +80,10 @@ public static OtlpHttpMetricExporter createOtlpHttpMetricExporter(String otelBac
.setEndpoint(otelBackendUrl)
.setTimeout(timeout, TimeUnit.SECONDS);

HeadersSupplier supplier = HeadersSupplier.INSTANCE;
builder.setHeaders(supplier::getHeaders);
if (headers != null) {
builder.setHeaders(() -> headers);
supplier.updateHeaders(headers);
}
if (cert != null) {
builder.setTrustedCertificates(cert);
Expand Down
23 changes: 23 additions & 0 deletions internal/otel-dc/src/main/java/com/instana/dc/HeadersSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* (c) Copyright IBM Corp. 2024
* (c) Copyright Instana Inc.
*/
package com.instana.dc;

import java.util.HashMap;
import java.util.Map;

public enum HeadersSupplier {
INSTANCE;

private final Map<String, String> headers = new HashMap<>();

public synchronized void updateHeaders(Map<String, String> newHeaders) {
headers.clear();
headers.putAll(newHeaders);
}

public Map<String, String> getHeaders() {
return new HashMap<>(headers);
}
}
2 changes: 1 addition & 1 deletion llm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation("com.google.protobuf:protobuf-java-util:3.23.4")
implementation("com.linecorp.armeria:armeria:1.27.3")
implementation("com.linecorp.armeria:armeria-grpc:1.27.3")
implementation(files("libs/otel-dc-0.9.9.jar"))
implementation(files("libs/otel-dc-0.10.0.jar"))

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
Expand Down
Binary file added llm/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed llm/libs/otel-dc-0.9.9.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.instana.dc.llm.impl.llm;

import static com.instana.dc.DcUtil.OTEL_EXPORTER_OTLP_HEADERS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;

import com.google.common.collect.ImmutableList;
import com.instana.dc.HeadersSupplier;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.RequestContext;
import com.linecorp.armeria.common.RequestHeaders;

import io.grpc.stub.StreamObserver;
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
Expand Down Expand Up @@ -190,6 +197,26 @@ public void export(
ExportMetricsServiceRequest request,
StreamObserver<ExportMetricsServiceResponse> responseObserver) {

if (System.getenv(OTEL_EXPORTER_OTLP_HEADERS) == null) {
HttpRequest httpRequest = RequestContext.current().request();
RequestHeaders headers = httpRequest!=null ? httpRequest.headers() : null;
if ( headers != null ) {
HeadersSupplier supplier = HeadersSupplier.INSTANCE;
Map<String, String> newHeaders = new HashMap<>();
String xInstanaKey = headers.get("x-instana-key");
if (xInstanaKey != null && !xInstanaKey.isEmpty()) {
newHeaders.put("x-instana-key", xInstanaKey);
}
String xInstanaHost = headers.get("x-instana-host");
if (xInstanaHost != null && !xInstanaHost.isEmpty()) {
newHeaders.put("x-instana-host", xInstanaHost);
}
if ( ! newHeaders.isEmpty() ) {
supplier.updateHeaders(newHeaders);
}
}
}

synchronized (mutex) {
List<ResourceMetrics> allResourceMetrics = request.getResourceMetricsList();
for (ResourceMetrics resourceMetrics : allResourceMetrics) {
Expand Down
2 changes: 1 addition & 1 deletion rdb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation("io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.34.1")
implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0-rc1")
implementation(files("libs/otel-dc-0.9.9.jar"))
implementation(files("libs/otel-dc-0.10.0.jar"))
implementation(files("libs/ngdbc-2.4.64.jar"))
implementation("org.apache.commons:commons-dbcp2:2.11.0")

Expand Down
Binary file added rdb/libs/otel-dc-0.10.0.jar
Binary file not shown.
Binary file removed rdb/libs/otel-dc-0.9.9.jar
Binary file not shown.