@Test public void test_WHEN_NoMatches_THEN_ShouldReturnDefaultSample() { final List<MapperConfig> mapperConfigs = Arrays.asList( new MapperConfig("client-nope.*.*.*"), new MapperConfig("*.client-nope.*.*.*"), new MapperConfig("not.even.this.*.*.*") ); final CustomMappingSampleBuilder converter = new CustomMappingSampleBuilder(mapperConfigs); final Collector.MetricFamilySamples.Sample result = converter.createSample( "app.okhttpclient.client.HttpClient.service.total", "", Collections.singletonList("quantile"), Collections.singletonList("0.99"), 0d); assertEquals(new Collector.MetricFamilySamples.Sample("app_okhttpclient_client_HttpClient_service_total", Collections.singletonList("quantile"), Collections.singletonList("0.99"), 0d), result); }
@Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { if (dropwizardName == null) { throw new IllegalArgumentException("Dropwizard metric name cannot be null"); } CompiledMapperConfig matchingConfig = null; for (CompiledMapperConfig config : this.compiledMapperConfigs) { if (config.pattern.matches(dropwizardName)) { matchingConfig = config; break; } } if (matchingConfig != null) { final Map<String, String> params = matchingConfig.pattern.extractParameters(dropwizardName); final NameAndLabels nameAndLabels = getNameAndLabels(matchingConfig.mapperConfig, params); nameAndLabels.labelNames.addAll(additionalLabelNames); nameAndLabels.labelValues.addAll(additionalLabelValues); return defaultMetricSampleBuilder.createSample( nameAndLabels.name, nameSuffix, nameAndLabels.labelNames, nameAndLabels.labelValues, value ); } return defaultMetricSampleBuilder.createSample( dropwizardName, nameSuffix, additionalLabelNames, additionalLabelValues, value ); }
CustomMappingSampleBuilder implements SampleBuilder { @Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { if (dropwizardName == null) { throw new IllegalArgumentException("Dropwizard metric name cannot be null"); } CompiledMapperConfig matchingConfig = null; for (CompiledMapperConfig config : this.compiledMapperConfigs) { if (config.pattern.matches(dropwizardName)) { matchingConfig = config; break; } } if (matchingConfig != null) { final Map<String, String> params = matchingConfig.pattern.extractParameters(dropwizardName); final NameAndLabels nameAndLabels = getNameAndLabels(matchingConfig.mapperConfig, params); nameAndLabels.labelNames.addAll(additionalLabelNames); nameAndLabels.labelValues.addAll(additionalLabelValues); return defaultMetricSampleBuilder.createSample( nameAndLabels.name, nameSuffix, nameAndLabels.labelNames, nameAndLabels.labelValues, value ); } return defaultMetricSampleBuilder.createSample( dropwizardName, nameSuffix, additionalLabelNames, additionalLabelValues, value ); } }
CustomMappingSampleBuilder implements SampleBuilder { @Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { if (dropwizardName == null) { throw new IllegalArgumentException("Dropwizard metric name cannot be null"); } CompiledMapperConfig matchingConfig = null; for (CompiledMapperConfig config : this.compiledMapperConfigs) { if (config.pattern.matches(dropwizardName)) { matchingConfig = config; break; } } if (matchingConfig != null) { final Map<String, String> params = matchingConfig.pattern.extractParameters(dropwizardName); final NameAndLabels nameAndLabels = getNameAndLabels(matchingConfig.mapperConfig, params); nameAndLabels.labelNames.addAll(additionalLabelNames); nameAndLabels.labelValues.addAll(additionalLabelValues); return defaultMetricSampleBuilder.createSample( nameAndLabels.name, nameSuffix, nameAndLabels.labelNames, nameAndLabels.labelValues, value ); } return defaultMetricSampleBuilder.createSample( dropwizardName, nameSuffix, additionalLabelNames, additionalLabelValues, value ); } CustomMappingSampleBuilder(final List<MapperConfig> mapperConfigs); }
CustomMappingSampleBuilder implements SampleBuilder { @Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { if (dropwizardName == null) { throw new IllegalArgumentException("Dropwizard metric name cannot be null"); } CompiledMapperConfig matchingConfig = null; for (CompiledMapperConfig config : this.compiledMapperConfigs) { if (config.pattern.matches(dropwizardName)) { matchingConfig = config; break; } } if (matchingConfig != null) { final Map<String, String> params = matchingConfig.pattern.extractParameters(dropwizardName); final NameAndLabels nameAndLabels = getNameAndLabels(matchingConfig.mapperConfig, params); nameAndLabels.labelNames.addAll(additionalLabelNames); nameAndLabels.labelValues.addAll(additionalLabelValues); return defaultMetricSampleBuilder.createSample( nameAndLabels.name, nameSuffix, nameAndLabels.labelNames, nameAndLabels.labelValues, value ); } return defaultMetricSampleBuilder.createSample( dropwizardName, nameSuffix, additionalLabelNames, additionalLabelValues, value ); } CustomMappingSampleBuilder(final List<MapperConfig> mapperConfigs); @Override Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value); }
CustomMappingSampleBuilder implements SampleBuilder { @Override public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value) { if (dropwizardName == null) { throw new IllegalArgumentException("Dropwizard metric name cannot be null"); } CompiledMapperConfig matchingConfig = null; for (CompiledMapperConfig config : this.compiledMapperConfigs) { if (config.pattern.matches(dropwizardName)) { matchingConfig = config; break; } } if (matchingConfig != null) { final Map<String, String> params = matchingConfig.pattern.extractParameters(dropwizardName); final NameAndLabels nameAndLabels = getNameAndLabels(matchingConfig.mapperConfig, params); nameAndLabels.labelNames.addAll(additionalLabelNames); nameAndLabels.labelValues.addAll(additionalLabelValues); return defaultMetricSampleBuilder.createSample( nameAndLabels.name, nameSuffix, nameAndLabels.labelNames, nameAndLabels.labelValues, value ); } return defaultMetricSampleBuilder.createSample( dropwizardName, nameSuffix, additionalLabelNames, additionalLabelValues, value ); } CustomMappingSampleBuilder(final List<MapperConfig> mapperConfigs); @Override Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List<String> additionalLabelNames, final List<String> additionalLabelValues, final double value);  }