Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All metrics include dialogueVersion #436

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-436.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: All tagged metrics produced by dialogue will now have an extra `dialogueVersion`
tag.
links:
- https://github.com/palantir/dialogue/pull/436
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 <T> Gauge<T> gauge(MetricName metricName, Gauge<T> gauge) {
return delegate.gauge(augment(metricName), gauge);
}

@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 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");
}
}