
com.palantir.dialogue.core.DialogueNodeselectionMetrics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dialogue-core Show documentation
Show all versions of dialogue-core Show documentation
Palantir open source project
package com.palantir.dialogue.core;
import com.codahale.metrics.Meter;
import com.google.errorprone.annotations.CheckReturnValue;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.Safe;
import com.palantir.tritium.metrics.registry.MetricName;
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
/**
* Instrumentation for which node selection strategy is used
*/
final class DialogueNodeselectionMetrics {
private static final String JAVA_VERSION = System.getProperty("java.version", "unknown");
private static final String LIBRARY_NAME = "dialogue";
private static final String LIBRARY_VERSION = "4.7.0";
private final TaggedMetricRegistry registry;
private DialogueNodeselectionMetrics(TaggedMetricRegistry registry) {
this.registry = registry;
}
static DialogueNodeselectionMetrics of(TaggedMetricRegistry registry) {
return new DialogueNodeselectionMetrics(Preconditions.checkNotNull(registry, "TaggedMetricRegistry"));
}
/**
* Marked every time the node selection strategy changes
*/
@CheckReturnValue
StrategyBuilderChannelNameStage strategy() {
return new StrategyBuilder();
}
@Override
public String toString() {
return "DialogueNodeselectionMetrics{registry=" + registry + '}';
}
interface StrategyBuildStage {
@CheckReturnValue
Meter build();
@CheckReturnValue
MetricName buildMetricName();
}
interface StrategyBuilderChannelNameStage {
@CheckReturnValue
StrategyBuilderStrategyStage channelName(@Safe String channelName);
}
interface StrategyBuilderStrategyStage {
@CheckReturnValue
StrategyBuildStage strategy(@Safe String strategy);
}
private final class StrategyBuilder
implements StrategyBuilderChannelNameStage, StrategyBuilderStrategyStage, StrategyBuildStage {
private String channelName;
private String strategy;
@Override
public StrategyBuilder channelName(@Safe String channelName) {
Preconditions.checkState(this.channelName == null, "channel-name is already set");
this.channelName = Preconditions.checkNotNull(channelName, "channel-name is required");
return this;
}
@Override
public StrategyBuilder strategy(@Safe String strategy) {
Preconditions.checkState(this.strategy == null, "strategy is already set");
this.strategy = Preconditions.checkNotNull(strategy, "strategy is required");
return this;
}
@Override
public Meter build() {
return registry.meter(buildMetricName());
}
@Override
public MetricName buildMetricName() {
return MetricName.builder()
.safeName("dialogue.nodeselection.strategy")
.putSafeTags("channel-name", channelName)
.putSafeTags("strategy", strategy)
.putSafeTags("libraryName", LIBRARY_NAME)
.putSafeTags("libraryVersion", LIBRARY_VERSION)
.putSafeTags("javaVersion", JAVA_VERSION)
.build();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy