2017-10-26 11:05:52 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2021-01-29 23:56:29 +00:00
|
|
|
"context"
|
2017-10-26 11:05:52 +00:00
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/models"
|
|
|
|
"github.com/influxdata/influxdb/query"
|
|
|
|
"github.com/influxdata/influxdb/tsdb"
|
2017-10-30 21:40:26 +00:00
|
|
|
"github.com/influxdata/influxql"
|
2017-10-27 17:27:01 +00:00
|
|
|
"go.uber.org/zap"
|
2017-10-26 11:05:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TSDBStoreMock is a mockable implementation of tsdb.Store.
|
|
|
|
type TSDBStoreMock struct {
|
|
|
|
BackupShardFn func(id uint64, since time.Time, w io.Writer) error
|
2017-12-08 17:11:07 +00:00
|
|
|
BackupSeriesFileFn func(database string, w io.Writer) error
|
2017-12-07 16:35:20 +00:00
|
|
|
ExportShardFn func(id uint64, ExportStart time.Time, ExportEnd time.Time, w io.Writer) error
|
2017-10-26 11:05:52 +00:00
|
|
|
CloseFn func() error
|
|
|
|
CreateShardFn func(database, policy string, shardID uint64, enabled bool) error
|
|
|
|
CreateShardSnapshotFn func(id uint64) (string, error)
|
|
|
|
DatabasesFn func() []string
|
|
|
|
DeleteDatabaseFn func(name string) error
|
|
|
|
DeleteMeasurementFn func(database, name string) error
|
|
|
|
DeleteRetentionPolicyFn func(database, name string) error
|
2018-01-03 12:11:17 +00:00
|
|
|
DeleteSeriesFn func(database string, sources []influxql.Source, condition influxql.Expr) error
|
2017-10-26 11:05:52 +00:00
|
|
|
DeleteShardFn func(id uint64) error
|
|
|
|
DiskSizeFn func() (int64, error)
|
|
|
|
ExpandSourcesFn func(sources influxql.Sources) (influxql.Sources, error)
|
2020-12-07 14:24:37 +00:00
|
|
|
ImportShardFn func(id uint64, r io.Reader) error
|
2017-10-26 11:05:52 +00:00
|
|
|
MeasurementSeriesCountsFn func(database string) (measuments int, series int)
|
|
|
|
MeasurementsCardinalityFn func(database string) (int64, error)
|
2021-03-22 13:52:33 +00:00
|
|
|
MeasurementNamesFn func(auth query.FineAuthorizer, database string, cond influxql.Expr) ([][]byte, error)
|
2017-10-26 11:05:52 +00:00
|
|
|
OpenFn func() error
|
|
|
|
PathFn func() string
|
|
|
|
RestoreShardFn func(id uint64, r io.Reader) error
|
|
|
|
SeriesCardinalityFn func(database string) (int64, error)
|
|
|
|
SetShardEnabledFn func(shardID uint64, enabled bool) error
|
|
|
|
ShardFn func(id uint64) *tsdb.Shard
|
|
|
|
ShardGroupFn func(ids []uint64) tsdb.ShardGroup
|
|
|
|
ShardIDsFn func() []uint64
|
|
|
|
ShardNFn func() int
|
|
|
|
ShardRelativePathFn func(id uint64) (string, error)
|
|
|
|
ShardsFn func(ids []uint64) []*tsdb.Shard
|
|
|
|
StatisticsFn func(tags map[string]string) []models.Statistic
|
2021-03-22 13:52:33 +00:00
|
|
|
TagKeysFn func(auth query.FineAuthorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagKeys, error)
|
|
|
|
TagValuesFn func(auth query.FineAuthorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagValues, error)
|
2017-10-27 17:27:01 +00:00
|
|
|
WithLoggerFn func(log *zap.Logger)
|
feat: measurement metrics by login (#20687)
After turning on authentication and both forms of ingress metrics:
"ingress": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"cq","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":76}},
"ingress:1": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"database","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":152}},
"ingress:2": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"httpd","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":874}},
"ingress:3": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"ingress","rp":"monitor"},"values":{"pointsWritten":534,"valuesWritten":1068}},
"ingress:4": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"localStore","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":76}},
"ingress:5": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"queryExecutor","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":190}},
"ingress:6": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"runtime","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":570}},
"ingress:7": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"shard","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":836}},
"ingress:8": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"subscriber","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":114}},
"ingress:9": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_cache","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":684}},
"ingress:10": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_engine","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":2204}},
"ingress:11": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_filestore","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":152}},
"ingress:12": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_wal","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":304}},
"ingress:13": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"write","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":342}},
"ingress:14": {"name":"ingress","tags":{"db":"telegraf","login":"admin","measurement":"cpu","rp":"autogen"},"values":{"pointsWritten":1,"valuesWritten":1}},
"ingress:15": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"cpu","rp":"autogen"},"values":{"pointsWritten":1316,"valuesWritten":13160}},
"ingress:16": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"disk","rp":"autogen"},"values":{"pointsWritten":642,"valuesWritten":4494}},
"ingress:17": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"diskio","rp":"autogen"},"values":{"pointsWritten":214,"valuesWritten":2354}},
"ingress:18": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"mem","rp":"autogen"},"values":{"pointsWritten":107,"valuesWritten":963}},
"ingress:19": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"processes","rp":"autogen"},"values":{"pointsWritten":107,"valuesWritten":856}},
"ingress:20": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"swap","rp":"autogen"},"values":{"pointsWritten":214,"valuesWritten":642}},
"ingress:21": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"system","rp":"autogen"},"values":{"pointsWritten":321,"valuesWritten":749}},
Only by login:
"ingress": {"name":"ingress","tags":{"login":"_systemuser_monitor"},"values":{"pointsWritten":42,"valuesWritten":354}},
"ingress:1": {"name":"ingress","tags":{"login":"admin"},"values":{"pointsWritten":1,"valuesWritten":1}},
"ingress:2": {"name":"ingress","tags":{"login":"telegraf"},"values":{"pointsWritten":3547,"valuesWritten":28246}},
Notice writes by users 'telegraf', '_systemuser_monitor', and 'admin'.
2021-02-04 16:52:53 +00:00
|
|
|
WriteToShardFn func(ctx tsdb.WriteContext, shardID uint64, points []models.Point) error
|
2017-10-26 11:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TSDBStoreMock) BackupShard(id uint64, since time.Time, w io.Writer) error {
|
|
|
|
return s.BackupShardFn(id, since, w)
|
|
|
|
}
|
2017-12-08 17:11:07 +00:00
|
|
|
func (s *TSDBStoreMock) BackupSeriesFile(database string, w io.Writer) error {
|
|
|
|
return s.BackupSeriesFileFn(database, w)
|
2017-11-22 15:30:02 +00:00
|
|
|
}
|
2017-12-07 16:35:20 +00:00
|
|
|
func (s *TSDBStoreMock) ExportShard(id uint64, ExportStart time.Time, ExportEnd time.Time, w io.Writer) error {
|
|
|
|
return s.ExportShardFn(id, ExportStart, ExportEnd, w)
|
|
|
|
}
|
2017-10-26 11:05:52 +00:00
|
|
|
func (s *TSDBStoreMock) Close() error { return s.CloseFn() }
|
|
|
|
func (s *TSDBStoreMock) CreateShard(database string, retentionPolicy string, shardID uint64, enabled bool) error {
|
|
|
|
return s.CreateShardFn(database, retentionPolicy, shardID, enabled)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) CreateShardSnapshot(id uint64) (string, error) {
|
|
|
|
return s.CreateShardSnapshotFn(id)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Databases() []string {
|
|
|
|
return s.DatabasesFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) DeleteDatabase(name string) error {
|
|
|
|
return s.DeleteDatabaseFn(name)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) DeleteMeasurement(database string, name string) error {
|
|
|
|
return s.DeleteMeasurementFn(database, name)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) DeleteRetentionPolicy(database string, name string) error {
|
|
|
|
return s.DeleteRetentionPolicyFn(database, name)
|
|
|
|
}
|
2018-01-03 12:11:17 +00:00
|
|
|
func (s *TSDBStoreMock) DeleteSeries(database string, sources []influxql.Source, condition influxql.Expr) error {
|
|
|
|
return s.DeleteSeriesFn(database, sources, condition)
|
2017-10-26 11:05:52 +00:00
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) DeleteShard(shardID uint64) error {
|
|
|
|
return s.DeleteShardFn(shardID)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) DiskSize() (int64, error) {
|
|
|
|
return s.DiskSizeFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) ExpandSources(sources influxql.Sources) (influxql.Sources, error) {
|
|
|
|
return s.ExpandSourcesFn(sources)
|
|
|
|
}
|
2020-12-07 14:24:37 +00:00
|
|
|
func (s *TSDBStoreMock) ImportShard(id uint64, r io.Reader) error {
|
|
|
|
return s.ImportShardFn(id, r)
|
|
|
|
}
|
2021-10-05 13:07:25 +00:00
|
|
|
func (s *TSDBStoreMock) MeasurementNames(ctx context.Context, auth query.FineAuthorizer, database string, retentionPolicy string, cond influxql.Expr) ([][]byte, error) {
|
2017-11-15 15:48:23 +00:00
|
|
|
return s.MeasurementNamesFn(auth, database, cond)
|
2017-10-26 11:05:52 +00:00
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) MeasurementSeriesCounts(database string) (measuments int, series int) {
|
|
|
|
return s.MeasurementSeriesCountsFn(database)
|
|
|
|
}
|
2021-01-29 23:56:29 +00:00
|
|
|
func (s *TSDBStoreMock) MeasurementsCardinality(ctx context.Context, database string) (int64, error) {
|
2017-10-26 11:05:52 +00:00
|
|
|
return s.MeasurementsCardinalityFn(database)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Open() error {
|
|
|
|
return s.OpenFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Path() string {
|
|
|
|
return s.PathFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) RestoreShard(id uint64, r io.Reader) error {
|
|
|
|
return s.RestoreShardFn(id, r)
|
|
|
|
}
|
2021-01-29 23:56:29 +00:00
|
|
|
func (s *TSDBStoreMock) SeriesCardinality(ctx context.Context, database string) (int64, error) {
|
2017-10-26 11:05:52 +00:00
|
|
|
return s.SeriesCardinalityFn(database)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) SetShardEnabled(shardID uint64, enabled bool) error {
|
|
|
|
return s.SetShardEnabledFn(shardID, enabled)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Shard(id uint64) *tsdb.Shard {
|
|
|
|
return s.ShardFn(id)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) ShardGroup(ids []uint64) tsdb.ShardGroup {
|
|
|
|
return s.ShardGroupFn(ids)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) ShardIDs() []uint64 {
|
|
|
|
return s.ShardIDsFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) ShardN() int {
|
|
|
|
return s.ShardNFn()
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) ShardRelativePath(id uint64) (string, error) {
|
|
|
|
return s.ShardRelativePathFn(id)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Shards(ids []uint64) []*tsdb.Shard {
|
|
|
|
return s.ShardsFn(ids)
|
|
|
|
}
|
|
|
|
func (s *TSDBStoreMock) Statistics(tags map[string]string) []models.Statistic {
|
|
|
|
return s.StatisticsFn(tags)
|
|
|
|
}
|
2021-03-22 13:52:33 +00:00
|
|
|
func (s *TSDBStoreMock) TagKeys(ctx context.Context, auth query.FineAuthorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagKeys, error) {
|
2017-11-06 15:31:04 +00:00
|
|
|
return s.TagKeysFn(auth, shardIDs, cond)
|
|
|
|
}
|
2021-03-22 13:52:33 +00:00
|
|
|
func (s *TSDBStoreMock) TagValues(ctx context.Context, auth query.FineAuthorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagValues, error) {
|
2017-11-03 16:53:23 +00:00
|
|
|
return s.TagValuesFn(auth, shardIDs, cond)
|
2017-10-26 11:05:52 +00:00
|
|
|
}
|
2017-10-27 17:27:01 +00:00
|
|
|
func (s *TSDBStoreMock) WithLogger(log *zap.Logger) {
|
2017-10-26 11:05:52 +00:00
|
|
|
s.WithLoggerFn(log)
|
|
|
|
}
|
feat: measurement metrics by login (#20687)
After turning on authentication and both forms of ingress metrics:
"ingress": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"cq","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":76}},
"ingress:1": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"database","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":152}},
"ingress:2": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"httpd","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":874}},
"ingress:3": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"ingress","rp":"monitor"},"values":{"pointsWritten":534,"valuesWritten":1068}},
"ingress:4": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"localStore","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":76}},
"ingress:5": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"queryExecutor","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":190}},
"ingress:6": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"runtime","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":570}},
"ingress:7": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"shard","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":836}},
"ingress:8": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"subscriber","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":114}},
"ingress:9": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_cache","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":684}},
"ingress:10": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_engine","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":2204}},
"ingress:11": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_filestore","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":152}},
"ingress:12": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"tsm1_wal","rp":"monitor"},"values":{"pointsWritten":76,"valuesWritten":304}},
"ingress:13": {"name":"ingress","tags":{"db":"_internal","login":"_systemuser_monitor","measurement":"write","rp":"monitor"},"values":{"pointsWritten":38,"valuesWritten":342}},
"ingress:14": {"name":"ingress","tags":{"db":"telegraf","login":"admin","measurement":"cpu","rp":"autogen"},"values":{"pointsWritten":1,"valuesWritten":1}},
"ingress:15": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"cpu","rp":"autogen"},"values":{"pointsWritten":1316,"valuesWritten":13160}},
"ingress:16": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"disk","rp":"autogen"},"values":{"pointsWritten":642,"valuesWritten":4494}},
"ingress:17": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"diskio","rp":"autogen"},"values":{"pointsWritten":214,"valuesWritten":2354}},
"ingress:18": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"mem","rp":"autogen"},"values":{"pointsWritten":107,"valuesWritten":963}},
"ingress:19": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"processes","rp":"autogen"},"values":{"pointsWritten":107,"valuesWritten":856}},
"ingress:20": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"swap","rp":"autogen"},"values":{"pointsWritten":214,"valuesWritten":642}},
"ingress:21": {"name":"ingress","tags":{"db":"telegraf","login":"telegraf","measurement":"system","rp":"autogen"},"values":{"pointsWritten":321,"valuesWritten":749}},
Only by login:
"ingress": {"name":"ingress","tags":{"login":"_systemuser_monitor"},"values":{"pointsWritten":42,"valuesWritten":354}},
"ingress:1": {"name":"ingress","tags":{"login":"admin"},"values":{"pointsWritten":1,"valuesWritten":1}},
"ingress:2": {"name":"ingress","tags":{"login":"telegraf"},"values":{"pointsWritten":3547,"valuesWritten":28246}},
Notice writes by users 'telegraf', '_systemuser_monitor', and 'admin'.
2021-02-04 16:52:53 +00:00
|
|
|
func (s *TSDBStoreMock) WriteToShard(writeCtx tsdb.WriteContext, shardID uint64, points []models.Point) error {
|
|
|
|
return s.WriteToShardFn(writeCtx, shardID, points)
|
2017-10-26 11:05:52 +00:00
|
|
|
}
|