aggregating

package
v1.3.3-0...-f31c912 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEndpoint = "https://" + defaultEndpointHostname
)
View Source
const (
	ResourcePresenceReportsPrefix = "resourcePresenceReports"
)

Variables

This section is empty.

Functions

func ClearAlert

func ClearAlert(ctx context.Context, status services.StatusInternal) error

ClearAlert attempts to delete the reporting-failed alert; it's expected to return nil if it successfully deletes the alert, and a trace.NotFound error if there's no alert.

func RunSubmitter

func RunSubmitter(ctx context.Context, cfg SubmitterConfig)

RunSubmitter periodically fetches aggregated reports from the backend and sends them in small batches with the provided submitter, before deleting them. Must only be called after validating the config object with CheckAndSetDefaults, and should probably be called in a goroutine.

Types

type Reporter

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

Reporter aggregates and persists usage events to the backend.

func NewReporter

func NewReporter(ctx context.Context, cfg ReporterConfig) (*Reporter, error)

NewReporter returns a new running Reporter. To avoid resource leaks, GracefulStop must be called or the base context must be closed. The context will be used for all backend operations.

func (*Reporter) AnonymizeAndSubmit

func (r *Reporter) AnonymizeAndSubmit(events ...usagereporter.Anonymizable)

AnonymizeAndSubmit implements usagereporter.UsageReporter.

func (*Reporter) GracefulStop

func (r *Reporter) GracefulStop(ctx context.Context) error

GracefulStop implements usagereporter.GracefulStopper.

type ReporterConfig

type ReporterConfig struct {
	// Backend is the backend used to store reports. Required
	Backend backend.Backend
	// Log is the logger used for logging. Required.
	Log logrus.FieldLogger
	// Clock is the clock used for timestamping reports and deciding when to
	// persist them to the backend. Optional, defaults to the real clock.
	Clock clockwork.Clock

	// ClusterName is the ClusterName resource for the current cluster, used for
	// anonymization and to report the cluster name itself. Required.
	ClusterName types.ClusterName
	// HostID is the host ID of the current Teleport instance, added to reports
	// for auditing purposes. Required.
	HostID string
	// AnonymizationKey is the key used to anonymize data user or resource names. Optional.
	AnonymizationKey string
}

ReporterConfig contains the configuration for a Reporter.

func (*ReporterConfig) CheckAndSetDefaults

func (cfg *ReporterConfig) CheckAndSetDefaults() error

CheckAndSetDefaults checks the ReporterConfig for validity, returning nil if there's no error. Idempotent but not concurrent safe, as it might need to write to the config to apply defaults.

type SubmitterConfig

type SubmitterConfig struct {
	// Backend is the backend to use to read reports and apply locks. Required.
	Backend backend.Backend
	// Log is the [logrus.FieldLogger] used for logging. Required.
	Log logrus.FieldLogger
	// Status is used to create or clear cluster alerts on a failure. Required.
	Status services.StatusInternal
	// Submitter is used to submit usage reports. Required.
	Submitter UsageReportsSubmitter

	// HostID is the host ID of the current Teleport instance, used in the lock
	// payload and cluster alert description to help debugging. Optional.
	HostID string
}

SubmitterConfig contains the configuration for a [Submitter].

func (*SubmitterConfig) CheckAndSetDefaults

func (cfg *SubmitterConfig) CheckAndSetDefaults() error

CheckAndSetDefaults checks the SubmitterConfig for validity, returning nil if there's no error. Idempotent but not concurrent safe, as it might need to write to the config to apply defaults.

type UsageReportsSubmitter

type UsageReportsSubmitter func(context.Context, *prehogv1.SubmitUsageReportsRequest) (uuid.UUID, error)

UsageReportsSubmitter is almost SubmitUsageReports from prehog.v1alpha.TeleportReportingService, but instead of returning the raw response (and requiring wrapping the request in a [connect.Request]) it should parse the response and return the batch UUID.

Jump to

Keyboard shortcuts

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