common

package
v0.0.0-...-44e4a4a Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RandomProjectID   string = "12345"
	RandomNamespaceID string = "123"
	RandomServiceName string = "test-service"
	RandomMetricName  string = "random-metric-name"
)
View Source
const LogBodyMaxPrefixSize = 128

Variables

View Source
var (
	RandomTraceID = [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}
	RandomSpanID  = [8]byte{0, 0, 0, 0, 1, 2, 3, 4}
)
View Source
var ErrUnknownProjectID = errors.New("unknown project ID")

Functions

func DecodePage

func DecodePage[T pageType](rawCursor string) (*T, error)

func EncodePage

func EncodePage[T pageType](p *T) (string, error)

func GenerateOTELExponentialHistogramMetrics

func GenerateOTELExponentialHistogramMetrics(attributes map[string]string) pmetric.Metrics

func GenerateOTELGaugeMetrics

func GenerateOTELGaugeMetrics(attributes map[string]string, value float64) pmetric.Metrics

func GenerateOTELHistogramMetrics

func GenerateOTELHistogramMetrics(
	attributes map[string]string,
	startTimestamp time.Time,
	timestamp time.Time,
	explicitBounds []float64,
	bucketCounts []uint64,
) pmetric.Metrics

func GenerateOTELMetrics

func GenerateOTELMetrics(
	mtype pmetric.MetricType,
	attributes map[string]string,
	value float64,
) pmetric.Metrics

func GenerateOTELSumMetrics

func GenerateOTELSumMetrics(
	attributes map[string]string,
	startTimestamp time.Time,
	timestamp time.Time,
	value float64,
) pmetric.Metrics

func GetProjectIDFromRequest

func GetProjectIDFromRequest(ctx *gin.Context) (string, error)

GetProjectIDFromRequest retrieves the project ID from the request context.

It prioritizes the header value over the path parameter to satisfy both v3 and v4 versions of the query API. Returns the project ID as a string.

func PersistOTELMetrics

func PersistOTELMetrics(
	ctx context.Context,
	db clickhouse.Conn,
	logger *zap.Logger,
	md pmetric.Metrics,
	ingestionTimestamp time.Time,
) error

Types

type LogsPage

type LogsPage struct {
	LastSeenTimestamp   string `json:"last_seen_timestamp,omitempty"`
	LastSeenTraceID     string `json:"trace_id" ch:"TraceId"`
	LastSeenSpanID      string `json:"span_id" ch:"SpanId"`
	LastSeenServiceName string `json:"service_name"`
	// We can't really put the whole body into the URL, but OTOH some logs may
	// different by only the logs body. A compro
	LastSeenBodyPrefix string `json:"body"`
}

LogsPage holds the details of the page token needed for the next page.

Requests for the next page should include this cursor in the page token parameter. Even though we use nanosecond precision internally, we still need to account for other fields when accurately determining last entry on the given page, as some tooling may simply round the timestamp to the closests second (or simply have 1-second precision in the first place), resulting in multiple log entries having the same timestamp.

These fields do not 100% guarantee that we will not display a log entry twice (i.e. on previous page and then on the next), but should greatly reduce the risk.

Fields below belong to the index CH is using.

Jump to

Keyboard shortcuts

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