Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public final class SerializingMetricWriter implements MetricWriter {
private static final byte[] OK_SUMMARY = "OkSummary".getBytes(ISO_8859_1);
private static final byte[] ERROR_SUMMARY = "ErrorSummary".getBytes(ISO_8859_1);
private static final byte[] PROCESS_TAGS = "ProcessTags".getBytes(ISO_8859_1);
private static final byte[] GIT_COMMIT_SHA = "GitCommitSha".getBytes(ISO_8859_1);
private static final byte[] IS_TRACE_ROOT = "IsTraceRoot".getBytes(ISO_8859_1);
private static final byte[] SPAN_KIND = "SpanKind".getBytes(ISO_8859_1);
private static final byte[] PEER_TAGS = "PeerTags".getBytes(ISO_8859_1);
private static final byte[] HTTP_METHOD = "HTTPMethod".getBytes(ISO_8859_1);
private static final byte[] HTTP_ENDPOINT = "HTTPEndpoint".getBytes(ISO_8859_1);
private static final byte[] GRPC_STATUS_CODE = "GRPCStatusCode".getBytes(ISO_8859_1);
private static final byte[] SERVICE_SOURCE = "srv_src".getBytes(ISO_8859_1);
private static final byte[] GIT_COMMIT_SHA = "GitCommitSha".getBytes(ISO_8859_1);

// Constant declared here for compile-time folding
public static final int TRISTATE_TRUE = TriState.TRUE.serialValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,64 @@ class SerializingMetricWriterTest extends DDSpecification {
return validated
}
}

def "ServiceSource optional in the payload"() {
setup:
long startTime = MILLISECONDS.toNanos(System.currentTimeMillis())
long duration = SECONDS.toNanos(10)
WellKnownTags wellKnownTags = new WellKnownTags("runtimeid", "hostname", "env", "service", "version", "language")

def keyWithNoSource = new MetricKey("resource", "service", "operation", null, "type", 200, false, false, "server", [], "GET", "/api/users")
def keyWithSource = new MetricKey("resource", "service", "operation", "source", "type", 200, false, false, "server", [], "POST", null)

def content = [
Pair.of(keyWithNoSource, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L))),
Pair.of(keyWithSource, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L))),
]

ValidatingSink sink = new ValidatingSink(wellKnownTags, startTime, duration, content)
SerializingMetricWriter writer = new SerializingMetricWriter(wellKnownTags, sink, 128)

when:
writer.startBucket(content.size(), startTime, duration)
for (Pair<MetricKey, AggregateMetric> pair : content) {
writer.add(pair.getLeft(), pair.getRight())
}
writer.finishBucket()

then:
sink.validatedInput()
}

def "HTTPMethod and HTTPEndpoint fields are optional in payload"() {
setup:
long startTime = MILLISECONDS.toNanos(System.currentTimeMillis())
long duration = SECONDS.toNanos(10)
WellKnownTags wellKnownTags = new WellKnownTags("runtimeid", "hostname", "env", "service", "version", "language")

def keyWithBoth = new MetricKey("resource", "service", "operation", null, "type", 200, false, false, "server", [], "GET", "/api/users")
def keyWithMethodOnly = new MetricKey("resource", "service", "operation", null, "type", 200, false, false, "server", [], "POST", null)
def keyWithEndpointOnly = new MetricKey("resource", "service", "operation", null, "type", 200, false, false, "server", [], null, "/api/orders")
def keyWithNeither = new MetricKey("resource", "service", "operation", null, "type", 200, false, false, "client", [], null, null)

def content = [
Pair.of(keyWithBoth, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L))),
Pair.of(keyWithMethodOnly, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L))),
Pair.of(keyWithEndpointOnly, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L))),
Pair.of(keyWithNeither, new AggregateMetric().recordDurations(1, new AtomicLongArray(1L)))
]

ValidatingSink sink = new ValidatingSink(wellKnownTags, startTime, duration, content)
SerializingMetricWriter writer = new SerializingMetricWriter(wellKnownTags, sink, 128)

when:
writer.startBucket(content.size(), startTime, duration)
for (Pair<MetricKey, AggregateMetric> pair : content) {
writer.add(pair.getLeft(), pair.getRight())
}
writer.finishBucket()

then:
sink.validatedInput()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,15 @@ class WellKnownTagsTest extends DDSpecification {
wellKnownTags.getService() as String == "service"
wellKnownTags.getVersion() as String == "version"
wellKnownTags.getLanguage() as String == "language"
wellKnownTags.getGitCommitSha() as String == ""
}

def "well known tags with git commit sha"() {
given:
WellKnownTags wellKnownTags =
new WellKnownTags("runtimeid", "hostname", "env", "service", "version", "language", "abc123")
expect:
wellKnownTags.getRuntimeId() as String == "runtimeid"
wellKnownTags.getGitCommitSha() as String == "abc123"
}
}
Loading