stat

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

README

component-stat - Settings component for generating a metrics client

GoDoc

autoauto- [component-stat - Settings component for generating a metrics client](#component-stat---settings-component-for-generating-a-metrics-client)auto - [Overview](#overview)auto - [Quick Start](#quick-start)auto - [Status](#status)auto - [Contributing](#contributing)auto - [Building And Testing](#building-and-testing)auto - [License](#license)auto - [Contributing Agreement](#contributing-agreement)autoauto

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/v2"
)

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 CountAggregator added in v0.3.0

type CountAggregator struct {
	Stater xstats.XStater
	Bucket map[StatTagKey]float64

	FlushInterval time.Duration
	// contains filtered or unexported fields
}

CountAggregator is a wrapper around xstats.XStater, that aggregates Count metrics on a time interval before sending them through Stater

func (*CountAggregator) AddTags added in v0.3.0

func (ca *CountAggregator) AddTags(tags ...string)

AddTags implements XStater interface

func (*CountAggregator) Count added in v0.3.0

func (ca *CountAggregator) Count(stat string, count float64, tags ...string)

Count implements XStater interface. This Count in particular inserts a stat, then proceeds to try to flush the Bucket. If there exists a flush in progress, we proceed to overflow on the channel and return by default

func (*CountAggregator) Gauge added in v0.3.0

func (ca *CountAggregator) Gauge(stat string, value float64, tags ...string)

Gauge implements XStater interface

func (*CountAggregator) GetTags added in v0.3.0

func (ca *CountAggregator) GetTags() []string

GetTags implements XStater interface

func (*CountAggregator) Histogram added in v0.3.0

func (ca *CountAggregator) Histogram(stat string, value float64, tags ...string)

Histogram implements XStater interface

func (*CountAggregator) Timing added in v0.3.0

func (ca *CountAggregator) Timing(stat string, duration time.Duration, tags ...string)

Timing implements XStater interface

type CountAggregatorComponent added in v0.3.0

type CountAggregatorComponent struct {
	StatComponent *DatadogComponent
}

CountAggregatorComponent implements the settings.Component interface for a countaggregator.

func (*CountAggregatorComponent) New added in v0.3.0

New creates a configured countaggregator that wraps around a stats client.

func (*CountAggregatorComponent) Settings added in v0.3.0

Settings generates a config with default values applied.

type CountAggregatorConfig added in v0.3.0

type CountAggregatorConfig struct {
	FlushInterval time.Duration `description:"Frequency of when to send aggregated metrics."`
	StatConfig    *DatadogConfig
}

CountAggregatorConfig is the configuration for a CountAggregator.

func (*CountAggregatorConfig) Name added in v0.3.0

func (*CountAggregatorConfig) 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.

type StatTagKey added in v0.3.0

type StatTagKey struct {
	StatKey string
	TagsKey string
}

StatTagKey is a struct that represents a composite key for storing aggregated stats

Jump to

Keyboard shortcuts

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