Skip to content

Commit 75f6dae

Browse files
committed
feat: add tests for equal operator on arguments
1 parent ebf333b commit 75f6dae

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static boolean doesRuleMatch(Rule rule) {
104104
}
105105

106106
private static boolean matchOperator(String value, String operator, List<String> matches) {
107-
// not sure if these are nullable, but the semantics make sense
107+
// not sure if these are nullable, but the semantics makes sense
108108
// and that will save us from a NPE
109109
if (value == null || operator == null) {
110110
return false;
@@ -140,6 +140,9 @@ private static boolean matchOperator(String value, String operator, List<String>
140140
// We do all of the case insensitivity modifications in this function, because each selector will
141141
// be viewed just once
142142
static boolean selectorMatch(String origin, List<String> matches, String operator, String key) {
143+
if (operator == null) {
144+
return false;
145+
}
143146
operator = operator.toLowerCase();
144147
switch (origin.toLowerCase()) {
145148
case "language":
@@ -152,9 +155,6 @@ static boolean selectorMatch(String origin, List<String> matches, String operato
152155
return false;
153156
}
154157
String envValue = System.getenv(key.toUpperCase());
155-
if (envValue == null) {
156-
return false;
157-
}
158158
return matchOperator(envValue, operator, matches);
159159
case "process_arguments":
160160
if (key == null) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ apm_configuration_rules:
6868
injectEnvConfig("DD_PROFILING_ENABLED", "true")
6969
injectEnvConfig("DD_SERVICE", "mysvc")
7070
injectEnvConfig("DD_TAGS", "team:apm,component:web")
71+
System.setProperty("arg1", "value1")
72+
7173
def match = StableConfigParser.selectorMatch(origin, matches, operator, key)
7274

7375
then:
@@ -83,6 +85,7 @@ apm_configuration_rules:
8385
"language" | ["java"] | "exists" | "" | false
8486
"language" | ["java"] | "something unexpected" | "" | false
8587
"environment_variables" | [] | "exists" | "DD_TAGS" | true
88+
"environment_variables" | null | "exists" | "DD_TAGS" | true
8689
"environment_variables" | ["team:apm"] | "contains" | "DD_TAGS" | true
8790
"ENVIRONMENT_VARIABLES" | ["TeAm:ApM"] | "CoNtAiNs" | "Dd_TaGs" | true // check case insensitivity
8891
"environment_variables" | ["team:apm"] | "equals" | "DD_TAGS" | false
@@ -96,6 +99,13 @@ apm_configuration_rules:
9699
"environment_variables" | ["svc"] | "contains" | "DD_SERVICE" | true
97100
"environment_variables" | ["other"] | "contains" | "DD_SERVICE" | false
98101
"environment_variables" | [null] | "contains" | "DD_SERVICE" | false
102+
"environment_variables" | [] | "equals" | null | false
103+
"environment_variables" | null | "equals" | "DD_SERVICE" | false
104+
"language" | ["java"] | null | "" | false
105+
"process_arguments" | null | "exists" | "-Darg1" | true
106+
"process_arguments" | null | "exists" | "-Darg2" | false
107+
"process_arguments" | ["value1"] | "equals" | "-Darg1" | true
108+
"process_arguments" | ["value2"] | "equals" | "-Darg1" | false
99109
}
100110

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

0 commit comments

Comments
 (0)