Skip to content

Commit b92a5e3

Browse files
committed
Adding agent description attributes setters
1 parent 65ebb98 commit b92a5e3

File tree

1 file changed

+289
-4
lines changed

1 file changed

+289
-4
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/OpampClientBuilder.java

Lines changed: 289 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import opamp.proto.AgentCapabilities;
1919
import opamp.proto.AgentDescription;
2020
import opamp.proto.AnyValue;
21+
import opamp.proto.ArrayValue;
2122
import opamp.proto.KeyValue;
2223
import opamp.proto.RemoteConfigStatus;
2324

@@ -66,7 +67,7 @@ public OpampClientBuilder setInstanceUid(byte[] value) {
6667
}
6768

6869
/**
69-
* Sets a string attribute into the <a
70+
* Puts a string attribute into the <a
7071
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
7172
* field.
7273
*
@@ -75,13 +76,130 @@ public OpampClientBuilder setInstanceUid(byte[] value) {
7576
* @return this
7677
*/
7778
@CanIgnoreReturnValue
78-
public OpampClientBuilder setIdentifyingAttribute(String key, String value) {
79+
public OpampClientBuilder putIdentifyingAttribute(String key, String value) {
7980
identifyingAttributes.put(key, createStringValue(value));
8081
return this;
8182
}
8283

8384
/**
84-
* Sets an attribute into the <a
85+
* Puts a boolean attribute into the <a
86+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
87+
* field.
88+
*
89+
* @param key The attribute key.
90+
* @param value The attribute value.
91+
* @return this
92+
*/
93+
@CanIgnoreReturnValue
94+
public OpampClientBuilder putIdentifyingAttribute(String key, boolean value) {
95+
identifyingAttributes.put(key, createBooleanValue(value));
96+
return this;
97+
}
98+
99+
/**
100+
* Puts a long (proto int64) attribute into the <a
101+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
102+
* field.
103+
*
104+
* @param key The attribute key.
105+
* @param value The attribute value.
106+
* @return this
107+
*/
108+
@CanIgnoreReturnValue
109+
public OpampClientBuilder putIdentifyingAttribute(String key, long value) {
110+
identifyingAttributes.put(key, createLongValue(value));
111+
return this;
112+
}
113+
114+
/**
115+
* Puts a double attribute into the <a
116+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
117+
* field.
118+
*
119+
* @param key The attribute key.
120+
* @param value The attribute value.
121+
* @return this
122+
*/
123+
@CanIgnoreReturnValue
124+
public OpampClientBuilder putIdentifyingAttribute(String key, double value) {
125+
identifyingAttributes.put(key, createDoubleValue(value));
126+
return this;
127+
}
128+
129+
/**
130+
* Puts a string array attribute into the <a
131+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
132+
* field.
133+
*
134+
* @param key The attribute key.
135+
* @param values The attribute values.
136+
* @return this
137+
*/
138+
@CanIgnoreReturnValue
139+
public OpampClientBuilder putIdentifyingAttribute(String key, String... values) {
140+
if (values == null) {
141+
return this;
142+
}
143+
identifyingAttributes.put(key, createArrayValue(createStringValueList(values)));
144+
return this;
145+
}
146+
147+
/**
148+
* Puts a boolean array attribute into the <a
149+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
150+
* field.
151+
*
152+
* @param key The attribute key.
153+
* @param values The attribute values.
154+
* @return this
155+
*/
156+
@CanIgnoreReturnValue
157+
public OpampClientBuilder putIdentifyingAttribute(String key, boolean... values) {
158+
if (values == null) {
159+
return this;
160+
}
161+
identifyingAttributes.put(key, createArrayValue(createBooleanValueList(values)));
162+
return this;
163+
}
164+
165+
/**
166+
* Puts a long (proto int64) array attribute into the <a
167+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
168+
* field.
169+
*
170+
* @param key The attribute key.
171+
* @param values The attribute values.
172+
* @return this
173+
*/
174+
@CanIgnoreReturnValue
175+
public OpampClientBuilder putIdentifyingAttribute(String key, long... values) {
176+
if (values == null) {
177+
return this;
178+
}
179+
identifyingAttributes.put(key, createArrayValue(createLongValueList(values)));
180+
return this;
181+
}
182+
183+
/**
184+
* Puts a double array attribute into the <a
185+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionidentifying_attributes">identifying_attributes</a>
186+
* field.
187+
*
188+
* @param key The attribute key.
189+
* @param values The attribute values.
190+
* @return this
191+
*/
192+
@CanIgnoreReturnValue
193+
public OpampClientBuilder putIdentifyingAttribute(String key, double... values) {
194+
if (values == null) {
195+
return this;
196+
}
197+
identifyingAttributes.put(key, createArrayValue(createDoubleValueList(values)));
198+
return this;
199+
}
200+
201+
/**
202+
* Puts a string attribute into the <a
85203
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
86204
* field.
87205
*
@@ -90,11 +208,128 @@ public OpampClientBuilder setIdentifyingAttribute(String key, String value) {
90208
* @return this
91209
*/
92210
@CanIgnoreReturnValue
93-
public OpampClientBuilder setNonIdentifyingAttribute(String key, String value) {
211+
public OpampClientBuilder putNonIdentifyingAttribute(String key, String value) {
94212
nonIdentifyingAttributes.put(key, createStringValue(value));
95213
return this;
96214
}
97215

216+
/**
217+
* Puts a boolean attribute into the <a
218+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
219+
* field.
220+
*
221+
* @param key The attribute key
222+
* @param value The attribute value.
223+
* @return this
224+
*/
225+
@CanIgnoreReturnValue
226+
public OpampClientBuilder putNonIdentifyingAttribute(String key, boolean value) {
227+
nonIdentifyingAttributes.put(key, createBooleanValue(value));
228+
return this;
229+
}
230+
231+
/**
232+
* Puts a long (proto int64) attribute into the <a
233+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
234+
* field.
235+
*
236+
* @param key The attribute key
237+
* @param value The attribute value.
238+
* @return this
239+
*/
240+
@CanIgnoreReturnValue
241+
public OpampClientBuilder putNonIdentifyingAttribute(String key, long value) {
242+
nonIdentifyingAttributes.put(key, createLongValue(value));
243+
return this;
244+
}
245+
246+
/**
247+
* Puts a double attribute into the <a
248+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
249+
* field.
250+
*
251+
* @param key The attribute key
252+
* @param value The attribute value.
253+
* @return this
254+
*/
255+
@CanIgnoreReturnValue
256+
public OpampClientBuilder putNonIdentifyingAttribute(String key, double value) {
257+
nonIdentifyingAttributes.put(key, createDoubleValue(value));
258+
return this;
259+
}
260+
261+
/**
262+
* Puts a string array attribute into the <a
263+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
264+
* field.
265+
*
266+
* @param key The attribute key
267+
* @param values The attribute values.
268+
* @return this
269+
*/
270+
@CanIgnoreReturnValue
271+
public OpampClientBuilder putNonIdentifyingAttribute(String key, String... values) {
272+
if (values == null) {
273+
return this;
274+
}
275+
nonIdentifyingAttributes.put(key, createArrayValue(createStringValueList(values)));
276+
return this;
277+
}
278+
279+
/**
280+
* Puts a boolean array attribute into the <a
281+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
282+
* field.
283+
*
284+
* @param key The attribute key
285+
* @param values The attribute values.
286+
* @return this
287+
*/
288+
@CanIgnoreReturnValue
289+
public OpampClientBuilder putNonIdentifyingAttribute(String key, boolean... values) {
290+
if (values == null) {
291+
return this;
292+
}
293+
nonIdentifyingAttributes.put(key, createArrayValue(createBooleanValueList(values)));
294+
return this;
295+
}
296+
297+
/**
298+
* Puts a long (proto int64) array attribute into the <a
299+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
300+
* field.
301+
*
302+
* @param key The attribute key
303+
* @param values The attribute values.
304+
* @return this
305+
*/
306+
@CanIgnoreReturnValue
307+
public OpampClientBuilder putNonIdentifyingAttribute(String key, long... values) {
308+
if (values == null) {
309+
return this;
310+
}
311+
nonIdentifyingAttributes.put(key, createArrayValue(createLongValueList(values)));
312+
return this;
313+
}
314+
315+
/**
316+
* Puts a double array attribute into the <a
317+
* href="https://github.com/open-telemetry/opamp-spec/blob/main/specification.md#agentdescriptionnon_identifying_attributes">non_identifying_attributes</a>
318+
* field.
319+
*
320+
* @param key The attribute key
321+
* @param values The attribute values.
322+
* @return this
323+
*/
324+
@CanIgnoreReturnValue
325+
public OpampClientBuilder putNonIdentifyingAttribute(String key, double... values) {
326+
if (values == null) {
327+
return this;
328+
}
329+
nonIdentifyingAttributes.put(key, createArrayValue(createDoubleValueList(values)));
330+
return this;
331+
}
332+
98333
/**
99334
* Adds the AcceptsRemoteConfig and ReportsRemoteConfig capabilities to the Client so that the
100335
* Server can offer remote config values as explained <a
@@ -186,6 +421,56 @@ private static AnyValue createStringValue(String value) {
186421
return new AnyValue.Builder().string_value(value).build();
187422
}
188423

424+
private static AnyValue createBooleanValue(boolean value) {
425+
return new AnyValue.Builder().bool_value(value).build();
426+
}
427+
428+
private static AnyValue createLongValue(long value) {
429+
return new AnyValue.Builder().int_value(value).build();
430+
}
431+
432+
private static AnyValue createDoubleValue(double value) {
433+
return new AnyValue.Builder().double_value(value).build();
434+
}
435+
436+
private static List<AnyValue> createStringValueList(String[] values) {
437+
List<AnyValue> anyValues = new ArrayList<>();
438+
for (String value : values) {
439+
anyValues.add(createStringValue(value));
440+
}
441+
return anyValues;
442+
}
443+
444+
private static List<AnyValue> createBooleanValueList(boolean[] values) {
445+
List<AnyValue> anyValues = new ArrayList<>();
446+
for (boolean value : values) {
447+
anyValues.add(createBooleanValue(value));
448+
}
449+
return anyValues;
450+
}
451+
452+
private static List<AnyValue> createLongValueList(long[] values) {
453+
List<AnyValue> anyValues = new ArrayList<>();
454+
for (long value : values) {
455+
anyValues.add(createLongValue(value));
456+
}
457+
return anyValues;
458+
}
459+
460+
private static List<AnyValue> createDoubleValueList(double[] values) {
461+
List<AnyValue> anyValues = new ArrayList<>();
462+
for (double value : values) {
463+
anyValues.add(createDoubleValue(value));
464+
}
465+
return anyValues;
466+
}
467+
468+
private static AnyValue createArrayValue(List<AnyValue> values) {
469+
return new AnyValue.Builder()
470+
.array_value(new ArrayValue.Builder().values(values).build())
471+
.build();
472+
}
473+
189474
private static KeyValue createKeyValue(String key, AnyValue value) {
190475
return new KeyValue.Builder().key(key).value(value).build();
191476
}

0 commit comments

Comments
 (0)