mirror of
https://github.com/hanzoai/otel-collector.git
synced 2026-11-02 13:34:59 +00:00
- imports: ClickHouse/ch-go, clickhouse-go/v2, srikanthccv/ClickHouse-go-mock
-> github.com/hanzo-ds/{native,go,mock} (require, clean semver, NO replace)
- identifiers/aliases/type-names/config-keys/type-IDs: clickhouse -> datastore
(receiver dir clickhousesystemtablesreceiver -> datastoresystemtablesreceiver)
- DSN scheme clickhouse:// -> datastore:// (driver treats non-http/https as Native)
- removed the go.opencensus.io version-pin replace (require-pinned instead)
- kept: real external refs (github.com/ClickHouse, clickhouse.com docs) and the
hanzo-ds/mock test API (NewClickHouseNative) pending the mock's own rename
Full ./... build passes. 0 replace directives, 0 signoz.
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package datastoresystemtablesreceiver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzo-ds/go/lib/driver"
|
|
)
|
|
|
|
// Used by the receiver for working with datastore.
|
|
// Helps mock things for tests
|
|
type datastoreQuerier interface {
|
|
// Scrape query_log table for rows with minEventTs <= event_time < maxEventTs
|
|
scrapeQueryLog(
|
|
ctx context.Context, minEventTs uint32, maxEventTs uint32,
|
|
) ([]QueryLog, error)
|
|
|
|
// Get unix epoch time now at the server (seconds)
|
|
unixTsNow(context.Context) (uint32, error)
|
|
}
|
|
|
|
type querrierImpl struct {
|
|
db driver.Conn
|
|
|
|
// Cluster name to use for scraping query log from clustered deployments.
|
|
// If ClusterName is specified, the scrape will target `clusterAllReplicas(clusterName, system.query_log)`
|
|
clusterName string
|
|
}
|
|
|
|
var _ datastoreQuerier = (*querrierImpl)(nil)
|
|
|
|
func newDatastoreQuerrier(db driver.Conn, clusterName string) *querrierImpl {
|
|
return &querrierImpl{
|
|
db: db,
|
|
clusterName: clusterName,
|
|
}
|
|
}
|
|
|
|
func (q *querrierImpl) scrapeQueryLog(
|
|
ctx context.Context, minTs uint32, maxTs uint32,
|
|
) ([]QueryLog, error) {
|
|
return scrapeQueryLogTable(ctx, q.db, q.clusterName, minTs, maxTs)
|
|
}
|
|
|
|
func (q *querrierImpl) unixTsNow(ctx context.Context) (
|
|
uint32, error,
|
|
) {
|
|
var serverTsNow uint32
|
|
row := q.db.QueryRow(ctx, `select toUnixTimestamp(now())`)
|
|
if err := row.Scan(&serverTsNow); err != nil {
|
|
return 0, fmt.Errorf(
|
|
"couldn't query current timestamp at datastore server: %w", err,
|
|
)
|
|
}
|
|
return serverTsNow, nil
|
|
}
|