Skip to content

Commit cfb37db

Browse files
committed
fix: use equal method instead of operator
1 parent 75f6dae commit cfb37db

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/StableConfigParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static boolean matchOperator(String value, String operator, List<String>
109109
if (value == null || operator == null) {
110110
return false;
111111
}
112-
if (operator == "exists") {
112+
if (operator.equals("exists")) {
113113
return true;
114114
}
115115
if (matches == null) {
@@ -146,7 +146,7 @@ static boolean selectorMatch(String origin, List<String> matches, String operato
146146
operator = operator.toLowerCase();
147147
switch (origin.toLowerCase()) {
148148
case "language":
149-
if (operator == "exists") {
149+
if (operator.equals("exists")) {
150150
return false;
151151
}
152152
return matchOperator("java", operator, matches);

internal-api/src/test/groovy/datadog/trace/bootstrap/config/provider/StableConfigParserTest.groovy

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,40 @@ apm_configuration_rules:
6262
Files.delete(filePath)
6363
}
6464

65+
def "test parse and template"() {
66+
when:
67+
Path filePath = Files.createTempFile("testFile_", ".yaml")
68+
then:
69+
if (filePath == null) {
70+
throw new AssertionError("Failed to create: " + filePath)
71+
}
72+
73+
when:
74+
String yaml = """
75+
apm_configuration_rules:
76+
- selectors:
77+
- origin: process_arguments
78+
key: "-Dtest_parse_and_template"
79+
operator: exists
80+
configuration:
81+
DD_SERVICE: {{process_arguments['-Dtest_parse_and_template']}}
82+
"""
83+
System.setProperty("test_parse_and_template", "myservice")
84+
Files.write(filePath, yaml.getBytes())
85+
StableConfigSource.StableConfig cfg = StableConfigParser.parse(filePath.toString())
86+
87+
then:
88+
cfg.get("DD_SERVICE") == "myservice"
89+
}
90+
6591
def "test selectorMatch"() {
6692
when:
6793
// Env vars
6894
injectEnvConfig("DD_PROFILING_ENABLED", "true")
6995
injectEnvConfig("DD_SERVICE", "mysvc")
7096
injectEnvConfig("DD_TAGS", "team:apm,component:web")
71-
System.setProperty("arg1", "value1")
72-
97+
System.setProperty("test_selectorMatch", "value1")
98+
7399
def match = StableConfigParser.selectorMatch(origin, matches, operator, key)
74100

75101
then:
@@ -102,10 +128,10 @@ apm_configuration_rules:
102128
"environment_variables" | [] | "equals" | null | false
103129
"environment_variables" | null | "equals" | "DD_SERVICE" | false
104130
"language" | ["java"] | null | "" | false
105-
"process_arguments" | null | "exists" | "-Darg1" | true
131+
"process_arguments" | null | "exists" | "-Dtest_selectorMatch" | true
106132
"process_arguments" | null | "exists" | "-Darg2" | false
107-
"process_arguments" | ["value1"] | "equals" | "-Darg1" | true
108-
"process_arguments" | ["value2"] | "equals" | "-Darg1" | false
133+
"process_arguments" | ["value1"] | "equals" | "-Dtest_selectorMatch" | true
134+
"process_arguments" | ["value2"] | "equals" | "-Dtest_selectorMatch" | false
109135
}
110136

111137
def "test duplicate entries not allowed"() {

0 commit comments

Comments
 (0)