Skip to content

Commit

Permalink
opensearch-project#20 Working on sending ubi queries as Otel.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Sep 12, 2024
1 parent 47f5e22 commit aef830a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ build
build-idea/
out/

volumes/
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM opensearchproject/opensearch:2.15.0
FROM opensearchproject/opensearch:2.16.0

COPY ./build/distributions/opensearch-ubi-2.15.0.0.zip /tmp/
COPY ./build/distributions/opensearch-ubi-2.16.0.0.zip /tmp/

RUN /usr/share/opensearch/bin/opensearch-plugin install --batch telemetry-otel
RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/opensearch-ubi-2.16.0.0.zip

RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/opensearch-ubi-2.15.0.0.zip
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ services:
logger.level: info
OPENSEARCH_INITIAL_ADMIN_PASSWORD: SuperSecretPassword_123
#ubi.dataprepper.url: "http://dataprepper-dev-os:2021/log/ingest"
# otel
telemetry.feature.tracer.enabled: true
telemetry.tracer.enabled: true
telemetry.tracer.sampler.probability: 1.0
opensearch.experimental.feature.telemetry.enabled: true
telemetry.otel.tracer.span.exporter.class: io.opentelemetry.exporter.logging.LoggingSpanExporter
telemetry.otel.tracer.exporter.batch_size: 1
telemetry.otel.tracer.exporter.max_queue_size: 3
volumes:
- "./volumes/logs:/usr/share/opensearch/logs"
ulimits:
memlock:
soft: -1
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
opensearchVersion = 2.15.0
ubiVersion = 2.15.0.0
opensearchVersion = 2.16.0
ubiVersion = 2.16.0.0
1 change: 0 additions & 1 deletion licenses/jackson-annotations-2.17.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions licenses/jackson-annotations-2.17.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
147b7b9412ffff24339f8aba080b292448e08698
1 change: 0 additions & 1 deletion licenses/jackson-databind-2.17.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions licenses/jackson-databind-2.17.2.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e6deb029e5901e027c129341fac39e515066b68c
26 changes: 25 additions & 1 deletion src/main/java/org/opensearch/ubi/UbiActionFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.opensearch.env.Environment;
import org.opensearch.search.SearchHit;
import org.opensearch.tasks.Task;
import org.opensearch.telemetry.tracing.Span;
import org.opensearch.telemetry.tracing.SpanBuilder;
import org.opensearch.telemetry.tracing.Tracer;
import org.opensearch.ubi.ext.UbiParameters;

Expand Down Expand Up @@ -138,7 +140,7 @@ public void onResponse(Response response) {
final QueryResponse queryResponse = new QueryResponse(queryId, queryResponseId, queryResponseHitIds);
final QueryRequest queryRequest = new QueryRequest(queryId, userQuery, userId, query, queryAttributes, queryResponse);

UbiOTel.send(task, tracer, queryRequest);
sendOtelTrace(task, tracer, queryRequest);

final String dataPrepperUrl = environment.settings().get(UbiSettings.DATA_PREPPER_URL);
if(dataPrepperUrl != null) {
Expand Down Expand Up @@ -304,4 +306,26 @@ private String getResourceFile(final String fileName) {
}
}

private void sendOtelTrace(final Task task, final Tracer tracer, final QueryRequest queryRequest) {

final Span span = tracer.startSpan(SpanBuilder.from(task, "ubi_search"));

span.addAttribute("ubi.user_id", queryRequest.getQueryId());
span.addAttribute("ubi.query", queryRequest.getQuery());
span.addAttribute("ubi.user_query", queryRequest.getUserQuery());
span.addAttribute("ubi.client_id", queryRequest.getClientId());
span.addAttribute("ubi.timestamp", queryRequest.getTimestamp());

for (final String key : queryRequest.getQueryAttributes().keySet()) {
span.addAttribute("ubi.attribute." + key, queryRequest.getQueryAttributes().get(key));
}

span.addAttribute("ubi.query_response.response_id", queryRequest.getQueryResponse().getQueryResponseId());
span.addAttribute("ubi.query_response.query_id", queryRequest.getQueryResponse().getQueryId());
span.addAttribute("ubi.query_response.response_id", String.join(",", queryRequest.getQueryResponse().getQueryResponseObjectIds()));

span.endSpan();

}

}
48 changes: 0 additions & 48 deletions src/main/java/org/opensearch/ubi/UbiOTel.java

This file was deleted.

0 comments on commit aef830a

Please sign in to comment.