provider.go
provider.go - Overview
This file defines a Prometheus provider that uses ClickHouse as the storage backend. It implements the prometheus.Prometheus
interface and provides functionality for querying and storing Prometheus metrics in ClickHouse.
Detailed Documentation
stCallback
var stCallback = func() (int64, error) {
return int64(model.Latest), nil
}
- Purpose: This variable defines a callback function that returns the latest timestamp.
- Returns:
int64
: The latest timestamp, represented as anint64
.error
: Returnsnil
always
type provider struct
type provider struct {
settings factory.ScopedProviderSettings
telemetryStore telemetrystore.TelemetryStore
engine *prometheus.Engine
queryable storage.SampleAndChunkQueryable
}
- Purpose: Defines the
provider
struct, which implements theprometheus.Prometheus
interface using ClickHouse. - Members:
settings
:factory.ScopedProviderSettings
- Provider-specific settings.telemetryStore
:telemetrystore.TelemetryStore
- Telemetry storage interface.engine
:*prometheus.Engine
- Prometheus query engine.queryable
:storage.SampleAndChunkQueryable
- Interface for querying sample and chunk data.
NewFactory
func NewFactory(telemetryStore telemetrystore.TelemetryStore) factory.ProviderFactory[prometheus.Prometheus, prometheus.Config] {
return factory.NewProviderFactory(factory.MustNewName("clickhouse"), func(ctx context.Context, providerSettings factory.ProviderSettings, config prometheus.Config) (prometheus.Prometheus, error) {
return New(ctx, providerSettings, config, telemetryStore)
})
}
- Purpose: Creates a new
ProviderFactory
for the ClickHouse Prometheus provider. - Parameters:
telemetryStore
:telemetrystore.TelemetryStore
- The telemetry store to use.
- Returns:
factory.ProviderFactory[prometheus.Prometheus, prometheus.Config]
: A newProviderFactory
instance.
New
func New(ctx context.Context, providerSettings factory.ProviderSettings, config prometheus.Config, telemetryStore telemetrystore.TelemetryStore) (prometheus.Prometheus, error) {
settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/prometheus/clickhouseprometheus")
readClient := NewReadClient(settings, telemetryStore)
return &provider{
settings: settings,
telemetryStore: telemetryStore,
engine: prometheus.NewEngine(settings.Logger(), config),
queryable: remote.NewSampleAndChunkQueryableClient(readClient, labels.EmptyLabels(), []*labels.Matcher{}, false, stCallback),
}, nil
}
- Purpose: Creates a new ClickHouse Prometheus provider.
- Parameters:
ctx
:context.Context
- The context.providerSettings
:factory.ProviderSettings
- The provider settings.config
:prometheus.Config
- The Prometheus configuration.telemetryStore
:telemetrystore.TelemetryStore
- The telemetry store to use.
- Returns:
prometheus.Prometheus
: A newprometheus.Prometheus
instance.error
: An error if the provider could not be created.
Engine
func (provider *provider) Engine() *prometheus.Engine {
return provider.engine
}
- Purpose: Returns the Prometheus engine.
- Parameters:
provider
:*provider
- The provider instance.
- Returns:
*prometheus.Engine
: The Prometheus engine.
Storage
func (provider *provider) Storage() storage.Queryable {
return provider
}
- Purpose: Returns the storage queryable.
- Parameters:
provider
:*provider
- The provider instance.
- Returns:
storage.Queryable
: The storage queryable.
Querier
func (provider *provider) Querier(mint, maxt int64) (storage.Querier, error) {
querier, err := provider.queryable.Querier(mint, maxt)
if err != nil {
return nil, err
}
return storage.NewMergeQuerier(nil, []storage.Querier{querier}, storage.ChainedSeriesMerge), nil
}
- Purpose: Creates a new Querier.
- Parameters:
mint
:int64
- The minimum timestamp.maxt
:int64
- The maximum timestamp.provider
:*provider
- The provider instance.
- Returns:
storage.Querier
: A newstorage.Querier
instance.error
: An error if the querier could not be created.
Code Examples
None
Include in Getting Started: NO