All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palantir.conjure.java.serialization.JsonParserMetrics Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
package com.palantir.conjure.java.serialization;

import com.codahale.metrics.Histogram;
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;

/**
 * Metrics produced instrumented Jackson components.
 */
final class JsonParserMetrics {
    private static final String JAVA_VERSION = System.getProperty("java.version", "unknown");

    private static final String LIBRARY_NAME = "conjure-java-runtime";

    private static final String LIBRARY_VERSION = "8.13.0";

    private final TaggedMetricRegistry registry;

    private JsonParserMetrics(TaggedMetricRegistry registry) {
        this.registry = registry;
    }

    static JsonParserMetrics of(TaggedMetricRegistry registry) {
        return new JsonParserMetrics(Preconditions.checkNotNull(registry, "TaggedMetricRegistry"));
    }

    /**
     * Histogram describing the length of strings parsed from input.
     */
    @CheckReturnValue
    Histogram stringLength(@Safe String format) {
        return registry.histogram(stringLengthMetricName(format));
    }

    static MetricName stringLengthMetricName(@Safe String format) {
        return MetricName.builder()
                .safeName("json.parser.string.length")
                .putSafeTags("format", format)
                .putSafeTags("libraryName", LIBRARY_NAME)
                .putSafeTags("libraryVersion", LIBRARY_VERSION)
                .putSafeTags("javaVersion", JAVA_VERSION)
                .build();
    }

    @Override
    public String toString() {
        return "JsonParserMetrics{registry=" + registry + '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy