stat

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2019 License: Apache-2.0 Imports: 8 Imported by: 3

README

component-stat - Settings component for generating a metrics client

Overview

This is a settings that enables constructing a metrics client. The resulting client is powered by xstats and can output to a variety of metrics collecting systems.

Quick Start

package main

import (
    "context"

    stat "github.com/asecurityteam/component-stat"
    "github.com/asecurityteam/settings"
)

func main() {
    ctx := context.Background()
    envSource := settings.NewEnvSource(os.Environ())

    s := stat.New(ctx, envSource)
    s.Count("my_metric", 1, "tag:value", "tag2:value2")
}

Status

This project is in incubation which means we are not yet operating this tool in production and the interfaces are subject to change.

Contributing

Building And Testing

We publish a docker image called SDCLI that bundles all of our build dependencies. It is used by the included Makefile to help make building and testing a bit easier. The following actions are available through the Makefile:

  • make dep

    Install the project dependencies into a vendor directory

  • make lint

    Run our static analysis suite

  • make test

    Run unit tests and generate a coverage artifact

  • make integration

    Run integration tests and generate a coverage artifact

  • make coverage

    Report the combined coverage for unit and integration tests

License

This project is licensed under Apache 2.0. See LICENSE.txt for details.

Contributing Agreement

Atlassian requires signing a contributor's agreement before we can accept a patch. If you are an individual you can fill out the individual CLA. If you are contributing on behalf of your company then please fill out the corporate CLA.

Documentation

Index

Constants

View Source
const (

	// OutputNull is the selection for no metrics.
	OutputNull = "NULL"
	// OutputDatadog selects the datadog/extended-statsd driver.
	OutputDatadog = "DATADOG"
)

Variables

View Source
var StatFromContext = xstats.FromContext

StatFromContext is the concrete implementation of StatFn that should be used at runtime.

Functions

This section is empty.

Types

type Component

type Component struct {
	NullStat *NullComponent
	Datadog  *DatadogComponent
}

Component enables creating configured loggers.

func NewComponent

func NewComponent() *Component

NewComponent populates an StatComponent with defaults.

func (*Component) New

func (c *Component) New(ctx context.Context, conf *Config) (Stat, error)

New creates a configured stats client.

func (*Component) Settings

func (c *Component) Settings() *Config

Settings generates a StatsConfig with default values applied.

type Config

type Config struct {
	Output   string `description:"Destination stream of the stats. One of NULLSTAT, DATADOG."`
	NullStat *NullConfig
	Datadog  *DatadogConfig
}

Config contains all configuration values for creating a system stat client.

func (*Config) Name

func (*Config) Name() string

Name of the configuration as it might appear in config files.

type DatadogComponent

type DatadogComponent struct{}

DatadogComponent implements the settings.Component interface for a datadog stats client.

func (*DatadogComponent) New

New creates a configured stats client.

func (*DatadogComponent) Settings

func (*DatadogComponent) Settings() *DatadogConfig

Settings generates a config with default values applied.

type DatadogConfig

type DatadogConfig struct {
	Address       string        `description:"Listener address to use when sending metrics."`
	FlushInterval time.Duration `description:"Frequencing of sending metrics to listener."`
	Tags          []string      `description:"Any static tags for all metrics."`
	PacketSize    int           `description:"Max packet size to send."`
}

DatadogConfig is for configuration a datadog client.

func (*DatadogConfig) Name

func (*DatadogConfig) Name() string

Name of the configuration as it might appear in config files.

type NullComponent

type NullComponent struct{}

NullComponent implements the settings.Component interface for a NOP stat client.

func (*NullComponent) New

func (*NullComponent) New(_ context.Context, conf *NullConfig) (Stat, error)

New creates a configured stats client.

func (*NullComponent) Settings

func (*NullComponent) Settings() *NullConfig

Settings generates a config with default values applied.

type NullConfig

type NullConfig struct{}

NullConfig is empty. There are no options for NULL.

func (*NullConfig) Name

func (*NullConfig) Name() string

Name of the configuration as it might appear in config files.

type Stat

type Stat = xstats.XStater

Stat is the project metrics client interface. it is currently an alias for xstats.XStater.

func Load

func Load(ctx context.Context, source settings.Source, c *Component) (Stat, error)

Load is a convenience method for binding the source to the component.

func New

func New(ctx context.Context, source settings.Source) (Stat, error)

New is the top-level entry point for creating a new stat client.

type StatFn

type StatFn func(context.Context) Stat

StatFn is the type that should be accepted by code that intend to emit custom metrics using the context stat client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL