httpstats

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

component-httpstats - Settings component for generating an HTTP stat client

GoDoc

autoauto- [component-httpstats - Settings component for generating an HTTP stat client](#component-httpstats---settings-component-for-generating-an-http-stat-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 an http client whose transport logs key HTTP metrics with configurable names on every request. The resulting client is powered by xstats and httpstats.

Quick Start

package main

import (
    "context"
    "net/http"
    "os"

    "github.com/asecurityteam/component-httpstats"
    "github.com/asecurityteam/transport"
    "github.com/asecurityteam/settings/v2"
)

func main() {
    ctx := context.Background()
    os.SetEnv("METRICS_BACKEND", "testdependency")
    envSource := settings.NewEnvSource(os.Environ())

    client := &http.Client(
        Transport: httpstats.New(ctx, envSource)(
            transport.New(
              transport.OptionMaxResponseHeaderBytes(4096),
              transport.OptionDisableCompression(true)
            )
        )
    )
    req, _ := http.NewRequest(http.MethodGet, "www.google.com", http.NoBody)

    // various HTTP metrics emitted and tagged with a "client_dependency"
    // value of "testdependency", among other default tag keys and values
    _, _ := client.Do(req)
}

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

This section is empty.

Variables

View Source
var ErrNoBackend = errors.New("no backend configured")

ErrNoBackend is returned when attempting to initialize a MetricsComponent without configuring a value for the Backend tag.

Functions

func New

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

New is the top-level entrypoint for creating an `http.Transport` decorator that emits HTTP metrics on every `RoundTrip`.

Useful when configuring a `MetricsComponent` outside of the hierarchy of a surrounding application.

Types

type MetricsComponent

type MetricsComponent struct{}

MetricsComponent implements the settings.Component interface.

func NewComponent

func NewComponent() *MetricsComponent

NewComponent populates default values.

func (*MetricsComponent) New

New generates the HTTP metrics transport decorator.

If `Dependency` is zero-valued, this constructor will return an error.

If `Path` is zero-valued, this constructor adds an `httpstats.TransportOptionRequestTag` that dynamically tags the request path on each request made with the decorated `http.Transport`.

func (*MetricsComponent) Settings

func (*MetricsComponent) Settings() *MetricsConfig

Settings generates a config populated with defaults.

type MetricsConfig

type MetricsConfig struct {
	Timing            string `description:"Name of overall timing metric."`
	DNS               string `description:"Name of DNS timing metric."`
	TCP               string `description:"Name of TCP timing metric."`
	ConnectionIdle    string `description:"Name of idle timing metric."`
	TLS               string `description:"Name of TLS timing metric."`
	WroteHeaders      string `description:"Name of time to write headers metric."`
	FirstResponseByte string `description:"Name of time to first resposne byte metrics."`
	BytesReceived     string `description:"Name of bytes received metric."`
	BytesSent         string `description:"Name of bytes sent metric."`
	BytesTotal        string `description:"Name of bytes sent and received metric."`
	PutIdle           string `description:"Name of idle connection return count metric."`
	BackendTag        string `description:"Name of the tag containing the backend reference."`
	PathTag           string `description:"Name of the tag containing the path reference."`
	Backend           string `description:"Static value for the backend tag metric."`
	Path              string `description:"Static value for the path tag metric. If not specified, will be generated for each request."`
	OmitPathTag       bool   `` /* 147-byte string literal not displayed */
}

MetricsConfig contains settings for request metrics emissions.

func (*MetricsConfig) Name

func (*MetricsConfig) Name() string

Name of the config root.

Jump to

Keyboard shortcuts

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