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

HDDS-3236. Fix Dropwizard metrics mapping for latest Ratis metrics. #707

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder;
import org.apache.logging.log4j.util.Strings;
import static org.apache.ratis.server.metrics.RatisMetrics.RATIS_APPLICATION_NAME_METRICS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Collect Dropwizard metrics and rename ratis specific metrics.
*/
public class RatisNameRewriteSampleBuilder extends DefaultSampleBuilder {

private static final Logger LOG =
LoggerFactory.getLogger(RatisNameRewriteSampleBuilder.class);

private List<Pattern> followerPatterns = new ArrayList<>();

public RatisNameRewriteSampleBuilder() {
Expand All @@ -41,8 +46,8 @@ public RatisNameRewriteSampleBuilder() {
"grpc_log_appender_follower_(.*)_(latency|success|inconsistency)"
+ ".*"));
followerPatterns
.add(Pattern.compile("follower_(.*)_lastHeartbeatElapsedTime"));
followerPatterns.add(Pattern.compile("(.*)_peerCommitIndex"));
.add(Pattern.compile("follower_([^_]*)_.*"));
followerPatterns.add(Pattern.compile("([^_]*)_peerCommitIndex"));

}

Expand All @@ -51,12 +56,16 @@ public Sample createSample(String dropwizardName, String nameSuffix,
List<String> additionalLabelNames, List<String> additionalLabelValues,
double value) {
//this is a ratis metrics, where the second part is an instance id.
if (dropwizardName.startsWith(RATIS_APPLICATION_NAME_METRICS)
|| (dropwizardName.startsWith("ratis_grpc"))) {
if (dropwizardName.startsWith(RATIS_APPLICATION_NAME_METRICS)) {
List<String> names = new ArrayList<>(additionalLabelNames);
List<String> values = new ArrayList<>(additionalLabelValues);
String name = normalizeRatisMetric(dropwizardName, names, values);

if (LOG.isTraceEnabled()) {
LOG.trace(
"Ratis dropwizard {} metrics are converted to {} with tag "
+ "keys/values {},{}", dropwizardName, name, names, values);
}
return super
.createSample(name, nameSuffix,
names,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public class TestRatisNameRewrite {
@Parameterized.Parameters
public static List<Object[]> parameters() {
return Arrays.asList(
new Object[] {
"ratis.log_appender"
+ ".851cb00a-af97-455a-b079-d94a77d2a936@group-C14654DE8C2C"
+ ".follower_65f881ea-8794-403d-be77-a030ed79c341_match_index",
"ratis.log_appender.follower_match_index",
new String[] {"instance", "group", "follower"},
new String[] {"851cb00a-af97-455a-b079-d94a77d2a936",
"group-C14654DE8C2C",
"65f881ea-8794-403d-be77-a030ed79c341"}
},
new Object[] {
"ratis_grpc.log_appender.72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67@group"
+ "-72caaf3a-fb1c-4da4-9cc0-a2ce21bb8e67"
Expand Down