Skip to content

Commit

Permalink
Improve database semconv stability test formatting (open-telemetry#12580
Browse files Browse the repository at this point in the history
)
  • Loading branch information
trask authored and Alex Kats committed Nov 21, 2024
1 parent 61c6eed commit ba18df8
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
Expand All @@ -22,7 +23,6 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -108,9 +108,7 @@ void syncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
"USE " + parameter.keyspace))),
equalTo(maybeStable(DB_STATEMENT), "USE " + parameter.keyspace))),
trace ->
trace.hasSpansSatisfyingExactly(
span ->
Expand All @@ -124,18 +122,10 @@ void syncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_NAME),
parameter.keyspace),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table))));
equalTo(maybeStable(DB_NAME), parameter.keyspace),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table))));
} else {
testing.waitAndAssertTraces(
trace ->
Expand All @@ -151,15 +141,9 @@ void syncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table))));
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table))));
}

session.close();
Expand Down Expand Up @@ -196,9 +180,7 @@ void asyncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
"USE " + parameter.keyspace))),
equalTo(maybeStable(DB_STATEMENT), "USE " + parameter.keyspace))),
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
Expand All @@ -213,18 +195,10 @@ void asyncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_NAME),
parameter.keyspace),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table)),
equalTo(maybeStable(DB_NAME), parameter.keyspace),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)),
span ->
span.hasName("callbackListener")
.hasKind(SpanKind.INTERNAL)
Expand All @@ -245,15 +219,9 @@ void asyncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table)),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)),
span ->
span.hasName("callbackListener")
.hasKind(SpanKind.INTERNAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.cassandra.v4.common;

import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
Expand Down Expand Up @@ -33,7 +34,6 @@
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -113,15 +113,9 @@ void syncTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_NAME),
parameter.keyspace),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(maybeStable(DB_NAME), parameter.keyspace),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"),
equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"),
satisfies(
Expand All @@ -132,9 +126,7 @@ void syncTest(Parameter parameter) {
val -> val.isInstanceOf(Boolean.class)),
equalTo(DB_CASSANDRA_PAGE_SIZE, 5000),
equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table))));
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table))));

session.close();
}
Expand Down Expand Up @@ -175,15 +167,9 @@ void asyncTest(Parameter parameter) throws Exception {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_NAME),
parameter.keyspace),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(maybeStable(DB_NAME), parameter.keyspace),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"),
equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"),
satisfies(
Expand All @@ -194,9 +180,7 @@ void asyncTest(Parameter parameter) throws Exception {
val -> val.isInstanceOf(Boolean.class)),
equalTo(DB_CASSANDRA_PAGE_SIZE, 5000),
equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table)),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)),
span ->
span.hasName("child")
.hasKind(SpanKind.INTERNAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.testing.cassandra.v4_4;

import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
Expand All @@ -29,7 +30,6 @@
import com.datastax.oss.driver.api.core.CqlSession;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.cassandra.v4.common.AbstractCassandraTest;
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -73,15 +73,9 @@ void reactiveTest(Parameter parameter) {
equalTo(NETWORK_PEER_ADDRESS, cassandraIp),
equalTo(NETWORK_PEER_PORT, cassandraPort),
equalTo(DB_SYSTEM, "cassandra"),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_NAME),
parameter.keyspace),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_STATEMENT),
parameter.expectedStatement),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
parameter.operation),
equalTo(maybeStable(DB_NAME), parameter.keyspace),
equalTo(maybeStable(DB_STATEMENT), parameter.expectedStatement),
equalTo(maybeStable(DB_OPERATION), parameter.operation),
equalTo(DB_CASSANDRA_CONSISTENCY_LEVEL, "LOCAL_ONE"),
equalTo(DB_CASSANDRA_COORDINATOR_DC, "datacenter1"),
satisfies(
Expand All @@ -92,9 +86,7 @@ void reactiveTest(Parameter parameter) {
val -> val.isInstanceOf(Boolean.class)),
equalTo(DB_CASSANDRA_PAGE_SIZE, 5000),
equalTo(DB_CASSANDRA_SPECULATIVE_EXECUTION_COUNT, 0),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_CASSANDRA_TABLE),
parameter.table)),
equalTo(maybeStable(DB_CASSANDRA_TABLE), parameter.table)),
span ->
span.hasName("child")
.hasKind(SpanKind.INTERNAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.couchbase;

import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
Expand All @@ -23,7 +24,6 @@
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil;
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -93,9 +93,7 @@ void hasBucket(BucketSettings bucketSettings)
equalTo(
DB_SYSTEM,
DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
"Cluster.openBucket")),
equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")),
span ->
assertCouchbaseSpan(span, "ClusterManager.hasBucket")
.hasParent(trace.getSpan(0))));
Expand Down Expand Up @@ -136,9 +134,7 @@ void upsert(BucketSettings bucketSettings)
equalTo(
DB_SYSTEM,
DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
"Cluster.openBucket")),
equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")),
span ->
assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name())
.hasParent(trace.getSpan(1))));
Expand Down Expand Up @@ -186,9 +182,7 @@ void upsertAndGet(BucketSettings bucketSettings)
equalTo(
DB_SYSTEM,
DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
"Cluster.openBucket")),
equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")),
span ->
assertCouchbaseSpan(span, "Bucket.upsert", bucketSettings.name())
.hasParent(trace.getSpan(1)),
Expand Down Expand Up @@ -233,9 +227,7 @@ void query() throws ExecutionException, InterruptedException, TimeoutException {
equalTo(
DB_SYSTEM,
DbIncubatingAttributes.DbSystemIncubatingValues.COUCHBASE),
equalTo(
SemconvStabilityUtil.getAttributeKey(DB_OPERATION),
"Cluster.openBucket")),
equalTo(maybeStable(DB_OPERATION), "Cluster.openBucket")),
span ->
assertCouchbaseSpan(
span,
Expand Down
Loading

0 comments on commit ba18df8

Please sign in to comment.