Skip to content

Commit 005f711

Browse files
authored
Merge branch 'master' into andrea.marziali/css2
2 parents bfc6609 + 89e92d5 commit 005f711

File tree

7 files changed

+135
-22
lines changed

7 files changed

+135
-22
lines changed

.gitlab-ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ pre-release-checks:
200200
allow_failure: false
201201
script:
202202
- |
203-
SONATYPE_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
204-
SONATYPE_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
203+
MAVEN_CENTRAL_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
204+
MAVEN_CENTRAL_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
205205
# See https://central.sonatype.org/publish/publish-portal-api/
206206
# 15e0cbbb-deff-421e-9e02-296a24d0cada is deployment, any deployment id listed in central work, the idea is to check whether the token can authenticate
207-
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$SONATYPE_USERNAME:$SONATYPE_PASSWORD" | base64)"
207+
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$MAVEN_CENTRAL_USERNAME:$MAVEN_CENTRAL_PASSWORD" | base64)"
208208
if [ $? -ne 0 ]; then
209209
echo "Failed to authenticate against central. Check credentials, see https://datadoghq.atlassian.net/wiki/x/Oog5OgE"
210210
exit 1
@@ -768,8 +768,8 @@ deploy_to_di_backend:manual:
768768
UPSTREAM_COMMIT_AUTHOR: $CI_COMMIT_AUTHOR
769769
UPSTREAM_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
770770

771-
# If the deploy_to_sonatype job is re-run, re-trigger the deploy_artifacts_to_github job as well so that the artifacts match.
772-
deploy_to_sonatype:
771+
# If the deploy_to_maven_central job is re-run, re-trigger the deploy_artifacts_to_github job as well so that the artifacts match.
772+
deploy_to_maven_central:
773773
extends: .gradle_build
774774
stage: publish
775775
needs: [ build ]
@@ -786,8 +786,8 @@ deploy_to_sonatype:
786786
- when: manual
787787
allow_failure: true
788788
script:
789-
- export SONATYPE_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
790-
- export SONATYPE_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
789+
- export MAVEN_CENTRAL_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
790+
- export MAVEN_CENTRAL_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
791791
- export GPG_PRIVATE_KEY=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.signing.gpg_private_key --with-decryption --query "Parameter.Value" --out text)
792792
- export GPG_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.signing.gpg_passphrase --with-decryption --query "Parameter.Value" --out text)
793793
- ./gradlew -PbuildInfo.build.number=$CI_JOB_ID publishToSonatype closeSonatypeStagingRepository -PskipTests $GRADLE_ARGS
@@ -805,11 +805,11 @@ deploy_artifacts_to_github:
805805
when: never
806806
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
807807
when: on_success
808-
# Requires the deploy_to_sonatype job to have run first (the UP-TO-DATE gradle check across jobs is broken)
808+
# Requires the deploy_to_maven_central job to have run first (the UP-TO-DATE gradle check across jobs is broken)
809809
# This will deploy the artifacts built from the publishToSonatype task to the GitHub release
810810
needs:
811-
- job: deploy_to_sonatype
812-
# The deploy_to_sonatype job is not run for release candidate versions
811+
- job: deploy_to_maven_central
812+
# The deploy_to_maven_central job is not run for release candidate versions
813813
optional: true
814814
script:
815815
- aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.gh_release_token --with-decryption --query "Parameter.Value" --out text > github-token.txt

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ nexusPublishing {
110110
sonatype {
111111
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
112112
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
113-
username = System.getenv("SONATYPE_USERNAME")
114-
password = System.getenv("SONATYPE_PASSWORD")
113+
username = System.getenv("MAVEN_CENTRAL_USERNAME")
114+
password = System.getenv("MAVEN_CENTRAL_PASSWORD")
115115
}
116116
}
117117
}

dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
365365
"-Duser.dir=${projectHome.toAbsolutePath()}".toString(),
366366
"-Dmaven.mainClass=org.apache.maven.cli.MavenCli".toString(),
367367
"-Dmaven.multiModuleProjectDirectory=${projectHome.toAbsolutePath()}".toString(),
368+
"-Dmaven.artifact.threads=10",
368369
]
369370
if (runWithAgent) {
370371
if (System.getenv("DD_CIVISIBILITY_SMOKETEST_DEBUG_PARENT") != null) {

dd-trace-core/src/main/java/datadog/trace/common/metrics/ConflatingMetricsAggregator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,6 @@ private void disable() {
325325
features.discover();
326326
if (!features.supportsMetrics()) {
327327
log.debug("Disabling metric reporting because an agent downgrade was detected");
328-
AgentTaskScheduler.Scheduled<?> cancellation = this.cancellation;
329-
if (null != cancellation) {
330-
cancellation.cancel();
331-
}
332-
this.thread.interrupt();
333328
this.pending.clear();
334329
this.batchPool.clear();
335330
this.inbox.clear();
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package datadog.trace.common.metrics
2+
3+
import datadog.communication.ddagent.SharedCommunicationObjects
4+
import datadog.trace.api.Config
5+
import datadog.trace.core.test.DDCoreSpecification
6+
7+
import java.util.concurrent.CountDownLatch
8+
9+
import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer
10+
11+
class MetricsReliabilityTest extends DDCoreSpecification {
12+
13+
static class State {
14+
boolean agentMetricsAvailable
15+
boolean receivedStats
16+
boolean receivedClientComputedHeader
17+
CountDownLatch latch
18+
def reset(agentMetricsAvailable) {
19+
this.agentMetricsAvailable = agentMetricsAvailable
20+
receivedStats = false
21+
receivedClientComputedHeader = false
22+
latch = new CountDownLatch(1)
23+
}
24+
}
25+
26+
static newAgent(State state) {
27+
httpServer {
28+
handlers {
29+
get("/info") {
30+
response.send('{"endpoints":[' + (state.agentMetricsAvailable ? '"/v0.6/stats", ' : '')
31+
+ '"/v0.4/traces"]}')
32+
state.latch.countDown()
33+
}
34+
post("/v0.6/stats", {
35+
state.receivedStats = true
36+
response.status(state.agentMetricsAvailable ? 200 : 404).send()
37+
})
38+
put("/v0.4/traces", {
39+
state.receivedClientComputedHeader = "true" == request.getHeader('Datadog-Client-Computed-Stats')
40+
response.status(200).send()
41+
})
42+
}
43+
}
44+
}
45+
46+
def "metrics should reliably handle momentary downgrades"() {
47+
setup:
48+
def state = new State()
49+
state.reset(true)
50+
def agent = newAgent(state)
51+
agent.start()
52+
def props = new Properties()
53+
props.put("trace.agent.url", agent.getAddress().toString())
54+
props.put("trace.tracer.metrics.enabled", "true")
55+
def config = Config.get(props)
56+
def sharedComm = new SharedCommunicationObjects()
57+
sharedComm.createRemaining(config)
58+
def featuresDiscovery = sharedComm.featuresDiscovery(config)
59+
def tracer = tracerBuilder().sharedCommunicationObjects(sharedComm).config(config).build()
60+
61+
when: "metrics enabled and discovery is performed"
62+
featuresDiscovery.discover()
63+
64+
then: "should support metrics"
65+
state.latch.await()
66+
assert featuresDiscovery.supportsMetrics()
67+
68+
when: "a span is published"
69+
tracer.startSpan("test", "test").finish()
70+
tracer.flush()
71+
tracer.flushMetrics()
72+
73+
then: "should have sent statistics and informed the agent that we calculate the stats"
74+
assert state.receivedClientComputedHeader
75+
assert state.receivedStats
76+
77+
when: "simulate an agent downgrade"
78+
state.reset(false)
79+
tracer.startSpan("test", "test").finish()
80+
tracer.flush()
81+
tracer.flushMetrics()
82+
83+
then: "a discovery should have done - we do not support anymore stats calculation"
84+
state.latch.await()
85+
assert !featuresDiscovery.supportsMetrics()
86+
87+
when: "a span is published"
88+
tracer.startSpan("test", "test").finish()
89+
tracer.flush()
90+
tracer.flushMetrics()
91+
92+
then: "should have not sent statistics and informed the agent that we don't calculate the stats anymore"
93+
assert !state.receivedClientComputedHeader
94+
assert !state.receivedStats
95+
96+
when: "we detect that the agent can calculate the stats again"
97+
state.reset(true)
98+
featuresDiscovery.discover()
99+
100+
then: "we should understand it"
101+
state.latch.await()
102+
assert featuresDiscovery.supportsMetrics()
103+
104+
when: "a span is published"
105+
tracer.startSpan("test", "test").finish()
106+
tracer.flush()
107+
tracer.flushMetrics()
108+
109+
then: "we should have sent the stats and informed the agent to not calculate the stats on the trace payload"
110+
assert state.receivedClientComputedHeader
111+
assert state.receivedStats
112+
113+
cleanup:
114+
tracer.close()
115+
agent.stop()
116+
}
117+
}

gradle/publish.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ apply plugin: 'signing'
33

44
/**
55
* Proper publishing requires the following environment variables:
6-
* SONATYPE_USERNAME
7-
* SONATYPE_PASSWORD
6+
* MAVEN_CENTRAL_USERNAME
7+
* MAVEN_CENTRAL_PASSWORD
88
* GPG_PRIVATE_KEY
99
* GPG_PASSWORD
1010
*/
@@ -81,8 +81,8 @@ gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
8181
if (taskGraph.hasTask(publish) || taskGraph.hasTask("publishToSonatype")) {
8282
assert project.findProperty("removeJarVersionNumbers") != true
8383
if (taskGraph.hasTask("publishToSonatype")) {
84-
assert System.getenv("SONATYPE_USERNAME") != null
85-
assert System.getenv("SONATYPE_PASSWORD") != null
84+
assert System.getenv("MAVEN_CENTRAL_USERNAME") != null
85+
assert System.getenv("MAVEN_CENTRAL_PASSWORD") != null
8686
if (isCI) {
8787
assert System.getenv("GPG_PRIVATE_KEY") != null
8888
assert System.getenv("GPG_PASSWORD") != null

gradle/repositories.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
}
1111
}
1212
mavenCentral()
13-
// add sonatype repository for snapshot dependencies
13+
// add maven central repository for snapshot dependencies
1414
maven {
1515
content {
1616
includeGroup "com.datadoghq"

0 commit comments

Comments
 (0)