GithubHelp home page GithubHelp logo

so1us2 / metric-schema Goto Github PK

View Code? Open in Web Editor NEW

This project forked from palantir/metric-schema

0.0 0.0 0.0 418 KB

Schema for standard metric definitions

License: Apache License 2.0

Shell 0.05% Java 92.99% Groovy 6.96%

metric-schema's Introduction

Metric Schema

A simple opinionated toolchain to define and document metrics produced by a project.

Features:

  • Source of truth for metrics, eliminating incorrect and outdated documentation.
  • Produces a standardized representation of metrics to library and service consumers based on the classpath.

The generated java utilities wrap a Tritium registry to provide simple, concise accessors to declared metrics.

Usage

Metric definitions are located in project src/main/metrics directories. Files are YAML formatted with the .yml extension and represent a collection of namespaces, a logical group of metrics with a shared prefix. The schema is defined using conjure, and can be found here.

Metric utilities are updated using the generateMetrics gradle task. If this is the first metric definition in the module, it may be necessary to regenerate the IDE configuration after metrics are generated, IntelliJ IDEA users can run the idea task.

./gradlew generateMetrics

Metric documentation is updated using the generateMetricsMarkdown gradle task or by running ./gradlew --write-locks. The gradle plugin will ensure that the metrics markdown is always up to date.

All metric definitions will be embedded within the output JAR as a resource located metric-schema/metrics.json.

Example

# Prefix applied to all metrics
namespaces:
  my.service:
    # Documentation describing the entire namespace.
    docs: Metrics helpful for monitoring a my-service instance.
    metrics:
      # Results in a meter with name `my.service.failures` tagged with `{operationType: <value>}`
      failures:
        type: meter
        tags:
          - operationType
        docs: Rate of failures by `operationType`
      # results in a histogram with name `my.service.result.batch.size` and no tags.
      result.batch.size:
        type: histogram
        # Provide additional context beyond the metric name
        docs: Batch size (based on the number of elements) of results written to s3.

The example schema produces the following utility class for java consumers:

/** Metrics helpful for monitoring a my-service instance. */
public final class MyServiceMetrics {
    private final TaggedMetricRegistry registry;

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

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

    /** Rate of failures by <code>operationType</code> */
    public Meter failures(String operationType) {
        return registry.meter(
                MetricName.builder()
                        .safeName("my.service.failures")
                        .putSafeTags("operationType", operationType)
                        .build());
    }

    /** Batch size (based on the number of elements) of results written to s3. */
    public Histogram resultBatchSize() {
        return registry.histogram(
                MetricName.builder().safeName("my.service.result.batch.size").build());
    }

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

The utility should be created once and reused.

MyServiceMetrics metrics = MyServiceMetrics.of(server.taggedMetrics());
// Metric objects should be reused as much as possible to avoid unnecessary lookups
Meter creationFailures = metrics.failures("create");

Options

Metric definitions can also include options that do not change the overall declaration, but may affect the way it is handled in a particular context.

options:
  javaPackage: 'com.palantir.my.package' # Specifies under which package Java classes should be generated
  javaVisibility: packagePrivate # Specifies visibility of generated Utility class. Defaults to public
namespaces:
...

Installation

Add the gradle-metric-schema gradle plugin dependency to the root build.gradle.

buildscript {
  dependencies {
    classpath 'com.palantir.metricschema:gradle-metric-schema:<VERSION>'   
  }
}

Apply the com.palantir.metric-schema plugin to build.gradle in the module which defines metrics.

apply plugin: 'com.palantir.metric-schema'

Architecture

Design documentation describing the rationale for decisions is maintained in design.md.

Gradle Tasks

./gradlew tasks - to get the list of gradle tasks

Start Developing

Run one of the following commands:

  • ./gradlew idea for IntelliJ
  • ./gradlew eclipse for Eclipse

metric-schema's People

Contributors

bulldozer-bot[bot] avatar cannoliopsida avatar carterkozak avatar ferozco avatar schlosna avatar svc-autorelease avatar svc-excavator-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.