metrics

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: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggregationInterval1m = "1m" // minutely
	AggregationInterval1h = "1h" // hourly
	AggregationInterval1d = "1d" // daily
)
View Source
const (
	GroupByAttributesAll    string = "*"
	GroupByAttributesBucket string = "bucket"
)
View Source
const (
	RandomProjectID   string = "12345"
	RandomNamespaceID string = "123"
	RandomServiceName string = "test-service"
	RandomMetricName  string = "random-metric-name"
)
View Source
const (
	GroupingOverAttributes int = iota
	GroupingOverMetricName
	GroupingOverNone
)

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}
)

Functions

func GenerateRandomFloat64

func GenerateRandomFloat64(min, max float64) float64

Generate a random float64 value within the range [min .. max)

func GenerateRandomTimestamps

func GenerateRandomTimestamps(
	aggregation AggregateBucket,
	endTimestamp, targetTime time.Time,
	numTimestamps int,
) []time.Time

GenerateRandomTimestamps generates a slice of random timestamps within the given minute

Types

type AggregateBucket

type AggregateBucket string
const (
	Raw      AggregateBucket = "main"
	Secondly AggregateBucket = "1s"
	Minutely AggregateBucket = "1m"
	Hourly   AggregateBucket = "1h"
	Daily    AggregateBucket = "1d"
)

type AggregateFunction

type AggregateFunction string
const (
	AggregateFunctionUnknown AggregateFunction = "unknown"
	AggregateFunctionLast    AggregateFunction = "last"
	AggregateFunctionSum     AggregateFunction = "sum"
	AggregateFunctionAvg     AggregateFunction = "avg"
	AggregateFunctionMin     AggregateFunction = "min"
	AggregateFunctionMax     AggregateFunction = "max"
	AggregateFunctionCount   AggregateFunction = "count"
	AggregateFunctionP50     AggregateFunction = "p50"
	AggregateFunctionP75     AggregateFunction = "p75"
	AggregateFunctionP90     AggregateFunction = "p90"
	AggregateFunctionP95     AggregateFunction = "p95"
	AggregateFunctionP99     AggregateFunction = "p99"
)

func GetAggregationFunctionFromString

func GetAggregationFunctionFromString(fn string) AggregateFunction

type AggregationInterval

type AggregationInterval string

type ByMetricName

type ByMetricName []MetricName

func (ByMetricName) Len

func (s ByMetricName) Len() int

func (ByMetricName) Less

func (s ByMetricName) Less(i, j int) bool

func (ByMetricName) Swap

func (s ByMetricName) Swap(i, j int)

type CounterMetricsResponse

type CounterMetricsResponse struct {
	StartTimestamp int64       `json:"start_ts"`
	EndTimestamp   int64       `json:"end_ts"`
	Results        []QueryData `json:"results"`
}

type DataGenerator

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

func NewDataGenerator

func NewDataGenerator(db clickhouse.Conn, logger *zap.Logger) *DataGenerator

func (*DataGenerator) GenerateMetrics

func (d *DataGenerator) GenerateMetrics(
	ctx context.Context,
	startTimestamp time.Time,
	endTimestamp time.Time,
	ingestionTimestamp time.Time,
	opts metricOptions,
) error

func (*DataGenerator) RawData

func (d *DataGenerator) RawData() []GeneratedRawData

func (*DataGenerator) RawDataAggregated

func (d *DataGenerator) RawDataAggregated(q *Query) []GeneratedTimeseries

type Filter

type Filter struct {
	Key      string
	Value    string
	Operator string
}

type FilterOp

type FilterOp string
const (
	FilterOpNoOp         FilterOp = "noop"
	FilterOpEqual        FilterOp = "eq"
	FilterOpNotEqual     FilterOp = "neq"
	FilterOpLike         FilterOp = "re"
	FilterOpNotLike      FilterOp = "nre"
	FilterOpHasAttribute FilterOp = "hasAttr"
)

type GaugeMetricsResponse

type GaugeMetricsResponse struct {
	StartTimestamp int64       `json:"start_ts"`
	EndTimestamp   int64       `json:"end_ts"`
	Results        []QueryData `json:"results"`
}

type GaugeRow

type GaugeRow struct {
	MetricName        string            `ch:"MetricName"`
	MetricDescription string            `ch:"MetricDescription"`
	MetricUnit        string            `ch:"MetricUnit"`
	Fingerprint       string            `ch:"Fingerprint"`
	Attributes        map[string]string `ch:"FilteredAttributes"`
	Values            []float64         `ch:"Values"`
	LastValues        []float64         `ch:"LastValues"`
	Times             []time.Time       `ch:"Times"`
}

type GeneratedRawData

type GeneratedRawData struct {
	AggTimeUnix        time.Time
	TimeUnix           time.Time
	MetricName         string
	MetricDescription  string
	MetricUnit         string
	Attributes         map[string]string
	FilteredAttributes map[string]string
	Fingerprint        string
	Value              float64
	AggTemp            pmetric.AggregationTemporality
}

type GeneratedTimeseries

type GeneratedTimeseries struct {
	Fingerprint string
	Attributes  map[string]string
	Data        map[time.Time][]GeneratedRawData
	GroupBy     GroupBy
}

type GeneratedTimestamp

type GeneratedTimestamp struct {
	Pivot     time.Time
	Generated []time.Time
}

func GenerateTimestampsAggregatedPerDay

func GenerateTimestampsAggregatedPerDay(startTimestamp, endTimestamp time.Time, count int) []GeneratedTimestamp

GenerateTimestampsAggregatedPerDay generates a slice of "count" random timestamps grouped per day within a given time-interval: [start, end].

func GenerateTimestampsAggregatedPerHour

func GenerateTimestampsAggregatedPerHour(startTimestamp, endTimestamp time.Time, count int) []GeneratedTimestamp

GenerateTimestampsAggregatedPerHour generates a slice of "count" random timestamps grouped per hour within a given time-interval: [start, end].

func GenerateTimestampsAggregatedPerMinute

func GenerateTimestampsAggregatedPerMinute(startTimestamp, endTimestamp time.Time, count int) []GeneratedTimestamp

GenerateTimestampsAggregatedPerMinute generates a slice of "count" random timestamps grouped per minute within a given time-interval: [start, end].

func GenerateTimestampsAggregatedPerSecond

func GenerateTimestampsAggregatedPerSecond(startTimestamp, endTimestamp time.Time, count int) []GeneratedTimestamp

GenerateTimestampsAggregatedPerSecond generates a slice of "count" random timestamps grouped per second within a given time-interval: [start, end].

type GroupBy

type GroupBy struct {
	Attributes []string          `json:"attribute"`
	Function   AggregateFunction `json:"function"`
}

type HistogramDistributionData

type HistogramDistributionData struct {
	MetricName        string                  `json:"name"`
	MetricDescription string                  `json:"description"`
	MetricUnit        string                  `json:"unit"`
	MetricType        string                  `json:"type"`
	Fingerprint       string                  `json:"fingerprint"`
	Data              []PerBucketDistribution `json:"data"`
}

type HistogramDistributionResponse

type HistogramDistributionResponse struct {
	StartTimestamp int64                       `json:"start_ts"`
	EndTimestamp   int64                       `json:"end_ts"`
	Results        []HistogramDistributionData `json:"results"`
}

type HistogramDistributionRow

type HistogramDistributionRow struct {
	ProjectID         string    `ch:"ProjectId"`
	MetricName        string    `ch:"MetricName"`
	MetricDescription string    `ch:"MetricDescription"`
	MetricUnit        string    `ch:"MetricUnit"`
	Fingerprint       string    `ch:"Fingerprint"`
	StartTimeUnix     time.Time `ch:"StartTimeUnix"`
	AggTimeUnix       time.Time `ch:"AggTimeUnix"`
	AggTemp           int32     `ch:"AggTemp"`
	Min               float64   `ch:"Min"`
	Max               float64   `ch:"Max"`
	Count             uint64    `ch:"Count"`
	Sum               float64   `ch:"Sum"`
	Bounds            []float64 `ch:"Bounds"`
	BoundsHash        uint64    `ch:"BoundsHash"`
	SamplesCount      uint64    `ch:"SamplesCount"`
	Delta             []uint64  `ch:"Delta"`
	Cumulative        []uint64  `ch:"Cumulative"`
}

type HistogramMetricRow

type HistogramMetricRow struct {
	MetricName        string            `ch:"MetricName"`
	MetricDescription string            `ch:"MetricDescription"`
	MetricUnit        string            `ch:"MetricUnit"`
	Fingerprint       string            `ch:"Fingerprint"`
	Attributes        map[string]string `ch:"Attributes"`
	Values            []float64         `ch:"Values"`
	Times             []time.Time       `ch:"Times"`
}

type MetricAttributesGetFn

type MetricAttributesGetFn func(context.Context) (map[string]interface{}, error)

type MetricAttributesRow

type MetricAttributesRow struct {
	ProjectID  string   `ch:"ProjectId"`
	Name       string   `ch:"MetricName"`
	Attributes []string `ch:"Attributes"`
}

type MetricName

type MetricName struct {
	Name           string   `json:"name"`
	Description    string   `json:"description"`
	Attributes     []string `json:"attributes"`
	Type           string   `json:"type"`
	LastIngestedAt int64    `json:"last_ingested_at"`
}

type MetricNameFilters

type MetricNameFilters struct {
	ProjectID  string
	StartsWith string   `form:"starts_with"`
	Search     string   `form:"search"`
	Limit      int      `form:"limit" binding:"numeric"`
	Attributes []string `form:"attributes"`
}

type MetricNameGetFn

type MetricNameGetFn func(context.Context) ([]MetricName, error)

type MetricNameResponse

type MetricNameResponse struct {
	Metrics    []MetricName `json:"metrics"`
	Attributes []string     `json:"all_available_attributes"`
}

type MetricNameRow

type MetricNameRow struct {
	ProjectID      string    `ch:"ProjectId"`
	Name           string    `ch:"MetricName"`
	Description    string    `ch:"MetricDescription"`
	Attributes     []string  `ch:"Attributes"`
	LastIngestedAt time.Time `ch:"LastIngestedAt"`
}

type MetricRow

type MetricRow struct {
	MetricName        string            `ch:"MetricName"`
	MetricDescription string            `ch:"MetricDescription"`
	MetricUnit        string            `ch:"MetricUnit"`
	Fingerprint       string            `ch:"Fingerprint"`
	Attributes        map[string]string `ch:"FilteredAttributes"`
	Values            []float64         `ch:"Values"`
	Times             []time.Time       `ch:"Times"`
}

type MetricSearchMetadataResponse

type MetricSearchMetadataResponse struct {
	MetricName               string   `json:"name"`
	MetricType               string   `json:"type"`
	MetricDescription        string   `json:"description"`
	AttributeKeys            []string `json:"attribute_keys"`
	LastIngestedAt           int64    `json:"last_ingested_at"`
	SupportedAggregations    []string `json:"supported_aggregations"`
	SupportedFunctions       []string `json:"supported_functions"`
	DefaultGroupByAttributes []string `json:"default_group_by_attributes"`
	DefaultGroupByFunction   string   `json:"default_group_by_function"`
}

type MetricSearchMetadataRow

type MetricSearchMetadataRow struct {
	MetricName        string    `ch:"MetricName"`
	MetricDescription string    `ch:"MetricDescription"`
	AttributeKeys     []string  `ch:"AttributeKeys"`
	LastIngestedAt    time.Time `ch:"LastIngestedAt"`
}

type MetricsResponse

type MetricsResponse struct {
	StartTimestamp int64 `json:"start_ts"`
	EndTimestamp   int64 `json:"end_ts"`

	Results []QueryData `json:"results"`
}

type MockQuerier

type MockQuerier struct{}

func (*MockQuerier) GetMetricNames

func (*MockQuerier) GetMetrics

func (*MockQuerier) GetMetrics(_ context.Context, _ *QueryContext) (interface{}, error)

func (*MockQuerier) GetSearchMetadata

func (*MockQuerier) GetSearchMetadata(_ context.Context, _ *QueryContext) (interface{}, error)

type PerBucketDistribution

type PerBucketDistribution struct {
	BucketsHash  uint64         `json:"bucketsHash"`
	Buckets      []string       `json:"buckets"`
	Distribution [][]QueryPoint `json:"distribution"`
}

type Querier

type Querier interface {
	GetMetricNames(context.Context, *MetricNameFilters) (*MetricNameResponse, error)
	GetMetrics(context.Context, *QueryContext) (interface{}, error)
	GetSearchMetadata(context.Context, *QueryContext) (interface{}, error)
}

func NewQuerier

func NewQuerier(
	clickHouseDSN string,
	clickHouseCloudDSN string,
	opts *clickhouse.Options,
	logger *zap.Logger,
) (Querier, error)

type Query

type Query struct {
	TargetMetric string   `json:"mname"`
	TargetType   string   `json:"mtype"`
	TargetVisual string   `json:"mvisual"`
	Filters      []Filter `json:"filters"`
	GroupBy      GroupBy  `json:"groupby"`
}

func (*Query) GetGroupingType

func (q *Query) GetGroupingType() int

type QueryContext

type QueryContext struct {
	ProjectID string `json:"project_id"`

	Queries    map[string]*Query `json:"queries,omitempty"`
	Expression string            `json:"expression,omitempty"`

	StartTimestamp time.Time `json:"start_time"`
	EndTimestamp   time.Time `json:"end_time"`
}

type QueryData

type QueryData struct {
	MetricName        string            `json:"name"`
	MetricDescription string            `json:"description"`
	MetricUnit        string            `json:"unit"`
	MetricType        string            `json:"type"`
	Attributes        map[string]string `json:"attributes"`
	Values            []QueryPoint      `json:"values,omitempty"`
}

type QueryPoint

type QueryPoint [2]string // time, value

type SumMetricsResponse

type SumMetricsResponse struct {
	StartTimestamp int64       `json:"start_ts"`
	EndTimestamp   int64       `json:"end_ts"`
	Results        []QueryData `json:"results"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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