Giter VIP home page Giter VIP logo

go-metrics-stackdriver's Introduction

go-metrics-stackdriver

godoc

This library provides a stackdriver sink for applications instrumented with the go-metrics library.

๐Ÿšจ Warning

This is not an officially supported Google product.

In general the author of this package would recommend instrumenting custom metrics for new code by following the official GCP documentation, especially for new applications.

This package is intended as a way to publish metrics for applications that are already instrumented with go-metrics without having to use a sidecar process like stackdriver-prometheus-sidecar.

๐Ÿšจ Upgrading

Between v0.5.0 and v0.6.0, the behavior of the IncrCounter() method changed: previously it would create a GAUGE metric kind, but from v0.6.0 forward it will create a CUMULATIVE metric kind. (See #18 for a discussion.)

However, once a MetricDescriptor has been created in Google Cloud Monitoring, its metricKind field cannot be changed. So if you have any existing GAUGE metrics that were created by IncrCounter(), you will see errors in your logs when the v0.6.0 client attempts to update them and fails. Your options for handling this are:

  1. Change the name of the metric you are passing to IncrCounter (creating a new metricDescriptor with a different name), or:
  2. Delete the existing metricDescriptor using the delete API and let go-metrics re-create it as a CUMULATIVE metric

Additionally, v0.6.0 adds ResetCounter() and ResetCounterWithLabels() methods: calling these methods resets the counter value to zero.

Details

stackdriver.NewSink's return value satisfies the go-metrics library's MetricSink interface. When providing a stackdriver.Sink to libraries and applications instrumented against MetricSink, the metrics will be aggregated within this library and written to stackdriver as Generic Task timeseries metrics.

Example

import "github.com/google/go-metrics-stackdriver"
...
client, _ := monitoring.NewMetricClient(context.Background())
ss := stackdriver.NewSink(client, &stackdriver.Config{
  ProjectID: projectID,
})
...
ss.SetGauge([]string{"foo"}, 42)
ss.IncrCounter([]string{"baz"}, 1)
ss.AddSample([]string{"method", "const"}, 200)

The full example can be run from a cloud shell console to test how metrics are collected and displayed.

You can also try out the example using Cloud Run!

Run on Google Cloud

go-metrics-stackdriver's People

Contributors

daisy1754 avatar minor-fixes avatar n-oden avatar rf avatar tam7t avatar zdunecki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-metrics-stackdriver's Issues

Graceful shutdown of Sink

Hi.
In some cases, there is a graceful shutdown logic of the application (such as in Cloud Run), and I need a way to gracefully shutdown the Sink as well, so pending metrics will get sent upon closure and not lost.

Switch counter metrics to use cumulative or delta

It turns out that a counter metrics use a gauge metric type as here

MetricKind: metricpb.MetricDescriptor_GAUGE,

This doesn't seem to be right. According to documentation of Aligner I am unable to calculate deltas if the metric is not defined as delta or cumulative. This is a big limitation. Should we consider switching to cumulative in case of counters?

Sampling Results Inaccurate

This library used to work, but lately it started to produce weird and inaccurate values.
If I run the full example and check in stackdriver UI for foo metric: m.AddSample([]string{"foo"}, 100), the result in stackdriver is 75 for some reason. It happens on every sample in the basic example.

Screen Shot 2022-01-11 at 0 44 08

Error: Only one point can be written per TimeSeries

We are facing this error when using the library:

2021/02/12 18:23:36 Failed to write time series data: rpc error: code = InvalidArgument desc = One or more TimeSeries could not be written: Field timeSeries[11] had an invalid value: Duplicate TimeSeries encountered. Only one point can be written per TimeSeries per request.: timeSeries[11];

Use protocmp for rpc testing

The expectations in stackdriver_test.go would be much more readable of a package like protocmp was used for ensuring the requests had the correct data.

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.