-
Notifications
You must be signed in to change notification settings - Fork 362
Remove containerTagsHash/processTags from DSM primary pathway hash #12573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
19b4dff
e11b5ba
d123fca
1ac2f08
e973691
47634e9
8527d0d
2c92565
d43081e
ed4f05a
b3548ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| package datadog.trace.api.datastreams | ||
|
|
||
| import datadog.trace.api.BaseHash | ||
| import datadog.trace.api.Config | ||
| import datadog.trace.api.ProcessTags | ||
| import spock.lang.Specification | ||
| import java.nio.ByteBuffer | ||
|
|
||
|
|
||
| class DataStreamsTagsTest extends Specification { | ||
| def cleanup() { | ||
| BaseHash.recalcBaseHash(null) | ||
| ProcessTags.reset(Config.get()) | ||
| } | ||
|
|
||
| def getTags(int idx) { | ||
| return new DataStreamsTags("bus" + idx, DataStreamsTags.Direction.OUTBOUND, "exchange" + idx, "topic" + idx, "type" + idx, "subscription" + idx, | ||
| "dataset_name" + idx, "dataset_namespace" + idx, true, "group" + idx, "consumer_group" + idx, true, | ||
|
|
@@ -80,7 +87,7 @@ class DataStreamsTagsTest extends Specification { | |
| DataStreamsTags.setServiceNameOverride(serviceName) | ||
| def two = getTags(0) | ||
|
|
||
| BaseHash.updateBaseHash(12) | ||
| BaseHash.updateIdentityHash(12) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same root cause as in
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch, will fix before merge. |
||
| def three = getTags(0) | ||
|
|
||
| expect: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package datadog.trace.api; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
|
||
| import datadog.trace.test.junit.utils.config.WithConfigExtension; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| @ExtendWith(WithConfigExtension.class) | ||
| class BaseHashIdentityTest { | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| ProcessTags.reset(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void cleanup() { | ||
| ProcessTags.reset(); | ||
| } | ||
|
|
||
| @Test | ||
| void identityHashDependsOnServiceEnvAndPrimaryTag() { | ||
| // identityHash is calculated once (service/env/primaryTag are fixed for the JVM's | ||
| // lifetime), so this exercises the underlying hashing function directly rather than | ||
| // via Config + recalcBaseHash. | ||
| long base = BaseHash.calcIdentity("service", "env", "region-1"); | ||
|
|
||
| assertNotEquals(base, BaseHash.calcIdentity("service-2", "env", "region-1")); | ||
| assertNotEquals(base, BaseHash.calcIdentity("service", "env-2", "region-1")); | ||
| assertNotEquals(base, BaseHash.calcIdentity("service", "env", "region-2")); | ||
| assertEquals(base, BaseHash.calcIdentity("service", "env", "region-1")); | ||
| } | ||
|
|
||
| @Test | ||
| void identityHashIsUnaffectedByContainerTagsHashOrProcessTags() { | ||
| BaseHash.recalcBaseHash(null); | ||
| long baseIdentityHash = BaseHash.getIdentityHash(); | ||
|
|
||
| BaseHash.recalcBaseHash("some-container-tags-hash"); | ||
| long withContainerTagsHash = BaseHash.getIdentityHash(); | ||
|
|
||
| ProcessTags.addTag("foo", "bar"); | ||
| long withProcessTags = BaseHash.getIdentityHash(); | ||
|
|
||
| // DSM2-335: identity hash must not be perturbed by per-pod/per-rollout inputs | ||
| assertEquals(baseIdentityHash, withContainerTagsHash); | ||
| assertEquals(baseIdentityHash, withProcessTags); | ||
| } | ||
|
|
||
| @Test | ||
| void getIdentityHashRecalculatesFromConfigWhenUnset() { | ||
| // 0 means "not yet computed" - simulate that state, e.g. before this class is ever touched | ||
| BaseHash.updateIdentityHash(0L); | ||
|
|
||
| long recalculated = BaseHash.getIdentityHash(); | ||
| assertNotEquals(0L, recalculated); | ||
|
|
||
| // once non-zero, later reads don't recalculate - a caller that needs a fresh value can | ||
| // still force one directly (e.g. tests via updateIdentityHash) | ||
| BaseHash.updateIdentityHash(42L); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, great catch, will fix before merge. |
||
| assertEquals(42L, BaseHash.getIdentityHash()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package datadog.trace.api.datastreams; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import datadog.trace.api.BaseHash; | ||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.ProcessTags; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class DataStreamsTagsContainerProcessTagsTest { | ||
|
|
||
| @AfterEach | ||
| void cleanup() { | ||
| BaseHash.recalcBaseHash(null); | ||
| ProcessTags.reset(Config.get()); | ||
| } | ||
|
|
||
| private static DataStreamsTags getTags(int idx) { | ||
| return new DataStreamsTags( | ||
| "bus" + idx, | ||
| DataStreamsTags.Direction.OUTBOUND, | ||
| "exchange" + idx, | ||
| "topic" + idx, | ||
| "type" + idx, | ||
| "subscription" + idx, | ||
| "dataset_name" + idx, | ||
| "dataset_namespace" + idx, | ||
| true, | ||
| "group" + idx, | ||
| "consumer_group" + idx, | ||
| true, | ||
| "kafka_cluster_id" + idx, | ||
| "partition" + idx); | ||
| } | ||
|
|
||
| @Test | ||
| void containerTagsHashDoesNotAffectAnyHashTier() { | ||
| // simulate the Agent reporting the pod/container's tags hash at startup | ||
| BaseHash.recalcBaseHash("container-tags-hash-1"); | ||
| DataStreamsTags base = getTags(0); | ||
|
|
||
| // a rolling deploy changes the container-tags hash the Agent reports | ||
| BaseHash.recalcBaseHash("container-tags-hash-2"); | ||
| DataStreamsTags afterRollingDeploy = getTags(0); | ||
|
|
||
| // DSM2-335: no hash tier is affected - container-tags hash is dropped entirely from DSM | ||
| assertEquals(base.getHash(), afterRollingDeploy.getHash()); | ||
| assertEquals(base.getAggregationHash(), afterRollingDeploy.getAggregationHash()); | ||
| assertEquals(base, afterRollingDeploy); | ||
| } | ||
|
|
||
| @Test | ||
| void processTagsDoNotAffectAnyHashTier() { | ||
| BaseHash.recalcBaseHash(null); | ||
| DataStreamsTags base = getTags(0); | ||
|
|
||
| // a process tag is added (e.g. cluster.name discovered after startup) | ||
| ProcessTags.addTag("cluster.name", "new-cluster"); | ||
| DataStreamsTags withProcessTag = getTags(0); | ||
|
|
||
| // DSM2-335: no hash tier is affected - process tags are dropped entirely from DSM | ||
| assertEquals(base.getHash(), withProcessTag.getHash()); | ||
| assertEquals(base.getAggregationHash(), withProcessTag.getAggregationHash()); | ||
| assertEquals(base, withProcessTag); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.