metrics

package module
v0.0.0-...-eeb1421 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DtxOperationType             operationType = "dtx"
	RpcOperationType             operationType = "rpc"
	RestOperationType            operationType = "rest"
	SagaOperationType            operationType = "saga"
	TwoPhasedCommitOperationType operationType = "2phasedcommit"
	DbOperationType              operationType = "db"
)

Variables

View Source
var (
	ErrInvalidServiceName error = fmt.Errorf("invalid input argument, service name cannot be nil")
)
View Source
var (
	// TransactionContextKey is the key used for newrelic.FromContext and
	// newrelic.NewContext.
	TransactionContextKey = ctxKeyType(struct{}{})
)

Functions

func AppendSuffix

func AppendSuffix(metricName string, metricType MetricType) string

func FormatMetricName

func FormatMetricName(m *MetricName, metricType MetricType) *string

Types

type Counter

type Counter struct {
	Metric
}

Counter a metric type that only linearly increases

type Gauge

type Gauge struct {
	Metric
}

Gauge a metric type that can increase and decrease

type Metric

type Metric struct {
	MetricName       string
	Name             string
	Help             string
	Subsystem        Subsystem
	Namespace        Namespace
	ServiceName      string
	MetricPartitions map[string]string
}

Metric encompasses the relative metadata associated with a service level metric being emitted

type MetricName

type MetricName struct {
	ServiceName     string
	OperationName   string
	IsDistributedTx bool
	IsDatabaseTx    bool
	IsError         bool
}

type MetricType

type MetricType string
const (
	Count         MetricType = "count"
	ErrorCount    MetricType = "error_count"
	Latency       MetricType = "latency"
	MetricSummary MetricType = "summary"
)
var (
	OperationLatencyMetric MetricType = "service.operation.latency"
	OperationStatusMetric  MetricType = "service.operation.status"
	RpcStatusMetric        MetricType = "service.rpc.status"
)

type MetricsCore

type MetricsCore struct {
	Havester *telemetry.Harvester
}

MetricsCore encapsulates the registration functionality as well as the facility to emit metrics to the new relic platform for observance

type MetricsEngine

type MetricsEngine struct {
	// Metrics encompasses all metrics defined for the various operations this service is part of
	Metrics *ServiceMetrics
	// ServiceName encompasses the name of the service
	ServiceName *string
	// Core is the utility by which metrics are emitted to new-relic
	Client *newrelic.Application
	Core   *MetricsCore
	// contains filtered or unexported fields
}

MetricsEngine enables this service to emit metrics to new relic

func (*MetricsEngine) RecordErrorCountMetric

func (me *MetricsEngine) RecordErrorCountMetric(operation string)

func (*MetricsEngine) RecordRequestCountMetric

func (me *MetricsEngine) RecordRequestCountMetric(operation string, status code.Code)

func (*MetricsEngine) RecordRequestLatencyMetric

func (me *MetricsEngine) RecordRequestLatencyMetric(operationName, destination string, start time.Time)

func (*MetricsEngine) RecordRequestStatusSummaryMetric

func (me *MetricsEngine) RecordRequestStatusSummaryMetric(operation, destination string)

func (*MetricsEngine) RecordStandardDtxMetrics

func (me *MetricsEngine) RecordStandardDtxMetrics(op, dest string, status code.Code, start time.Time)

func (*MetricsEngine) RecordStandardMetrics

func (me *MetricsEngine) RecordStandardMetrics(op string, isOperationSuccessful bool)

type Namespace

type Namespace string
const (
	RequestNamespace                   Namespace = "request.namespace"
	DistributedTxNamespace             Namespace = "dtx.namespace"
	DistributedSagaTxNamespace         Namespace = "dtx.saga.namespace"
	DistributedTx2PhaseCommitNamespace Namespace = "dtx.2phase_commit.namespace"
	DistributedTxTccNamespace          Namespace = "dtx.tcc.namespace"
	ServiceNamespace                   Namespace = "service.namespace"
	DatabaseNamespace                  Namespace = "database.namespace"
)

type RequestTimeKey

type RequestTimeKey struct{}

type ServiceDetails

type ServiceDetails struct {
	ServiceName string
	// The version of the service actively deployed
	Version string
	// The service P.O.
	PointOfContact string
	// A link to documentation around the service's functionality and uses
	DocumentationLink string
	// The environment in which the service is actively running and deployed in
	Environment string
	// license key for interactions with the new-relic platform
	NewRelicLicenseKey string
}

type ServiceMetadata

type ServiceMetadata struct {
	// Name is the service name
	Name string
	// The version of the service actively deployed
	Version string
	// The service P.O.
	PointOfContact string
	// A link to documentation around the service's functionality and uses
	DocumentationLink string
	// The environment in which the service is actively running and deployed in
	Environment string
}

ServiceMetadata outlines important pieces of information pertaining to the service the data points making up this object should further aid the on-call engineer to properly root cause any ambiguities tied to a ny metrics

type ServiceMetrics

type ServiceMetrics struct {
	// Tracks the number of request serviced by the service partitioned by name and status code
	RequestCountMetric *Metric

	// Tracks the latency associated with a various requests partitioned by service name, target name,
	// status code, and latency
	RequestLatencyMetric *Metric

	// Tracks the number of errors encountered by the service
	ErrorCountMetric *Metric

	// Tracks the status of all requests serviced by the service
	RequestStatusSummaryMetric *Metric

	// Tracks the number of db operations performed
	DbOperationCounter *Metric

	// Tracks the latency of various db operations
	DbOperationLatency *Metric

	// Tracks the number of grpc requests partitioned by name and status code
	// used for monitoring and alerting (RED method)
	GrpcRequestCounter *Metric

	// Tracks the latency associated with grpc requests partitioned by service name, target name,
	// status code, and latency
	GrpcRequestLatency *Metric
}

type ServiceTelemetry

type ServiceTelemetry interface {
	// ErrorCountUnaryServerInterceptor Create new unary server interceptor to capture number of errors.
	ErrorCountUnaryServerInterceptor() grpc.UnaryServerInterceptor
	// ErrorCountStreamServerInterceptor Create new stream server interceptor to capture error count over time.
	ErrorCountStreamServerInterceptor() grpc.StreamServerInterceptor
	// RequestLatencyUnaryServerInterceptor Create new unary server interceptor to capture request latency over time.
	RequestLatencyUnaryServerInterceptor() grpc.UnaryServerInterceptor
	// RequestLatencyStreamServerInterceptor Create new stream server interceptor to capture request latency over time.
	RequestLatencyStreamServerInterceptor() grpc.StreamServerInterceptor
	// RequestCountUnaryServerInterceptor Create new unary server interceptor to capture request count over time.
	RequestCountUnaryServerInterceptor() grpc.UnaryServerInterceptor
	// RequestCountStreamServerInterceptor Create new stream server interceptor to capture request count over time.
	RequestCountStreamServerInterceptor() grpc.StreamServerInterceptor
	// RequestTimeUnaryServerInterceptor Create new unary server interceptor to capture request time.
	RequestTimeUnaryServerInterceptor() grpc.UnaryServerInterceptor
	// RequestTimeStreamServerInterceptor Create new stream server interceptor to capture request time.
	RequestTimeStreamServerInterceptor() grpc.StreamServerInterceptor
	// TxnUnaryServerInterceptor Create new unary server interceptor to propagate the transaction across requests automatically.
	TxnUnaryServerInterceptor() grpc.UnaryServerInterceptor
	// TxnStreamServerInterceptor Create new stream server interceptor to propagate the transaction across requests automatically.
	TxnStreamServerInterceptor() grpc.StreamServerInterceptor
	// NewTransaction Create new transaction for the given service call
	NewTransaction(ctx context.Context, meta *TxMetadata) *newrelic.Transaction
	// New Segment Create new segment for the given service call
	NewSegment(txn *newrelic.Transaction, meta *TxMetadata) *newrelic.Segment
	// TxFromContext returns a transaction from the context if it exists, otherwise it creates a new transaction
	TxFromContext(ctx context.Context, meta *TxMetadata, sdk *newrelic.Application) *newrelic.Transaction
	// SpanName returns a formatted span name
	SpanName(meta *TxMetadata) string
	// TxName returns a formatted transaction name
	TxName(meta *TxMetadata) string
}

type Subsystem

type Subsystem string
const (
	GrpcSubSystem       Subsystem = "grpc.subsystem"
	ThirdPartySubSystem Subsystem = "thirdparty.subsystem"
	ErrorSubSystem      Subsystem = "error.subsystem"
	DbSubSystem         Subsystem = "database.subsystem"
)

type Summary

type Summary struct {
	Metric
}

Summary summarizes numerous facets of a metric

type Telemetry

type Telemetry struct {
	Engine *MetricsEngine
}

func New

func New(params *TelemetryParams) (*Telemetry, error)

func (*Telemetry) ErrorCountStreamServerInterceptor

func (c *Telemetry) ErrorCountStreamServerInterceptor() grpc.StreamServerInterceptor

ErrorCountStreamServerInterceptor Create new stream server interceptor to capture error count over time.

func (*Telemetry) ErrorCountUnaryServerInterceptor

func (c *Telemetry) ErrorCountUnaryServerInterceptor() grpc.UnaryServerInterceptor

ErrorCountUnaryServerInterceptor Create new unary server interceptor to capture number of errors.

func (Telemetry) NewSegment

func (t Telemetry) NewSegment(txn *newrelic.Transaction, meta *TxMetadata) *newrelic.Segment

NewSegment returns a new segment based on the provided metadata

func (Telemetry) NewTransaction

func (t Telemetry) NewTransaction(ctx context.Context, meta *TxMetadata) *newrelic.Transaction

NewTransaction returns a new transaction based on the provided metadata

func (*Telemetry) RequestCountStreamServerInterceptor

func (c *Telemetry) RequestCountStreamServerInterceptor() grpc.StreamServerInterceptor

RequestCountStreamServerInterceptor Create new stream server interceptor to capture the number of requests.

func (*Telemetry) RequestCountUnaryServerInterceptor

func (c *Telemetry) RequestCountUnaryServerInterceptor() grpc.UnaryServerInterceptor

RequestCountUnaryServerInterceptor Create new unary server interceptor to capture number of requests.

func (*Telemetry) RequestLatencyStreamServerInterceptor

func (c *Telemetry) RequestLatencyStreamServerInterceptor() grpc.StreamServerInterceptor

RequestLatencyStreamServerInterceptor Create new stream server interceptor to capture request latency.

func (*Telemetry) RequestLatencyUnaryServerInterceptor

func (c *Telemetry) RequestLatencyUnaryServerInterceptor() grpc.UnaryServerInterceptor

RequestLatencyUnaryServerInterceptor Create new unary server interceptor to capture request latency.

func (*Telemetry) RequestTimeStreamServerInterceptor

func (c *Telemetry) RequestTimeStreamServerInterceptor() grpc.StreamServerInterceptor

RequestTimeStreamServerInterceptor Create new stream server interceptor to capture the time of requests.

func (*Telemetry) RequestTimeUnaryServerInterceptor

func (c *Telemetry) RequestTimeUnaryServerInterceptor() grpc.UnaryServerInterceptor

RequestCountUnaryServerInterceptor Create new unary server interceptor to capture the time of requests.

func (Telemetry) SpanName

func (t Telemetry) SpanName(meta *TxMetadata) string

SpanName returns a formatted span name

func (Telemetry) TxFromContext

func (t Telemetry) TxFromContext(ctx context.Context, meta *TxMetadata, sdk *newrelic.Application) *newrelic.Transaction

TxFromContext returns a transaction from the context if it exists, otherwise it creates a new transaction

func (Telemetry) TxName

func (t Telemetry) TxName(meta *TxMetadata) string

TxName returns a formatted transaction name

func (*Telemetry) TxnStreamServerInterceptor

func (c *Telemetry) TxnStreamServerInterceptor() grpc.StreamServerInterceptor

TxnStreamServerInterceptor Create new stream server interceptor and passes txn via context.

func (*Telemetry) TxnUnaryServerInterceptor

func (c *Telemetry) TxnUnaryServerInterceptor() grpc.UnaryServerInterceptor

TxnUnaryServerInterceptor Create new unary server interceptor and passes txn via context.

type TelemetryParams

type TelemetryParams struct {
	ServiceName string
	// The version of the service actively deployed
	Version string
	// The service P.O.
	PointOfContact string
	// A link to documentation around the service's functionality and uses
	DocumentationLink string
	// The environment in which the service is actively running and deployed in
	Environment string
	// license key for interactions with the new-relic platform
	NewRelicLicenseKey string
	// logger instance used by the newrelic client
	Logger *zap.Logger
	// NewRelic telemetry client
	Client *newrelic.Application
	// Enable metric reporting
	Enabled bool
}

type TxMetadata

type TxMetadata struct {
	OperationName string
	OperationType operationType
	ServiceName   string
}

func (TxMetadata) Format

func (m TxMetadata) Format()

Format the metadata to ensure that the values are in the correct format

Jump to

Keyboard shortcuts

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