metrics

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedMetric

type AggregatedMetric struct {
	Name            string            `json:"name"`
	AggregationType string            `json:"aggregation_type"`
	Value           float64           `json:"value"`
	Labels          map[string]string `json:"labels"`
	BucketStart     time.Time         `json:"bucket_start"`
	BucketEnd       time.Time         `json:"bucket_end"`
	BucketSize      time.Duration     `json:"bucket_size" swaggertype:"integer"`
}

type AssetBreakdown

type AssetBreakdown struct {
	Type      string `json:"type"`
	Provider  string `json:"provider"`
	HasSchema bool   `json:"has_schema"`
	Owner     string `json:"owner"`
	Count     int64  `json:"count"`
}

type AssetCount

type AssetCount struct {
	AssetID       string `json:"asset_id"`
	AssetType     string `json:"asset_type"`
	AssetName     string `json:"asset_name"`
	AssetProvider string `json:"asset_provider"`
	Count         int64  `json:"count"`
}

type Collector

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

func NewCollector

func NewCollector(store Store) *Collector

func (*Collector) RecordAssetView

func (c *Collector) RecordAssetView(assetID, assetType, assetName, assetProvider string)

func (*Collector) RecordDBQuery

func (c *Collector) RecordDBQuery(operation string, duration time.Duration, success bool)

func (*Collector) RecordHTTPDuration

func (c *Collector) RecordHTTPDuration(method, path string, duration time.Duration)

func (*Collector) RecordHTTPRequest

func (c *Collector) RecordHTTPRequest(method, path, status string)

func (*Collector) RecordSearchQuery

func (c *Collector) RecordSearchQuery(queryType, query string)

func (*Collector) SetDBConnections

func (c *Collector) SetDBConnections(count int)

func (*Collector) StartAsyncRecording added in v0.6.0

func (c *Collector) StartAsyncRecording()

StartAsyncRecording starts the background worker for async metric recording

func (*Collector) StopAsyncRecording added in v0.6.0

func (c *Collector) StopAsyncRecording()

StopAsyncRecording stops the background worker and flushes remaining metrics

func (*Collector) UpdateAssetMetrics

func (c *Collector) UpdateAssetMetrics(breakdown []AssetBreakdown)

type Metric

type Metric struct {
	Name      string            `json:"name"`
	Type      MetricType        `json:"type"`
	Value     float64           `json:"value"`
	Labels    map[string]string `json:"labels"`
	Timestamp time.Time         `json:"timestamp"`
}

type MetricType

type MetricType string
const (
	Counter   MetricType = "counter"
	Gauge     MetricType = "gauge"
	Histogram MetricType = "histogram"
)

type PostgresStore

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

func (*PostgresStore) CreatePartition

func (s *PostgresStore) CreatePartition(ctx context.Context, date time.Time) error

CreatePartition creates a partition for the given date.

func (*PostgresStore) DeleteOldMetrics

func (s *PostgresStore) DeleteOldMetrics(ctx context.Context, olderThan time.Time) error

DeleteOldMetrics drops partitions older than the cutoff date.

func (*PostgresStore) GetAggregatedMetrics

func (s *PostgresStore) GetAggregatedMetrics(ctx context.Context, opts QueryOptions) ([]AggregatedMetric, error)

GetAggregatedMetrics returns aggregated metrics using pre-computed values.

func (*PostgresStore) GetAssetBreakdown

func (s *PostgresStore) GetAssetBreakdown(ctx context.Context) ([]AssetBreakdown, error)

func (*PostgresStore) GetAssetsByOwner

func (s *PostgresStore) GetAssetsByOwner(ctx context.Context, ownerFields []string) (map[string]int64, error)

func (*PostgresStore) GetAssetsByProvider

func (s *PostgresStore) GetAssetsByProvider(ctx context.Context) (map[string]int64, error)

func (*PostgresStore) GetAssetsByType

func (s *PostgresStore) GetAssetsByType(ctx context.Context) (map[string]int64, error)

func (*PostgresStore) GetAssetsWithSchemas

func (s *PostgresStore) GetAssetsWithSchemas(ctx context.Context) (int64, error)

func (*PostgresStore) GetMetrics

func (s *PostgresStore) GetMetrics(ctx context.Context, opts QueryOptions) ([]Metric, error)

GetMetrics returns raw metric data points by unnesting arrays.

func (*PostgresStore) GetTopAssets

func (s *PostgresStore) GetTopAssets(ctx context.Context, timeRange TimeRange, limit int) ([]AssetCount, error)

GetTopAssets returns the most viewed assets.

func (*PostgresStore) GetTopQueries

func (s *PostgresStore) GetTopQueries(ctx context.Context, timeRange TimeRange, limit int) ([]QueryCount, error)

GetTopQueries returns the most frequent search queries.

func (*PostgresStore) GetTotalAssets

func (s *PostgresStore) GetTotalAssets(ctx context.Context) (int64, error)

func (*PostgresStore) GetTotalAssetsFiltered

func (s *PostgresStore) GetTotalAssetsFiltered(ctx context.Context, excludedTypes []string, excludedProviders []string) (int64, error)

func (*PostgresStore) RecordMetric

func (s *PostgresStore) RecordMetric(ctx context.Context, metric Metric) error

func (*PostgresStore) RecordMetrics

func (s *PostgresStore) RecordMetrics(ctx context.Context, metrics []Metric) error

RecordMetrics appends metrics to the array-based timeseries table. Groups metrics by (name, labels, hour) and performs batch upserts. Deadlocks are handled gracefully since metrics are best-effort.

func (*PostgresStore) RefreshAssetStatistics added in v0.6.0

func (s *PostgresStore) RefreshAssetStatistics(ctx context.Context, ownerFields []string) error

RefreshAssetStatistics updates the pre-computed asset statistics table.

func (*PostgresStore) RefreshMetadataValueCounts added in v0.6.0

func (s *PostgresStore) RefreshMetadataValueCounts(ctx context.Context) error

RefreshMetadataValueCounts refreshes the materialized view for metadata autocomplete.

type QueryCount

type QueryCount struct {
	Query     string `json:"query"`
	QueryType string `json:"query_type"`
	Count     int64  `json:"count"`
}

type QueryOptions

type QueryOptions struct {
	TimeRange       TimeRange         `json:"time_range"`
	MetricNames     []string          `json:"metric_names"`
	Labels          map[string]string `json:"labels"`
	AggregationType string            `json:"aggregation_type"`
	BucketSize      time.Duration     `json:"bucket_size" swaggertype:"integer"`
}

type Recorder

type Recorder interface {
	RecordSearchQuery(ctx context.Context, queryType, query string)
	RecordAssetView(ctx context.Context, assetID, assetType, assetName, assetProvider string)
	RecordDBQuery(ctx context.Context, operation string, duration time.Duration, success bool)
	WrapDBQuery(ctx context.Context, operation string, fn func() error) error
	RecordCustomMetrics(ctx context.Context, metrics []Metric) error
}

func NewRecorder

func NewRecorder(collector *Collector) Recorder

type Service

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

func NewService

func NewService(store Store, db *pgxpool.Pool) *Service

func (*Service) Collector

func (s *Service) Collector() *Collector

func (*Service) GetAssetsByOwner

func (s *Service) GetAssetsByOwner(ctx context.Context, ownerFields []string) (map[string]int64, error)

func (*Service) GetAssetsByProvider

func (s *Service) GetAssetsByProvider(ctx context.Context) (map[string]int64, error)

func (*Service) GetAssetsByType

func (s *Service) GetAssetsByType(ctx context.Context) (map[string]int64, error)

func (*Service) GetAssetsWithSchemas

func (s *Service) GetAssetsWithSchemas(ctx context.Context) (int64, error)

func (*Service) GetMetrics

func (s *Service) GetMetrics(ctx context.Context, opts QueryOptions) ([]AggregatedMetric, error)

func (*Service) GetRecorder

func (s *Service) GetRecorder() Recorder

func (*Service) GetTopAssets

func (s *Service) GetTopAssets(ctx context.Context, timeRange TimeRange, limit int) ([]AssetCount, error)

func (*Service) GetTopQueries

func (s *Service) GetTopQueries(ctx context.Context, timeRange TimeRange, limit int) ([]QueryCount, error)

func (*Service) GetTotalAssets

func (s *Service) GetTotalAssets(ctx context.Context) (int64, error)

func (*Service) GetTotalAssetsFiltered

func (s *Service) GetTotalAssetsFiltered(ctx context.Context, excludedTypes []string, excludedProviders []string) (int64, error)

func (*Service) SetOwnerFields added in v0.6.0

func (s *Service) SetOwnerFields(fields []string)

SetOwnerFields configures which metadata fields to use for owner statistics.

func (*Service) Start

func (s *Service) Start(ctx context.Context)

func (*Service) Stop

func (s *Service) Stop()

type Store

type Store interface {
	RecordMetric(ctx context.Context, metric Metric) error
	RecordMetrics(ctx context.Context, metrics []Metric) error

	GetMetrics(ctx context.Context, opts QueryOptions) ([]Metric, error)
	GetAggregatedMetrics(ctx context.Context, opts QueryOptions) ([]AggregatedMetric, error)

	GetTopQueries(ctx context.Context, timeRange TimeRange, limit int) ([]QueryCount, error)
	GetTopAssets(ctx context.Context, timeRange TimeRange, limit int) ([]AssetCount, error)

	// Asset statistics (from pre-computed table)
	GetTotalAssets(ctx context.Context) (int64, error)
	GetTotalAssetsFiltered(ctx context.Context, excludedTypes []string, excludedProviders []string) (int64, error)
	GetAssetsByType(ctx context.Context) (map[string]int64, error)
	GetAssetsByProvider(ctx context.Context) (map[string]int64, error)
	GetAssetsWithSchemas(ctx context.Context) (int64, error)
	GetAssetsByOwner(ctx context.Context, ownerFields []string) (map[string]int64, error)
	GetAssetBreakdown(ctx context.Context) ([]AssetBreakdown, error)

	// Maintenance
	RefreshAssetStatistics(ctx context.Context, ownerFields []string) error
	RefreshMetadataValueCounts(ctx context.Context) error
	CreatePartition(ctx context.Context, date time.Time) error
	DeleteOldMetrics(ctx context.Context, olderThan time.Time) error
}

func NewPostgresStore

func NewPostgresStore(db *pgxpool.Pool) Store

type TimeRange

type TimeRange struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

Jump to

Keyboard shortcuts

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