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

Improve the aggregation logic for tokens and durations #62

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion llm/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
llm.application: LLM_DC

instances:
- otel.backend.url: http://localhost:4317
- otel.agentless.mode: true
otel.backend.url: http://<backend/agent-otlp-acceptor>:4317
callback.interval: 10
otel.service.name: DC1
otel.service.port: 8000
#Only configure the settings of the AI provider you are using
Expand Down
47 changes: 25 additions & 22 deletions llm/src/main/java/com/instana/dc/llm/AbstractLLMDc.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/
package com.instana.dc.llm;

import com.instana.dc.AbstractDc;
import com.instana.dc.llm.DataCollector.CustomDcConfig;
import com.instana.dc.resources.ContainerResource;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import static com.instana.dc.DcUtil.CALLBACK_INTERVAL;
import static com.instana.dc.DcUtil.INSTANA_PLUGIN;
import static com.instana.dc.DcUtil.OTEL_BACKEND_URL;
import static com.instana.dc.DcUtil.OTEL_BACKEND_USING_HTTP;
import static com.instana.dc.DcUtil.OTEL_SERVICE_NAME;
import static com.instana.dc.DcUtil.POLLING_INTERVAL;
import static com.instana.dc.DcUtil.mergeResourceAttributesFromEnv;
import static io.opentelemetry.api.common.AttributeKey.stringKey;

import java.net.InetAddress;
import java.net.UnknownHostException;
Expand All @@ -21,9 +21,16 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import static com.instana.dc.DcUtil.*;
import static com.instana.dc.llm.LLMDcUtil.*;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import com.instana.dc.AbstractDc;
import com.instana.dc.llm.DataCollector.CustomDcConfig;
import com.instana.dc.resources.ContainerResource;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.ResourceAttributes;
public abstract class AbstractLLMDc extends AbstractDc {
private static final Logger logger = Logger.getLogger(AbstractLLMDc.class.getName());

Expand All @@ -36,9 +43,8 @@ public abstract class AbstractLLMDc extends AbstractDc {
private String serviceInstanceId;
private CustomDcConfig cdcConfig;

// Used the fixed 10 seconds for poll interval
public static final int LLM_POLL_INTERVAL = 10;
public static final int LLM_CLBK_INTERVAL = 10;
public static final int DEFAULT_LLM_POLL_INTERVAL = 10;
public static final int DEFAULT_LLM_CLBK_INTERVAL = 10;

private final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();

Expand All @@ -52,10 +58,8 @@ public String getHostName() {

public AbstractLLMDc(Map<String, Object> properties, CustomDcConfig cdcConfig) {
super(new LLMRawMetricRegistry().getMap());
// pollInterval = (Integer) properties.getOrDefault(POLLING_INTERVAL, DEFAULT_POLL_INTERVAL);
// callbackInterval = (Integer) properties.getOrDefault(CALLBACK_INTERVAL, DEFAULT_CALLBACK_INTERVAL);
pollInterval = LLM_POLL_INTERVAL;
callbackInterval = LLM_CLBK_INTERVAL;
callbackInterval = (Integer) properties.getOrDefault(CALLBACK_INTERVAL, DEFAULT_LLM_CLBK_INTERVAL);
pollInterval = (Integer) properties.getOrDefault(POLLING_INTERVAL, callbackInterval);
otelBackendUrl = (String) properties.get(OTEL_BACKEND_URL);
otelUsingHttp = (Boolean) properties.getOrDefault(OTEL_BACKEND_USING_HTTP, Boolean.FALSE);
serviceName = (String) properties.get(OTEL_SERVICE_NAME);
Expand All @@ -68,12 +72,11 @@ public Resource getResourceAttributes() {
Resource resource = Resource.getDefault()
.merge(Resource.create(Attributes.of(
stringKey("llm.platform"), "LLM",
stringKey(SERVICE_NAME), serviceName,
stringKey(SERVICE_INSTANCE_ID), serviceInstanceId
ResourceAttributes.SERVICE_NAME, serviceName,
ResourceAttributes.SERVICE_INSTANCE_ID, serviceInstanceId
)))
.merge(Resource.create(Attributes.of(
stringKey("INSTANA_PLUGIN"), // com.instana.agent.sensorsdk.semconv.ResourceAttributes.INSTANA_PLUGIN
"llmonitor" // com.instana.agent.sensorsdk.semconv.ResourceAttributes.LLM
stringKey(INSTANA_PLUGIN), "llmonitor"
)));

resource = resource.merge(ContainerResource.get());
Expand Down
7 changes: 4 additions & 3 deletions llm/src/main/java/com/instana/dc/llm/DataCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*/
package com.instana.dc.llm;

import static com.instana.dc.DcUtil.CONFIG_ENV;
import static com.instana.dc.DcUtil.CONFIG_YAML;
import static com.instana.dc.DcUtil.LOGGING_PROP;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,9 +18,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import static com.instana.dc.DcUtil.CONFIG_ENV;
import static com.instana.dc.DcUtil.CONFIG_YAML;
import static com.instana.dc.DcUtil.LOGGING_PROP;
import com.instana.dc.IDc;

public class DataCollector {
Expand Down
4 changes: 1 addition & 3 deletions llm/src/main/java/com/instana/dc/llm/LLMDcRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
*/
package com.instana.dc.llm;

import com.instana.dc.llm.AbstractLLMDc;
import com.instana.dc.llm.impl.llm.LLMDc;

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

import com.instana.dc.llm.impl.llm.LLMDc;
public class LLMDcRegistry {
/* Add all DataCollector implementations here:
**/
Expand Down
3 changes: 1 addition & 2 deletions llm/src/main/java/com/instana/dc/llm/LLMDcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class LLMDcUtil {
*/
public static final String DEFAULT_INSTRUMENTATION_SCOPE = "instana.sensor-sdk.dc.llm";
public static final String DEFAULT_INSTRUMENTATION_SCOPE_VER = "1.0.0";
public static final String SERVICE_NAME = "service.name";
public static final String SERVICE_INSTANCE_ID = "service.instance.id";
public final static String WATSONX_PRICE_PROMPT_TOKES_PER_KILO = "watsonx.price.prompt.tokens.per.kilo";
public final static String WATSONX_PRICE_COMPLETE_TOKES_PER_KILO = "watsonx.price.complete.tokens.per.kilo";
public final static String OPENAI_PRICE_PROMPT_TOKES_PER_KILO = "openai.price.prompt.tokens.per.kilo";
Expand All @@ -24,6 +22,7 @@ public class LLMDcUtil {
public final static String BEDROCK_PRICE_PROMPT_TOKES_PER_KILO = "bedrock.price.prompt.tokens.per.kilo";
public final static String BEDROCK_PRICE_COMPLETE_TOKES_PER_KILO = "bedrock.price.complete.tokens.per.kilo";
public final static String SERVICE_LISTEN_PORT = "otel.service.port";
public final static String OTEL_AGENTLESS_MODE = "otel.agentless.mode";

/* Configurations for Metrics:
*/
Expand Down
25 changes: 21 additions & 4 deletions llm/src/main/java/com/instana/dc/llm/LLMRawMetricRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@
*/
package com.instana.dc.llm;

import com.instana.dc.RawMetric;
import static com.instana.dc.InstrumentType.GAUGE;
import static com.instana.dc.InstrumentType.UPDOWN_COUNTER;
import static com.instana.dc.llm.LLMDcUtil.LLM_COST_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_COST_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_COST_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_MAX_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_MAX_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_MAX_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_DURATION_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_REQ_COUNT_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_STATUS_UNIT;
import static com.instana.dc.llm.LLMDcUtil.LLM_TOKEN_DESC;
import static com.instana.dc.llm.LLMDcUtil.LLM_TOKEN_NAME;
import static com.instana.dc.llm.LLMDcUtil.LLM_TOKEN_UNIT;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.instana.dc.InstrumentType.GAUGE;
import static com.instana.dc.InstrumentType.UPDOWN_COUNTER;
import static com.instana.dc.llm.LLMDcUtil.*;
import com.instana.dc.RawMetric;

public class LLMRawMetricRegistry {
private final Map<String, RawMetric> map = new ConcurrentHashMap<String, RawMetric>() {{
Expand Down
Loading