usage

package
v1.34.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCollectionInterval = 1 * time.Hour
	// DefaultShardJitterInterval short for shard-level operations and can be configurable later on
	DefaultShardJitterInterval = 100 * time.Millisecond
	DefaultRuntimeLoadInterval = 2 * time.Minute
)

Variables

This section is empty.

Functions

func ParseCommonUsageConfig

func ParseCommonUsageConfig(config *config.Config) error

ParseCommonUsageConfig parses common environment variables shared by all usage modules

Types

type BaseModule

type BaseModule struct {
	// contains filtered or unexported fields
}

BaseModule contains the common logic for usage collection modules

func NewBaseModule

func NewBaseModule(moduleName string, storage StorageBackend) *BaseModule

NewBaseModule creates a new base module instance

func (*BaseModule) Close

func (b *BaseModule) Close() error

func (*BaseModule) GetMetrics

func (b *BaseModule) GetMetrics() *Metrics

func (*BaseModule) InitializeCommon

func (b *BaseModule) InitializeCommon(ctx context.Context, config *config.Config, logger logrus.FieldLogger, metrics *Metrics) error

InitializeCommon initializes the common components of the usage module

func (*BaseModule) Logger

func (b *BaseModule) Logger() logrus.FieldLogger

func (*BaseModule) Name

func (b *BaseModule) Name() string

func (*BaseModule) SetUsageService

func (b *BaseModule) SetUsageService(usageService any)

func (*BaseModule) Type

type BaseStorage

type BaseStorage struct {
	BucketName        string
	Prefix            string
	NodeID            string
	VerifyPermissions bool
	Logger            logrus.FieldLogger
	Metrics           *Metrics
}

BaseStorage provides common functionality for all storage backends

func NewBaseStorage

func NewBaseStorage(logger logrus.FieldLogger, metrics *Metrics) *BaseStorage

NewBaseStorage creates a new base storage instance

func (*BaseStorage) ConstructObjectKey

func (b *BaseStorage) ConstructObjectKey(collectionTime string) string

ConstructObjectKey creates the full object key path for storage

func (*BaseStorage) IsLocalhostEnvironment

func (b *BaseStorage) IsLocalhostEnvironment() bool

IsLocalhostEnvironment checks if running in localhost/emulator mode

func (*BaseStorage) LogVerificationStart

func (b *BaseStorage) LogVerificationStart()

LogVerificationStart logs the start of permission verification

func (*BaseStorage) LogVerificationSuccess

func (b *BaseStorage) LogVerificationSuccess(extraFields ...logrus.Fields)

LogVerificationSuccess logs successful permission verification

func (*BaseStorage) MarshalUsageData

func (b *BaseStorage) MarshalUsageData(usage *types.Report) ([]byte, error)

MarshalUsageData converts usage data to JSON

func (*BaseStorage) RecordUploadMetrics

func (b *BaseStorage) RecordUploadMetrics(dataSize int)

RecordUploadMetrics records upload metrics

func (*BaseStorage) UpdateCommonConfig

func (b *BaseStorage) UpdateCommonConfig(config StorageConfig) bool

UpdateCommonConfig updates common configuration fields and returns whether anything changed

type Metrics

type Metrics struct {
	// Operation metrics
	OperationTotal   *prometheus.CounterVec
	OperationLatency *prometheus.HistogramVec

	// Resource metrics
	ResourceCount    *prometheus.GaugeVec
	UploadedFileSize prometheus.Gauge
}

func NewMetrics

func NewMetrics(reg prometheus.Registerer, moduleName string) *Metrics

type MockStorageBackend

type MockStorageBackend struct {
	mock.Mock
}

MockStorageBackend is an autogenerated mock type for the StorageBackend type

func NewMockStorageBackend

func NewMockStorageBackend(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockStorageBackend

NewMockStorageBackend creates a new instance of MockStorageBackend. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockStorageBackend) Close

func (_m *MockStorageBackend) Close() error

Close provides a mock function with no fields

func (*MockStorageBackend) EXPECT

func (*MockStorageBackend) UpdateConfig

func (_m *MockStorageBackend) UpdateConfig(config StorageConfig) (bool, error)

UpdateConfig provides a mock function with given fields: config

func (*MockStorageBackend) UploadUsageData

func (_m *MockStorageBackend) UploadUsageData(ctx context.Context, _a1 *types.Report) error

UploadUsageData provides a mock function with given fields: ctx, _a1

func (*MockStorageBackend) VerifyPermissions

func (_m *MockStorageBackend) VerifyPermissions(ctx context.Context) error

VerifyPermissions provides a mock function with given fields: ctx

type MockStorageBackend_Close_Call

type MockStorageBackend_Close_Call struct {
	*mock.Call
}

MockStorageBackend_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'

func (*MockStorageBackend_Close_Call) Return

func (*MockStorageBackend_Close_Call) Run

func (*MockStorageBackend_Close_Call) RunAndReturn

type MockStorageBackend_Expecter

type MockStorageBackend_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockStorageBackend_Expecter) Close

Close is a helper method to define mock.On call

func (*MockStorageBackend_Expecter) UpdateConfig

func (_e *MockStorageBackend_Expecter) UpdateConfig(config interface{}) *MockStorageBackend_UpdateConfig_Call

UpdateConfig is a helper method to define mock.On call

  • config StorageConfig

func (*MockStorageBackend_Expecter) UploadUsageData

func (_e *MockStorageBackend_Expecter) UploadUsageData(ctx interface{}, _a1 interface{}) *MockStorageBackend_UploadUsageData_Call

UploadUsageData is a helper method to define mock.On call

  • ctx context.Context
  • _a1 *types.Report

func (*MockStorageBackend_Expecter) VerifyPermissions

func (_e *MockStorageBackend_Expecter) VerifyPermissions(ctx interface{}) *MockStorageBackend_VerifyPermissions_Call

VerifyPermissions is a helper method to define mock.On call

  • ctx context.Context

type MockStorageBackend_UpdateConfig_Call

type MockStorageBackend_UpdateConfig_Call struct {
	*mock.Call
}

MockStorageBackend_UpdateConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateConfig'

func (*MockStorageBackend_UpdateConfig_Call) Return

func (*MockStorageBackend_UpdateConfig_Call) Run

func (*MockStorageBackend_UpdateConfig_Call) RunAndReturn

type MockStorageBackend_UploadUsageData_Call

type MockStorageBackend_UploadUsageData_Call struct {
	*mock.Call
}

MockStorageBackend_UploadUsageData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UploadUsageData'

func (*MockStorageBackend_UploadUsageData_Call) Return

func (*MockStorageBackend_UploadUsageData_Call) Run

func (*MockStorageBackend_UploadUsageData_Call) RunAndReturn

type MockStorageBackend_VerifyPermissions_Call

type MockStorageBackend_VerifyPermissions_Call struct {
	*mock.Call
}

MockStorageBackend_VerifyPermissions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'VerifyPermissions'

func (*MockStorageBackend_VerifyPermissions_Call) Return

func (*MockStorageBackend_VerifyPermissions_Call) Run

func (*MockStorageBackend_VerifyPermissions_Call) RunAndReturn

type StorageBackend

type StorageBackend interface {
	// VerifyPermissions checks if the backend can access the storage location
	VerifyPermissions(ctx context.Context) error

	// UploadUsageData uploads the usage data to the storage backend
	UploadUsageData(ctx context.Context, usage *types.Report) error

	// Close cleans up any resources used by the storage backend
	Close() error

	// UpdateConfig updates the backend configuration from the provided config
	UpdateConfig(config StorageConfig) (bool, error) // returns true if any changes were made
}

StorageBackend defines the interface that storage implementations must implement

type StorageConfig

type StorageConfig struct {
	Bucket            string
	Prefix            string
	NodeID            string
	Version           string
	VerifyPermissions bool
}

StorageConfig contains common configuration fields for storage backends

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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