metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPMiddleware

func HTTPMiddleware(next http.Handler) http.Handler

HTTPMiddleware is middleware that records HTTP metrics.

func Handler

func Handler() http.Handler

Handler returns the Prometheus metrics handler.

func RecordBranchesIndexed

func RecordBranchesIndexed(branchCount int, success bool)

RecordBranchesIndexed records branch indexing metrics.

func RecordCodeHostRequest

func RecordCodeHostRequest(hostType, endpoint string, duration time.Duration, success bool)

RecordCodeHostRequest records code host API metrics.

func RecordError

func RecordError(category, errorType string)

RecordError records an error by category and type.

func RecordGitClone

func RecordGitClone(duration time.Duration, success bool)

RecordGitClone records git clone operation metrics.

func RecordGitFetch

func RecordGitFetch(duration time.Duration, success bool)

RecordGitFetch records git fetch operation metrics.

func RecordIndexFailure

func RecordIndexFailure(reason string)

RecordIndexFailure records an index failure with categorized reason. Reasons: oom_killed, timeout, git_error, zoekt_error, unknown.

func RecordJob

func RecordJob(jobType string, duration time.Duration, success bool)

RecordJob records job processing metrics.

func RecordOrphanedActiveMarkerRecovered

func RecordOrphanedActiveMarkerRecovered()

RecordOrphanedActiveMarkerRecovered increments the counter when an orphaned active marker is cleaned up.

func RecordRateLimit

func RecordRateLimit(allowed bool)

RecordRateLimit records rate limiting metrics.

func RecordReplace

func RecordReplace(filesModified int, success bool)

RecordReplace records replace operation metrics.

func RecordRepoIndex

func RecordRepoIndex(duration time.Duration, success bool)

RecordRepoIndex records repository indexing metrics.

func RecordRepoSize

func RecordRepoSize(sizeBytes int64, success bool)

RecordRepoSize records repository size before indexing.

func RecordRepoSync

func RecordRepoSync(duration time.Duration, success bool)

RecordRepoSync records repository sync metrics.

func RecordSearch

func RecordSearch(searchType string, duration time.Duration, resultCount int)

RecordSearch records search metrics.

func SetActiveIndexRepos

func SetActiveIndexRepos(count int)

SetActiveIndexRepos sets the number of repos currently in the active index set.

func SetCodeHostRateLimit

func SetCodeHostRateLimit(hostType string, remaining int, resetTime time.Time)

SetCodeHostRateLimit sets the code host rate limit gauges.

func SetConnectionCounts

func SetConnectionCounts(counts map[string]int)

SetConnectionCounts sets the connection count gauges.

func SetDBConnections

func SetDBConnections(open, inUse int)

SetDBConnections sets the database connection gauges.

func SetJobQueueCounts

func SetJobQueueCounts(counts map[string]int)

SetJobQueueCounts sets the job queue count gauges.

func SetOrphanedTempFiles

func SetOrphanedTempFiles(count int)

SetOrphanedTempFiles sets the current count of orphaned .tmp files.

func SetRateLimitBuckets

func SetRateLimitBuckets(count int)

SetRateLimitBuckets sets the number of active rate limit buckets.

func SetRedisConnections

func SetRedisConnections(open int)

SetRedisConnections sets the Redis connection gauge.

func SetRepositoryCounts

func SetRepositoryCounts(counts map[string]int)

SetRepositoryCounts sets the repository count gauges.

func SetStuckIndexJobs

func SetStuckIndexJobs(duration string, count int)

SetStuckIndexJobs sets the count of repos stuck in indexing state by duration.

func SetZoektStats

func SetZoektStats(shards int, indexSizeBytes int64)

SetZoektStats sets the Zoekt stats gauges.

Types

type Collector

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

Collector periodically collects infrastructure metrics.

func NewCollector

func NewCollector(
	db DBPool,
	redis *redis.Client,
	indexPath string,
	interval time.Duration,
) *Collector

NewCollector creates a new metrics collector. Pass nil for any component that's not available.

func (*Collector) Start

func (c *Collector) Start(ctx context.Context)

Start begins collecting metrics at the configured interval.

func (*Collector) Stop

func (c *Collector) Stop()

Stop stops the collector.

type DBPool

type DBPool interface {
	Stats() PoolStats
	Query(ctx context.Context, sql string, args ...any) (Rows, error)
}

DBPool is an interface for database pools that provide stats and query capabilities. This matches the db.Pool interface from internal/db.

type DBPoolAdapter

type DBPoolAdapter struct {
	StatsFunc func() PoolStats
	QueryFunc func(ctx context.Context, sql string, args ...any) (Rows, error)
}

DBPoolAdapter wraps a database pool to satisfy the DBPool interface.

func (*DBPoolAdapter) Query

func (a *DBPoolAdapter) Query(ctx context.Context, sql string, args ...any) (Rows, error)

Query executes a query.

func (*DBPoolAdapter) Stats

func (a *DBPoolAdapter) Stats() PoolStats

Stats returns pool statistics.

type PoolStats

type PoolStats struct {
	MaxOpenConnections int
	OpenConnections    int
	InUse              int
	Idle               int
}

PoolStats contains connection pool statistics. This matches db.PoolStats from internal/db.

type Rows

type Rows interface {
	Next() bool
	Scan(dest ...any) error
	Close()
	Err() error
}

Rows is an interface for query results. This matches db.Rows from internal/db.

Jump to

Keyboard shortcuts

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