use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.
the class EvictingMetricsRegistry method put.
@SuppressWarnings("unchecked")
private <M extends Metric> M put(MetricName metricName, MetricMatcher metricMatcher, Function<MetricName, M> getter) {
@Nullable Metric cached = metricCache.getIfPresent(metricName);
Objects.requireNonNull(metricNamesForMetricMatchers.get(metricMatcher)).add(metricName);
if (cached != null && cached == metricsRegistry.allMetrics().get(metricName)) {
return (M) cached;
}
return (M) metricCache.asMap().compute(metricName, (name, existing) -> {
@Nullable Metric expected = metricsRegistry.allMetrics().get(name);
return expected == null ? getter.apply(name) : expected;
});
}
use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.
the class LogsIngester method ingestLog.
public void ingestLog(LogsMessage logsMessage) {
LogsIngestionConfig logsIngestionConfig = logsIngestionConfigManager.getConfig();
boolean success = false;
for (MetricMatcher metricMatcher : logsIngestionConfig.counters) {
success |= maybeIngestLog(evictingMetricsRegistry::getCounter, metricMatcher, logsMessage);
}
for (MetricMatcher metricMatcher : logsIngestionConfig.gauges) {
success |= maybeIngestLog(evictingMetricsRegistry::getGauge, metricMatcher, logsMessage);
}
for (MetricMatcher metricMatcher : logsIngestionConfig.histograms) {
success |= maybeIngestLog(evictingMetricsRegistry::getHistogram, metricMatcher, logsMessage);
}
if (success) {
parsed.inc();
} else {
unparsed.inc();
}
}
use of com.wavefront.agent.config.MetricMatcher in project java by wavefrontHQ.
the class LogsIngesterTest method testHotloadedConfigClearsOldMetrics.
@Test
public void testHotloadedConfigClearsOldMetrics() throws Exception {
setup(parseConfigFile("test.yml"));
assertThat(getPoints(1, "plainCounter"), contains(PointMatchers.matches(1L, MetricConstants.DELTA_PREFIX + "plainCounter", ImmutableMap.of())));
// once the counter is reported, it is reset because now it is treated as delta counter.
// hence we check that plainCounter has value 1L below.
assertThat(getPoints(2, "plainCounter", "counterWithValue 42"), containsInAnyOrder(ImmutableList.of(PointMatchers.matches(42L, MetricConstants.DELTA_PREFIX + "counterWithValue", ImmutableMap.of()), PointMatchers.matches(1L, MetricConstants.DELTA_PREFIX + "plainCounter", ImmutableMap.of()))));
List<MetricMatcher> counters = Lists.newCopyOnWriteArrayList(logsIngestionConfig.counters);
int oldSize = counters.size();
counters.removeIf((metricMatcher -> metricMatcher.getPattern().equals("plainCounter")));
assertThat(counters, hasSize(oldSize - 1));
// Get a new config file because the SUT has a reference to the old one, and we'll be monkey patching
// this one.
logsIngestionConfig = parseConfigFile("test.yml");
logsIngestionConfig.verifyAndInit();
logsIngestionConfig.counters = counters;
logsIngesterUnderTest.logsIngestionConfigManager.forceConfigReload();
// once the counter is reported, it is reset because now it is treated as delta counter.
// since zero values are filtered out, no new values are expected.
assertThat(getPoints(0, "plainCounter"), emptyIterable());
}
Aggregations