stats

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const BlockstoreTypeKey = "blockstore_type"

Variables

View Source
var (
	ErrSendError        = errors.New("stats: send error")
	ErrNoInstallationID = fmt.Errorf("installation ID is missing: %w", ErrSendError)
)

Functions

func BuildMetadataProvider

func BuildMetadataProvider(logger logging.Logger, c *config.Config) cloud.MetadataProvider

func HashMetricValue added in v0.83.0

func HashMetricValue(s string) string

func IsSuccessStatusCode added in v0.90.1

func IsSuccessStatusCode(statusCode int) bool

IsSuccessStatusCode returns true for status code 2xx

Types

type BufferedCollector

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

func NewBufferedCollector

func NewBufferedCollector(installationID string, cfg Config, opts ...BufferedCollectorOpts) *BufferedCollector

func (*BufferedCollector) Close added in v0.62.0

func (s *BufferedCollector) Close()

func (*BufferedCollector) CollectCommPrefs added in v0.87.0

func (s *BufferedCollector) CollectCommPrefs(commPrefsEventData CommPrefs)

func (*BufferedCollector) CollectEvent

func (s *BufferedCollector) CollectEvent(ev Event)

func (*BufferedCollector) CollectEvents added in v0.89.0

func (s *BufferedCollector) CollectEvents(ev Event, count uint64)

func (*BufferedCollector) CollectMetadata

func (s *BufferedCollector) CollectMetadata(accountMetadata *Metadata)

func (*BufferedCollector) SetInstallationID

func (s *BufferedCollector) SetInstallationID(installationID string)

func (*BufferedCollector) SetRuntimeCollector added in v0.48.0

func (s *BufferedCollector) SetRuntimeCollector(runtimeCollector func() map[string]string)

func (*BufferedCollector) Start added in v0.90.1

func (s *BufferedCollector) Start(ctx context.Context)

func (*BufferedCollector) Stop added in v0.90.1

func (s *BufferedCollector) Stop()

type BufferedCollectorOpts

type BufferedCollectorOpts func(s *BufferedCollector)

func WithExtended added in v0.83.0

func WithExtended(b bool) BufferedCollectorOpts

func WithLogger added in v0.83.0

func WithLogger(l logging.Logger) BufferedCollectorOpts

func WithSender

func WithSender(sender Sender) BufferedCollectorOpts

func WithWriteBufferSize

func WithWriteBufferSize(bufferSize int) BufferedCollectorOpts

type Collector

type Collector interface {
	CollectEvent(ev Event)
	CollectEvents(ev Event, count uint64)
	CollectMetadata(accountMetadata *Metadata)
	CollectCommPrefs(commPrefsEventData CommPrefs)
	SetInstallationID(installationID string)

	// Close must be called to ensure the delivery of pending stats
	Close()
}

type CommPrefs added in v1.2.0

type CommPrefs struct {
	InstallationID  string
	Email           string
	FeatureUpdates  bool
	SecurityUpdates bool
	BlockstoreType  string
}

type CommPrefsData added in v0.87.0

type CommPrefsData struct {
	InstallationID  string `json:"installation_id"`
	Email           string `json:"email"`
	FeatureUpdates  bool   `json:"featureUpdates"`
	SecurityUpdates bool   `json:"securityUpdates"`
	BlockstoreType  string `json:"blockstoreType"`
}

type Config added in v0.90.0

type Config struct {
	Enabled       bool
	Address       string
	FlushInterval time.Duration
	FlushSize     int
	Extended      bool
}

type ConstantWithJitterBackOff added in v1.8.0

type ConstantWithJitterBackOff struct {
	Interval time.Duration
	Jitter   time.Duration
}

ConstantWithJitterBackOff is a backoff strategy that returns a constant interval with a random jitter which is half the interval.

func NewConstantWithJitterBackOff added in v1.8.0

func NewConstantWithJitterBackOff(d time.Duration) *ConstantWithJitterBackOff

func (*ConstantWithJitterBackOff) NextBackOff added in v1.8.0

func (b *ConstantWithJitterBackOff) NextBackOff() time.Duration

func (*ConstantWithJitterBackOff) Reset added in v1.8.0

func (b *ConstantWithJitterBackOff) Reset()

type Event added in v0.83.0

type Event struct {
	Class      string `json:"class"`
	Name       string `json:"name"`
	Repository string `json:"repository,omitempty"`
	Ref        string `json:"ref,omitempty"`
	SourceRef  string `json:"source_ref,omitempty"`
	UserID     string `json:"user_id,omitempty"`
	Client     string `json:"client,omitempty"`
}

func (Event) ClearExtended added in v0.83.0

func (e Event) ClearExtended() Event

ClearExtended clear values of *all* extended fields

func (Event) HashExtended added in v0.83.0

func (e Event) HashExtended() Event

HashExtended hash the values of extended fields with sensitive information

type FlushTicker

type FlushTicker interface {
	Stop()
	Tick() <-chan time.Time
}

type HTTPSender

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

func NewHTTPSender

func NewHTTPSender(addr string, log logging.Logger) *HTTPSender

func (*HTTPSender) SendEvent

func (s *HTTPSender) SendEvent(ctx context.Context, event *InputEvent) error

func (*HTTPSender) UpdateCommPrefs added in v0.87.0

func (s *HTTPSender) UpdateCommPrefs(ctx context.Context, commPrefs *CommPrefsData) error

func (*HTTPSender) UpdateMetadata

func (s *HTTPSender) UpdateMetadata(ctx context.Context, m Metadata) error

type InputEvent

type InputEvent struct {
	InstallationID string   `json:"installation_id"`
	ProcessID      string   `json:"process_id"`
	Time           string   `json:"time"`
	Metrics        []Metric `json:"metrics"`
}

type LoggerAdapter added in v0.90.1

type LoggerAdapter struct {
	logging.Logger
}

func (*LoggerAdapter) Printf added in v0.90.1

func (l *LoggerAdapter) Printf(msg string, args ...interface{})

type Metadata

type Metadata struct {
	InstallationID string          `json:"installation_id"`
	Entries        []MetadataEntry `json:"entries"`
}

func NewMetadata

func NewMetadata(ctx context.Context, logger logging.Logger, blockstoreType string, metadataProvider MetadataProvider, cloudMetadataProvider cloud.MetadataProvider) *Metadata

type MetadataEntry

type MetadataEntry struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type MetadataProvider added in v0.102.0

type MetadataProvider interface {
	GetMetadata(context.Context) (map[string]string, error)
}

type Metric

type Metric struct {
	Event
	Value uint64 `json:"value"`
}

type NopUsageReporter added in v1.8.0

type NopUsageReporter struct{}

NopUsageReporter is a usage reporter that does nothing.

func (*NopUsageReporter) Flush added in v1.8.0

func (n *NopUsageReporter) Flush(_ context.Context) (time.Time, error)

func (*NopUsageReporter) InstallationID added in v1.8.0

func (n *NopUsageReporter) InstallationID() string

func (*NopUsageReporter) Records added in v1.8.0

func (n *NopUsageReporter) Records(_ context.Context) ([]*UsageRecord, error)

type NullCollector added in v0.70.1

type NullCollector struct{}

func (*NullCollector) Close added in v0.70.1

func (m *NullCollector) Close()

func (*NullCollector) CollectCommPrefs added in v0.87.0

func (m *NullCollector) CollectCommPrefs(_ CommPrefs)

func (*NullCollector) CollectEvent added in v0.70.1

func (m *NullCollector) CollectEvent(_ Event)

func (*NullCollector) CollectEvents added in v0.89.0

func (m *NullCollector) CollectEvents(_ Event, _ uint64)

func (*NullCollector) CollectMetadata added in v0.70.1

func (m *NullCollector) CollectMetadata(_ *Metadata)

func (*NullCollector) SetInstallationID added in v0.70.1

func (m *NullCollector) SetInstallationID(_ string)

type Sender

type Sender interface {
	SendEvent(ctx context.Context, event *InputEvent) error
	UpdateMetadata(ctx context.Context, m Metadata) error
	UpdateCommPrefs(ctx context.Context, commPrefs *CommPrefsData) error
}

type TimeFn

type TimeFn func() time.Time

type TimeTicker

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

func (*TimeTicker) Stop

func (t *TimeTicker) Stop()

func (*TimeTicker) Tick

func (t *TimeTicker) Tick() <-chan time.Time

type UsageCounter added in v1.8.0

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

UsageCounter is a counter that can be used to track usage of a resource api/gtw

func NewUsageCounter added in v1.8.0

func NewUsageCounter() *UsageCounter

NewUsageCounter creates a new usage counter and adds it to the global list of usage counters

func UsageCounters added in v1.8.0

func UsageCounters() []*UsageCounter

UsageCounters returns a list of all usage counters. This is used for testing.

func (*UsageCounter) Add added in v1.8.0

func (uc *UsageCounter) Add(delta int64)

Add adds delta to the usage counter

func (*UsageCounter) Load added in v1.8.0

func (uc *UsageCounter) Load() int64

Load returns the current value of the usage counter

func (*UsageCounter) Reset added in v1.8.0

func (uc *UsageCounter) Reset() int64

Reset resets the usage counter to 0 and returns the previous value

func (*UsageCounter) Unregister added in v1.8.0

func (uc *UsageCounter) Unregister()

Unregister removes the usage counter from the global list of usage counters. This is used for testing.

type UsageRecord added in v1.8.0

type UsageRecord struct {
	Year  int
	Month int
	Count int64
}

UsageRecord is a record of usage for a specific month

type UsageReporter added in v1.8.0

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

UsageReporter is a usage reporter that persists usage counters to a storage backend.

func NewUsageReporter added in v1.8.0

func NewUsageReporter(installationID string, storage kv.Store) *UsageReporter

func (*UsageReporter) Flush added in v1.8.0

func (u *UsageReporter) Flush(ctx context.Context) (time.Time, error)

func (*UsageReporter) InstallationID added in v1.8.0

func (u *UsageReporter) InstallationID() string

func (*UsageReporter) Records added in v1.8.0

func (u *UsageReporter) Records(ctx context.Context) ([]*UsageRecord, error)

Records returns all usage records from the storage backend. It returns an error if the storage backend fails to scan the records or parse them. It will filter out records that are not from the current installation ID.

func (*UsageReporter) Start added in v1.8.0

func (u *UsageReporter) Start(ctx context.Context, interval time.Duration, logger logging.Logger)

Start starts the usage reporting loop. It persists the current usage counters to the storage backend every interval. To stop the loop, cancel the context.

type UsageReporterOperations added in v1.8.0

type UsageReporterOperations interface {
	InstallationID() string
	Records(ctx context.Context) ([]*UsageRecord, error)
	Flush(ctx context.Context) (time.Time, error)
}

UsageReporterOperations is an interface for usage reporting. The main two implementations here are UsageReporter and NopUsageReporter.

var (

	// DefaultUsageReporter is the default usage reporter. It does nothing.
	DefaultUsageReporter UsageReporterOperations = &NopUsageReporter{}

	ErrInvalidUsageKeyFormat = errors.New("invalid usage key format")
)

Jump to

Keyboard shortcuts

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