Skip to content

Commit

Permalink
Merge pull request #768 from DataDog/tyler/metrics-double
Browse files Browse the repository at this point in the history
Agent doesn’t like getting floats.
  • Loading branch information
tylerbenson authored Mar 15, 2019
2 parents d45d672 + 4722621 commit 071c16a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package datadog.trace.agent

import datadog.trace.agent.test.IntegrationTestUtils
import jvmbootstraptest.LogManagerSetter
import spock.lang.Retry
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Timeout

import java.lang.management.ManagementFactory
import java.lang.management.RuntimeMXBean

@Retry
@Timeout(30)
class CustomLogManagerTest extends Specification {
// Run all tests using forked jvm because groovy has already set the global log manager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ public void setMetric(final String key, final Number value) {
if (metrics.get() == null) {
metrics.compareAndSet(null, new ConcurrentHashMap<String, Number>());
}
metrics.get().put(key, value);
if (value instanceof Float) {
metrics.get().put(key, value.doubleValue());
} else {
metrics.get().put(key, value);
}
}
/**
* Add a tag to the span. Tags are not propagated to the children
Expand Down
28 changes: 28 additions & 0 deletions dd-trace-ot/src/test/groovy/datadog/trace/DDSpanContextTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@ class DDSpanContextTest extends Specification {
"tag-with-bool" | false
"tag_with_float" | 0.321
}

def "metrics use the expected types"() {
// floats should be converted to doubles.
setup:
def context = SpanFactory.newSpanOf(0).context
context.setMetric("test", value)
def metrics = context.getMetrics()

expect:
type.isInstance(metrics["test"])

where:
type | value
Integer | 0
Integer | Integer.MAX_VALUE
Integer | Integer.MIN_VALUE
Short | Short.MAX_VALUE
Short | Short.MIN_VALUE
Double | Float.MAX_VALUE
Double | Float.MIN_VALUE
Double | Double.MAX_VALUE
Double | Double.MIN_VALUE
Double | 1f
Double | 1d
Double | 0.5f
Double | 0.5d
Integer | 0x55
}
}

0 comments on commit 071c16a

Please sign in to comment.