sqlquery

package module
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

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"`
	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"`
}

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
	// 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) *Scraper

func (*Scraper) ID

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

func (*Scraper) Scrape

func (s *Scraper) Scrape(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