Coder Social home page Coder Social logo

Comments (3)

groob avatar groob commented on June 2, 2024

Now that we have a datastore abstraction, adding metrics on top would be a great place to start, and I'd like to tackle this sometime soon.

Here's what I'd like to do.

package datastore

// a private type that embeds the datastore interface
type instrumented struct {
    count metrics.Counter
    latency metrics.TimeHistogram
    Datastore
}

accept a datastore and return back the above one

func NewWithMetrics(ds Datastore) Datastore {
    count := metrics.NewCounter(...)
    latency := metrics. NewTimeHistogram(...)

    return instrumented{count, latency, ds}
}

layer methods on top of datastore

func (mw instrumented) NewUser(user *kolide.User) (user *kolide.User, err error) {
// from go-kit metrics example  
defer func(begin time.Time) {
        methodField := metrics.Field{Key: "method", Value: "newuser"}
        errorField := metrics.Field{Key: "error", Value: fmt.Sprintf("%v", err)}
        mw.requestCount.With(methodField).With(errorField).Add(1)
        mw.requestLatency.With(methodField).With(errorField).Observe(time.Since(begin))
  }(time.Now())
  user, err = mw.Datastore.NewUser(user)
}

from fleet.

marpaia avatar marpaia commented on June 2, 2024

This should be easy to do now that we're using go-kit.

from fleet.

groob avatar groob commented on June 2, 2024

Closing as I've begun initial work in #236
Will continue going down this path from now on.

from fleet.

Related Issues (20)

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.