sundheitotel

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-sundheit-opentelemetry

Actions Status CircleCI Coverage Status Go Report Card Godocs

A library built to provide support for open telemetry metrics for go-sundheit.

Installation

Using go modules:

go get github.com/AppsFlyer/go-sundheit-opentelemetry@v0.0.1

Usage

import (
	"net/http"
	"time"
	"log"

	"github.com/pkg/errors"
	"github.com/AppsFlyer/go-sundheit"
    sundheit_opentelemetry "github.com/AppsFlyer/go-sundheit-opentelemetry"

    healthhttp "github.com/AppsFlyer/go-sundheit/http"
	"github.com/AppsFlyer/go-sundheit/checks"
)

func main() {
    // creates otel metrics listener
    ot := sundheit_opentelemetry.NewMetricsListener()

	// create a new health instance
	h := gosundheit.New(gosundheit.WithCheckListeners(ot), gosundheit.WithHealthListeners(ot))
	
	// define an HTTP dependency check
	httpCheckConf := checks.HTTPCheckConfig{
		CheckName: "httpbin.url.check",
		Timeout:   1 * time.Second,
		// dependency you're checking - use your own URL here...
		// this URL will fail 50% of the times
		URL:       "http://httpbin.org/status/200,300",
	}
	// create the HTTP check for the dependency
	// fail fast when you misconfigured the URL. Don't ignore errors!!!
	httpCheck, err := checks.NewHTTPCheck(httpCheckConf)
	if err != nil {
		fmt.Println(err)
		return // your call...
	}

	// Alternatively panic when creating a check fails
	httpCheck = checks.Must(checks.NewHTTPCheck(httpCheckConf))

	err = h.RegisterCheck(
		httpCheck,
		gosundheit.InitialDelay(time.Second),         // the check will run once after 1 sec
		gosundheit.ExecutionPeriod(10 * time.Second), // the check will be executed every 10 sec
	)
	
	if err != nil {
		fmt.Println("Failed to register check: ", err)
		return // or whatever
	}

	// define more checks...
	
	// register a health endpoint
	http.Handle("/admin/health.json", healthhttp.HandleHealthJSON(h))
	
	// serve HTTP
	log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

Index

Constants

View Source
const (
	// ValAllChecks is the value used for the check tags when tagging all tests
	ValAllChecks       = "all_checks"
	StatusMetricName   = "health/status"
	DurationMetricName = "health/execute_time"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsListener

type MetricsListener struct {
	// contains filtered or unexported fields
}

func NewMetricsListener

func NewMetricsListener(opts ...Option) (*MetricsListener, error)

func (*MetricsListener) OnCheckCompleted

func (c *MetricsListener) OnCheckCompleted(name string, result gosundheit.Result)

func (*MetricsListener) OnCheckRegistered

func (c *MetricsListener) OnCheckRegistered(name string, result gosundheit.Result)

func (*MetricsListener) OnCheckStarted

func (c *MetricsListener) OnCheckStarted(_ string)

func (*MetricsListener) OnResultsUpdated

func (c *MetricsListener) OnResultsUpdated(results map[string]gosundheit.Result)

type Option

type Option func(*MetricsListener)

func WithClassification

func WithClassification(classification string) Option

WithClassification set custom classification for metrics

func WithDefaults

func WithDefaults() Option

func WithLivenessClassification

func WithLivenessClassification() Option

WithLivenessClassification sets the classification to "liveness"

func WithMeter

func WithMeter(meter metric.Meter) Option

func WithReadinessClassification

func WithReadinessClassification() Option

WithReadinessClassification sets the classification to "readiness"

func WithStartupClassification

func WithStartupClassification() Option

WithStartupClassification sets the classification to "startup"

Jump to

Keyboard shortcuts

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