Skip to content

Commit

Permalink
All metrics include dialogueVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdanfox committed Feb 26, 2020
1 parent f92e18f commit 6892108
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static Channel create(Collection<? extends Channel> channels, ClientConfi
Preconditions.checkArgument(!channels.isEmpty(), "channels must not be empty");
Preconditions.checkArgument(config.userAgent().isPresent(), "config.userAgent() must be specified");

DialogueClientMetrics clientMetrics = DialogueClientMetrics.of(config.taggedMetricRegistry());
DialogueClientMetrics clientMetrics =
DialogueClientMetrics.of(new VersionedTaggedMetricRegistry(config.taggedMetricRegistry()));
List<LimitedChannel> limitedChannels = channels.stream()
// Instrument inner-most channel with metrics so that we measure only the over-the-wire-time
.map(channel -> new InstrumentedChannel(channel, clientMetrics))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.dialogue.core;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.codahale.metrics.Timer;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import com.palantir.tritium.metrics.registry.TaggedMetricSet;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

final class VersionedTaggedMetricRegistry implements TaggedMetricRegistry {
private static final String DIALOGUE_VERSION = Optional.ofNullable(
VersionedTaggedMetricRegistry.class.getPackage().getImplementationVersion())
.orElse("dev");

private final TaggedMetricRegistry delegate;

VersionedTaggedMetricRegistry(TaggedMetricRegistry delegate) {
this.delegate = delegate;
}

private MetricName augment(MetricName name) {
return MetricName.builder()
.from(name)
.putSafeTags("dialogueVersion", DIALOGUE_VERSION)
.build();
}

@Override
public Map<MetricName, Metric> getMetrics() {
return delegate.getMetrics();
}

@Override
public void forEachMetric(BiConsumer<MetricName, Metric> consumer) {
delegate.forEachMetric(consumer);
}

@Override
public <T> Optional<Gauge<T>> gauge(MetricName metricName) {
return delegate.gauge(augment(metricName));
}

@Override
public void registerWithReplacement(MetricName metricName, Gauge<?> gauge) {
delegate.registerWithReplacement(augment(metricName), gauge);
}

@Override
public Timer timer(MetricName metricName) {
return delegate.timer(augment(metricName));
}

@Override
public Timer timer(MetricName metricName, Supplier<Timer> timerSupplier) {
return delegate.timer(augment(metricName), timerSupplier);
}

@Override
public Meter meter(MetricName metricName) {
return delegate.meter(augment(metricName));
}

@Override
public Meter meter(MetricName metricName, Supplier<Meter> meterSupplier) {
return delegate.meter(augment(metricName), meterSupplier);
}

@Override
public Histogram histogram(MetricName metricName) {
return delegate.histogram(augment(metricName));
}

@Override
public Histogram histogram(MetricName metricName, Supplier<Histogram> histogramSupplier) {
return delegate.histogram(augment(metricName), histogramSupplier);
}

@Override
public <T> Gauge<T> gauge(MetricName metricName, Gauge<T> gauge) {
return delegate.gauge(augment(metricName), gauge);
}

@Override
public Counter counter(MetricName metricName) {
return delegate.counter(augment(metricName));
}

@Override
public Counter counter(MetricName metricName, Supplier<Counter> counterSupplier) {
return delegate.counter(augment(metricName), counterSupplier);
}

@Override
public void addMetrics(String safeTagName, String safeTagValue, TaggedMetricSet metrics) {
throw new UnsupportedOperationException(
"Operations involving transforming metricsets are not implemented as we don't need them in dialogue");
}

@Override
public Optional<Metric> remove(MetricName metricName) {
throw new UnsupportedOperationException(
"Removal operations are not implemented as we don't need them in dialogue");
}

@Override
public Optional<TaggedMetricSet> removeMetrics(String safeTagName, String safeTagValue) {
throw new UnsupportedOperationException(
"Removal operations are not implemented as we don't need them in dialogue");
}

@Override
public boolean removeMetrics(String safeTagName, String safeTagValue, TaggedMetricSet metrics) {
throw new UnsupportedOperationException(
"Removal operations are not implemented as we don't need them in dialogue");
}
}

0 comments on commit 6892108

Please sign in to comment.