metrics

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Enabled is a flag to enable or disable the OpenTelemetry
	Enabled bool `yaml:"enabled" mapstructure:"enabled"`
	// Exporter is the otlp exporter used to export the traces
	Exporter Exporter `yaml:"exporter" mapstructure:"exporter"`
	// Url is the Url of the collector to which the traces are exported
	Url string `yaml:"url" mapstructure:"url"`
	// Token is the token used to authenticate with the collector
	Token string `yaml:"token" mapstructure:"token"`
	// TLS holds the tls configuration
	TLS TLSConfig `yaml:"tls" mapstructure:"tls"`
}

Config holds the configuration for OpenTelemetry

func (*Config) Validate

func (c *Config) Validate(ctx context.Context) error

type Exporter

type Exporter string

Exporter is the protocol used to export the traces

const (
	// HTTP is the protocol used to export the traces via HTTP/1.1
	HTTP Exporter = "http"
	// GRPC is the protocol used to export the traces via HTTP/2 (gRPC)
	GRPC Exporter = "grpc"
	// STDOUT is the protocol used to export the traces to the standard output
	STDOUT Exporter = "stdout"
	// NOOP is the protocol used to not export the traces
	NOOP Exporter = "noop"
)

func (Exporter) Create

func (e Exporter) Create(ctx context.Context, config *Config) (sdktrace.SpanExporter, error)

Create creates a new exporter based on the configuration

func (Exporter) IsExporting

func (e Exporter) IsExporting() bool

IsExporting returns true if the protocol is exporting the traces

func (Exporter) String

func (e Exporter) String() string

String returns the string representation of the protocol

func (Exporter) Validate

func (e Exporter) Validate() error

Validate validates the protocol

type FileOpener

type FileOpener func(string) (fs.File, error)

FileOpener is the function used to open a file

type Provider

type Provider interface {
	// GetRegistry returns the prometheus registry instance
	// containing the registered prometheus collectors
	GetRegistry() *prometheus.Registry
	// InitTracing initializes the OpenTelemetry tracing
	InitTracing(ctx context.Context) error
	// Shutdown closes the metrics and tracing
	Shutdown(ctx context.Context) error
}

func New

func New(config Config) Provider

New initializes the metrics and returns the PrometheusMetrics

type ProviderMock

type ProviderMock struct {
	// GetRegistryFunc mocks the GetRegistry method.
	GetRegistryFunc func() *prometheus.Registry

	// InitTracingFunc mocks the InitTracing method.
	InitTracingFunc func(ctx context.Context) error

	// ShutdownFunc mocks the Shutdown method.
	ShutdownFunc func(ctx context.Context) error
	// contains filtered or unexported fields
}

ProviderMock is a mock implementation of Provider.

func TestSomethingThatUsesProvider(t *testing.T) {

	// make and configure a mocked Provider
	mockedProvider := &ProviderMock{
		GetRegistryFunc: func() *prometheus.Registry {
			panic("mock out the GetRegistry method")
		},
		InitTracingFunc: func(ctx context.Context) error {
			panic("mock out the InitTracing method")
		},
		ShutdownFunc: func(ctx context.Context) error {
			panic("mock out the Shutdown method")
		},
	}

	// use mockedProvider in code that requires Provider
	// and then make assertions.

}

func (*ProviderMock) GetRegistry

func (mock *ProviderMock) GetRegistry() *prometheus.Registry

GetRegistry calls GetRegistryFunc.

func (*ProviderMock) GetRegistryCalls

func (mock *ProviderMock) GetRegistryCalls() []struct {
}

GetRegistryCalls gets all the calls that were made to GetRegistry. Check the length with:

len(mockedProvider.GetRegistryCalls())

func (*ProviderMock) InitTracing

func (mock *ProviderMock) InitTracing(ctx context.Context) error

InitTracing calls InitTracingFunc.

func (*ProviderMock) InitTracingCalls

func (mock *ProviderMock) InitTracingCalls() []struct {
	Ctx context.Context
}

InitTracingCalls gets all the calls that were made to InitTracing. Check the length with:

len(mockedProvider.InitTracingCalls())

func (*ProviderMock) Shutdown

func (mock *ProviderMock) Shutdown(ctx context.Context) error

Shutdown calls ShutdownFunc.

func (*ProviderMock) ShutdownCalls

func (mock *ProviderMock) ShutdownCalls() []struct {
	Ctx context.Context
}

ShutdownCalls gets all the calls that were made to Shutdown. Check the length with:

len(mockedProvider.ShutdownCalls())

type TLSConfig

type TLSConfig struct {
	// Enabled is a flag to enable or disable the tls
	Enabled bool `yaml:"enabled" mapstructure:"enabled"`
	// CertPath is the path to the tls certificate file.
	// This is only required if the otel backend uses custom TLS certificates.
	CertPath string `yaml:"certPath" mapstructure:"certPath"`
}

Jump to

Keyboard shortcuts

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