Skip to content

Commit

Permalink
Polish #1588
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Sep 29, 2019
1 parent 56f275b commit 26f2b8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,28 @@ default String prefix() {
return "newrelic";
}

/**
* When this is {@code false}, the New Relic eventType value will be set to {@link #eventType()}. Otherwise, the meter name will be used.
* Defaults to {@code false}.
* @return whether to use meter names as the New Relic eventType value
*/
default boolean meterNameEventTypeEnabled() {
String v = get(prefix() + ".meterNameEventTypeEnabled");
return (v == null) ? false : new Boolean(v);
return Boolean.parseBoolean(v);
}


/**
* This configuration property will only be used if {@link #meterNameEventTypeEnabled()} is {@code false}.
* Default value is {@code MicrometerSample}.
* @return static eventType value to send to New Relic for all metrics.
*/
default String eventType() {
String v = get(prefix() + ".eventType");
if (v == null)
v = "MicrometerSample";
return "MicrometerSample";
return v;
}

default String apiKey() {
String v = get(prefix() + ".apiKey");
if (v == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ Stream<String> writeMeter(Meter meter) {
}

private String event(Meter.Id id, Attribute... attributes) {
if (config.meterNameEventTypeEnabled() == false) {
//Include contextual attributes when publishing all metrics under a single categorical eventType,
if (!config.meterNameEventTypeEnabled()) {
// Include contextual attributes when publishing all metrics under a single categorical eventType,
// NOT when publishing an eventType per Meter/metric name
int size = attributes.length;
Attribute[] newAttrs = Arrays.copyOf(attributes, size + 2);

String name = id.getConventionName(config().namingConvention());
newAttrs[size] = new Attribute("metricName", name);
newAttrs[size + 1] = new Attribute("metricType", id.getType().toString());

return event(id, Tags.empty(), newAttrs);
}
return event(id, Tags.empty(), attributes);
Expand All @@ -253,7 +253,7 @@ private String event(Meter.Id id, Iterable<Tag> extraTags, Attribute... attribut
.append("\":\"").append(escapeJson(convention.tagValue(tag.getValue()))).append("\"");
}

String eventType = getEventType(id, config, convention);
String eventType = getEventType(id);

return Arrays.stream(attributes)
.map(attr ->
Expand All @@ -264,16 +264,12 @@ private String event(Meter.Id id, Iterable<Tag> extraTags, Attribute... attribut
.collect(Collectors.joining("", "{\"eventType\":\"" + escapeJson(eventType) + "\"", tagsJson + "}"));
}

String getEventType(Meter.Id id, NewRelicConfig config, NamingConvention convention) {
String eventType = null;
private String getEventType(Meter.Id id) {
if (config.meterNameEventTypeEnabled()) {
//meter/metric name event type
eventType = id.getConventionName(convention);
return id.getConventionName(config().namingConvention());
} else {
//static eventType "category"
eventType = config.eventType();
return config.eventType();
}
return eventType;
}

private void sendEvents(String insightsEndpoint, Stream<String> events) {
Expand Down

0 comments on commit 26f2b8e

Please sign in to comment.