sqlquery

package module
v0.133.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverHDB       = "hdb"
	DriverMySQL     = "mysql"
	DriverOracle    = "oracle"
	DriverPostgres  = "postgres"
	DriverSnowflake = "snowflake"
	DriverSQLServer = "sqlserver"
	DriverTDS       = "tds"
)

Variables

View Source
var ErrNullValueWarning = errors.New("NULL value")

Functions

func BuildDataSourceString added in v0.129.0

func BuildDataSourceString(config Config) (string, error)

func IsValidDriver added in v0.129.0

func IsValidDriver(driver string) bool

IsValidDriver checks if the given driver name is supported

Types

type ClientProviderFunc

type ClientProviderFunc func(Db, string, *zap.Logger, TelemetryConfig) DbClient

type Config

type Config struct {
	scraperhelper.ControllerConfig `mapstructure:",squash"`
	Driver                         string              `mapstructure:"driver"`
	DataSource                     string              `mapstructure:"datasource"`
	Host                           string              `mapstructure:"host"`
	Port                           int                 `mapstructure:"port"`
	Database                       string              `mapstructure:"database"`
	Username                       string              `mapstructure:"username"`
	Password                       configopaque.String `mapstructure:"password"`
	AdditionalParams               map[string]any      `mapstructure:"additional_params"`
	Queries                        []Query             `mapstructure:"queries"`
	StorageID                      *component.ID       `mapstructure:"storage"`
	Telemetry                      TelemetryConfig     `mapstructure:"telemetry"`
}

func (Config) Validate

func (c Config) Validate() error

type Db

type Db interface {
	QueryContext(ctx context.Context, query string, args ...any) (rows, error)
}

type DbClient

type DbClient interface {
	QueryRows(ctx context.Context, args ...any) ([]StringMap, error)
}

func NewDbClient

func NewDbClient(db Db, sql string, logger *zap.Logger, telemetry TelemetryConfig) DbClient

type DbProviderFunc

type DbProviderFunc func() (*sql.DB, error)

type DbSQLClient

type DbSQLClient struct {
	Db        Db
	Logger    *zap.Logger
	Telemetry TelemetryConfig
	SQL       string
}

func (DbSQLClient) QueryRows

func (cl DbSQLClient) QueryRows(ctx context.Context, args ...any) ([]StringMap, error)

type DbWrapper

type DbWrapper struct {
	Db *sql.DB
}

func (DbWrapper) QueryContext

func (d DbWrapper) QueryContext(ctx context.Context, query string, args ...any) (rows, error)

type FakeDBClient

type FakeDBClient struct {
	RequestCounter int
	StringMaps     [][]StringMap
	Err            error
}

This is only used for testing, but need to be exposed to other packages.

func (*FakeDBClient) QueryRows

func (c *FakeDBClient) QueryRows(context.Context, ...any) ([]StringMap, error)

type LogsCfg

type LogsCfg struct {
	BodyColumn       string   `mapstructure:"body_column"`
	AttributeColumns []string `mapstructure:"attribute_columns"`
}

func (LogsCfg) Validate

func (config LogsCfg) Validate() error

type MetricAggregation

type MetricAggregation string
const (
	MetricAggregationUnspecified MetricAggregation = ""
	MetricAggregationCumulative  MetricAggregation = "cumulative"
	MetricAggregationDelta       MetricAggregation = "delta"
)

func (MetricAggregation) Validate

func (a MetricAggregation) Validate() error

type MetricCfg

type MetricCfg struct {
	MetricName       string            `mapstructure:"metric_name"`
	ValueColumn      string            `mapstructure:"value_column"`
	AttributeColumns []string          `mapstructure:"attribute_columns"`
	Monotonic        bool              `mapstructure:"monotonic"`
	ValueType        MetricValueType   `mapstructure:"value_type"`
	DataType         MetricType        `mapstructure:"data_type"`
	Aggregation      MetricAggregation `mapstructure:"aggregation"`
	Unit             string            `mapstructure:"unit"`
	Description      string            `mapstructure:"description"`
	StaticAttributes map[string]string `mapstructure:"static_attributes"`
	StartTsColumn    string            `mapstructure:"start_ts_column"`
	TsColumn         string            `mapstructure:"ts_column"`
}

func (MetricCfg) Validate

func (c MetricCfg) Validate() error

type MetricType

type MetricType string
const (
	MetricTypeUnspecified MetricType = ""
	MetricTypeGauge       MetricType = "gauge"
	MetricTypeSum         MetricType = "sum"
)

func (MetricType) Validate

func (t MetricType) Validate() error

type MetricValueType

type MetricValueType string
const (
	MetricValueTypeUnspecified MetricValueType = ""
	MetricValueTypeInt         MetricValueType = "int"
	MetricValueTypeDouble      MetricValueType = "double"
)

func (MetricValueType) Validate

func (t MetricValueType) Validate() error

type Query

type Query struct {
	SQL                string      `mapstructure:"sql"`
	Metrics            []MetricCfg `mapstructure:"metrics"`
	Logs               []LogsCfg   `mapstructure:"logs"`
	TrackingColumn     string      `mapstructure:"tracking_column"`
	TrackingStartValue string      `mapstructure:"tracking_start_value"`
}

func (Query) Validate

func (q Query) Validate() error

type SQLOpenerFunc

type SQLOpenerFunc func(driverName, dataSourceName string) (*sql.DB, error)

type Scraper

type Scraper struct {
	Query                Query
	ScrapeCfg            scraperhelper.ControllerConfig
	StartTime            pcommon.Timestamp
	ClientProviderFunc   ClientProviderFunc
	DbProviderFunc       DbProviderFunc
	Logger               *zap.Logger
	Telemetry            TelemetryConfig
	Client               DbClient
	Db                   *sql.DB
	InstrumentationScope pcommon.InstrumentationScope
	// contains filtered or unexported fields
}

func NewScraper

func NewScraper(id component.ID, query Query, scrapeCfg scraperhelper.ControllerConfig, logger *zap.Logger, telemetry TelemetryConfig, dbProviderFunc DbProviderFunc, clientProviderFunc ClientProviderFunc, instrumentationScope pcommon.InstrumentationScope) *Scraper

func (*Scraper) ID

func (s *Scraper) ID() component.ID

func (*Scraper) ScrapeMetrics added in v0.115.0

func (s *Scraper) ScrapeMetrics(ctx context.Context) (pmetric.Metrics, error)

func (*Scraper) Shutdown

func (s *Scraper) Shutdown(_ context.Context) error

func (*Scraper) Start

type StringMap

type StringMap map[string]string

type TelemetryConfig

type TelemetryConfig struct {
	Logs TelemetryLogsConfig `mapstructure:"logs"`
}

type TelemetryLogsConfig

type TelemetryLogsConfig struct {
	Query bool `mapstructure:"query"`
}

Jump to

Keyboard shortcuts

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