Skip to content

Commit

Permalink
Add vault parameter to exporter (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
attilakreiner authored Apr 19, 2024
1 parent 6021d29 commit 5440606
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class ExporterConfig
public final String name;
public final String qname;
public final String type;
public final String vault;
public final OptionsConfig options;

public transient long id;
public transient long vaultId;

public static ExporterConfigBuilder<ExporterConfig> builder()
{
Expand All @@ -37,12 +39,14 @@ public static ExporterConfigBuilder<ExporterConfig> builder()
String namespace,
String name,
String type,
String vault,
OptionsConfig options)
{
this.namespace = requireNonNull(namespace);
this.name = requireNonNull(name);
this.qname = String.format("%s:%s", namespace, name);
this.type = requireNonNull(type);
this.vault = vault;
this.options = options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class ExporterConfigBuilder<T> extends ConfigBuilder<T, ExporterCon
private String namespace;
private String name;
private String type;
private String vault;
private OptionsConfig options;

ExporterConfigBuilder(
Expand Down Expand Up @@ -53,6 +54,13 @@ public ExporterConfigBuilder<T> name(
return this;
}

public ExporterConfigBuilder<T> vault(
String vault)
{
this.vault = vault;
return this;
}

public ExporterConfigBuilder<T> type(
String type)
{
Expand All @@ -76,6 +84,6 @@ public ExporterConfigBuilder<T> options(
@Override
public T build()
{
return mapper.apply(new ExporterConfig(namespace, name, type, options));
return mapper.apply(new ExporterConfig(namespace, name, type, vault, options));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class ExporterAdapter implements JsonbAdapter<ExporterConfig[], JsonObject>
{
private static final String TYPE_NAME = "type";
private static final String VAULT_NAME = "vault";
private static final String OPTIONS_NAME = "options";

private final OptionsConfigAdapter options;
Expand Down Expand Up @@ -60,6 +61,10 @@ public JsonObject adaptToJson(

JsonObjectBuilder item = Json.createObjectBuilder();
item.add(TYPE_NAME, exporter.type);
if (exporter.vault != null)
{
item.add(VAULT_NAME, exporter.vault);
}
if (exporter.options != null)
{
item.add(OPTIONS_NAME, options.adaptToJson(exporter.options));
Expand All @@ -82,11 +87,17 @@ public ExporterConfig[] adaptFromJson(

String type = item.getString(TYPE_NAME);
options.adaptType(type);
String vault = null;
if (item.containsKey(VAULT_NAME))
{
vault = item.getString(VAULT_NAME);
}

exporters.add(ExporterConfig.builder()
.namespace(namespace)
.name(name)
.type(type)
.vault(vault)
.options(options.adaptFromJson(item.getJsonObject(OPTIONS_NAME)))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ private void process(
for (ExporterConfig exporter : namespace.telemetry.exporters)
{
exporter.id = resolver.resolve(exporter.name);
if (exporter.vault != null)
{
exporter.vaultId = resolver.resolve(exporter.vault);
}
}

for (BindingConfig binding : namespace.bindings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void shouldReadTelemetryWithExporterOptions()
"\"test0\": " +
"{" +
"\"type\": \"test\"," +
"\"vault\": \"vault0\"," +
"\"options\": {" +
"\"mode\": \"test42\"" +
"}" +
Expand All @@ -173,6 +174,7 @@ public void shouldReadTelemetryWithExporterOptions()
assertThat(telemetry.metrics.get(1).name, equalTo("test.histogram"));
assertThat(telemetry.exporters.get(0).name, equalTo("test0"));
assertThat(telemetry.exporters.get(0).type, equalTo("test"));
assertThat(telemetry.exporters.get(0).vault, equalTo("vault0"));
assertThat(telemetry.exporters.get(0).options, instanceOf(TestExporterOptionsConfig.class));
assertThat(((TestExporterOptionsConfig)telemetry.exporters.get(0).options).mode, equalTo("test42"));
}
Expand All @@ -198,6 +200,7 @@ public void shouldWriteTelemetryWithExporterOptions()
.namespace("test")
.name("test0")
.type("test")
.vault("vault0")
.options(TestExporterOptionsConfig::builder)
.inject(identity())
.mode("test42")
Expand All @@ -213,6 +216,6 @@ public void shouldWriteTelemetryWithExporterOptions()
assertThat(text, equalTo(
"{\"attributes\":{\"test.attribute\":\"example\"}," +
"\"metrics\":[\"test.counter\"]," +
"\"exporters\":{\"test0\":{\"type\":\"test\",\"options\":{\"mode\":\"test42\"}}}}"));
"\"exporters\":{\"test0\":{\"type\":\"test\",\"vault\":\"vault0\",\"options\":{\"mode\":\"test42\"}}}}"));
}
}

0 comments on commit 5440606

Please sign in to comment.