-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeclarativeConfigPropertiesBridgeTest.java
More file actions
146 lines (129 loc) · 6.64 KB
/
Copy pathDeclarativeConfigPropertiesBridgeTest.java
File metadata and controls
146 lines (129 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.config.bridge;
import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration;
import io.opentelemetry.sdk.extension.incubator.fileconfig.SdkConfigProvider;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.InstrumentationModel;
import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.OpenTelemetryConfigurationModel;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class DeclarativeConfigPropertiesBridgeTest {
private ConfigProperties bridge;
private ConfigProperties emptyBridge;
@BeforeEach
void setup() {
bridge = create(new DeclarativeConfigPropertiesBridgeBuilder());
OpenTelemetryConfigurationModel emptyModel =
new OpenTelemetryConfigurationModel()
.withAdditionalProperty("instrumentation/development", new InstrumentationModel());
SdkConfigProvider emptyConfigProvider = SdkConfigProvider.create(emptyModel);
emptyBridge =
new DeclarativeConfigPropertiesBridgeBuilder()
.buildFromInstrumentationConfig(
Objects.requireNonNull(emptyConfigProvider.getInstrumentationConfig()));
}
private static ConfigProperties create(DeclarativeConfigPropertiesBridgeBuilder builder) {
OpenTelemetryConfigurationModel model =
DeclarativeConfiguration.parse(
DeclarativeConfigPropertiesBridgeTest.class
.getClassLoader()
.getResourceAsStream("config.yaml"));
return builder.buildFromInstrumentationConfig(
SdkConfigProvider.create(model).getInstrumentationConfig());
}
@Test
void getProperties() {
// only properties starting with "otel.instrumentation." are resolved
// asking for properties which don't exist or inaccessible shouldn't result in an error
assertThat(bridge.getString("file_format")).isNull();
assertThat(bridge.getString("file_format", "foo")).isEqualTo("foo");
assertThat(emptyBridge.getBoolean("otel.instrumentation.common.default-enabled")).isNull();
assertThat(emptyBridge.getBoolean("otel.instrumentation.common.default-enabled", true))
.isTrue();
// common cases
assertThat(bridge.getBoolean("otel.instrumentation.runtime-telemetry.enabled")).isFalse();
// check all the types
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("string_key1", "value1");
expectedMap.put("string_key2", "value2");
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.string_key"))
.isEqualTo("value");
assertThat(bridge.getBoolean("otel.instrumentation.example-instrumentation.bool_key")).isTrue();
assertThat(bridge.getInt("otel.instrumentation.example-instrumentation.int_key")).isEqualTo(1);
assertThat(bridge.getLong("otel.instrumentation.example-instrumentation.int_key"))
.isEqualTo(1L);
assertThat(bridge.getDuration("otel.instrumentation.example-instrumentation.duration_key1"))
.isEqualTo(Duration.ofMillis(123));
assertThat(bridge.getDuration("otel.instrumentation.example-instrumentation.duration_key2"))
.isEqualTo(Duration.ofNanos(987));
assertThat(bridge.getDouble("otel.instrumentation.example-instrumentation.double_key"))
.isEqualTo(1.1);
assertThat(bridge.getList("otel.instrumentation.example-instrumentation.list_key"))
.isEqualTo(Arrays.asList("value1", "value2"));
assertThat(bridge.getMap("otel.instrumentation.example-instrumentation.map_key"))
.isEqualTo(expectedMap);
// asking for properties with the wrong type returns null
assertThat(bridge.getBoolean("otel.instrumentation.example-instrumentation.string_key"))
.isNull();
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.bool_key")).isNull();
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.int_key")).isNull();
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.double_key"))
.isNull();
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.list_key")).isNull();
assertThat(bridge.getString("otel.instrumentation.example-instrumentation.map_key")).isNull();
// check all the types
assertThat(bridge.getString("otel.instrumentation.other-instrumentation.string_key", "value"))
.isEqualTo("value");
assertThat(bridge.getBoolean("otel.instrumentation.other-instrumentation.bool_key", true))
.isTrue();
assertThat(bridge.getInt("otel.instrumentation.other-instrumentation.int_key", 1)).isEqualTo(1);
assertThat(bridge.getLong("otel.instrumentation.other-instrumentation.int_key", 1L))
.isEqualTo(1L);
assertThat(
bridge.getDuration(
"otel.instrumentation.other-instrumentation.int_key", Duration.ofMillis(1)))
.isEqualTo(Duration.ofMillis(1));
assertThat(bridge.getDouble("otel.instrumentation.other-instrumentation.double_key", 1.1))
.isEqualTo(1.1);
assertThat(
bridge.getList(
"otel.instrumentation.other-instrumentation.list_key",
Arrays.asList("value1", "value2")))
.isEqualTo(Arrays.asList("value1", "value2"));
assertThat(bridge.getMap("otel.instrumentation.other-instrumentation.map_key", expectedMap))
.isEqualTo(expectedMap);
}
@Test
void vendor() {
// verify vendor specific property names are preserved in unchanged form (prefix is not stripped
// as for otel.instrumentation.*)
assertThat(bridge.getBoolean("acme.full_name.preserved")).isTrue();
}
@Test
void vendorTranslation() {
ConfigProperties propertiesBridge =
create(new DeclarativeConfigPropertiesBridgeBuilder().addMapping("acme", "acme.full_name"));
assertThat(propertiesBridge.getBoolean("acme.preserved")).isTrue();
}
@Test
void agentTranslation() {
ConfigProperties bridge =
create(
new DeclarativeConfigPropertiesBridgeBuilder()
.addMapping("otel.javaagent", "agent")
.addOverride("otel.javaagent.debug", true)
.addOverride("otel.javaagent.logging", "application"));
assertThat(bridge.getBoolean("otel.javaagent.debug")).isTrue();
assertThat(bridge.getBoolean("otel.javaagent.experimental.indy")).isTrue();
assertThat(bridge.getString("otel.javaagent.logging")).isEqualTo("application");
}
}