usagemetrics

package
v0.0.0-...-efb6969 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package usagemetrics provides logging utility for the operational status of Google Cloud Agents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentProperties

type AgentProperties struct {
	Name             string
	Version          string
	LogUsageMetrics  bool
	LogUsagePrefix   string
	LogUsageOptional string // optional string to be added to the usage log: "UsageLogPrefix/AgentName/AgentVersion[/OptionalString]/Status"
}

AgentProperties contains the properties of the agent used by UsageMetrics library.

type CloudProperties

type CloudProperties struct {
	ProjectID     string
	Zone          string
	InstanceName  string
	ProjectNumber string
	Image         string
	InstanceID    string
}

CloudProperties contains the properties of the cloud instance used by UsageMetrics library.

type Logger

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

A Logger is used to report the status of the agent to an internal metadata server.

func NewLogger

func NewLogger(agentProps *AgentProperties, cloudProps *CloudProperties, timeSource TimeSource, projectExclusions []string) *Logger

NewLogger creates a new Logger with an initialized hash map of Status to a last called timestamp.

func (*Logger) Action

func (l *Logger) Action(id int)

Action logs the ACTION status.

func (*Logger) Configured

func (l *Logger) Configured()

Configured logs the CONFIGURED status.

func (*Logger) DailyLogRunningStarted

func (l *Logger) DailyLogRunningStarted()

DailyLogRunningStarted logs the RUNNING status.

func (*Logger) Error

func (l *Logger) Error(id int)

Error logs the ERROR status.

func (*Logger) Installed

func (l *Logger) Installed()

Installed logs the INSTALLED status.

func (*Logger) IsDailyLogRunningStarted

func (l *Logger) IsDailyLogRunningStarted() bool

IsDailyLogRunningStarted returns true if DailyLogRunningStarted was previously called.

func (*Logger) LastCalled

func (l *Logger) LastCalled(s Status) time.Time

LastCalled returns the last time a status was called.

func (*Logger) LogStatus

func (l *Logger) LogStatus(s Status, v string)

LogStatus logs the agent status if usage metrics logging is enabled.

func (*Logger) Misconfigured

func (l *Logger) Misconfigured()

Misconfigured logs the MISCONFIGURED status.

func (*Logger) Running

func (l *Logger) Running()

Running logs the RUNNING status.

func (*Logger) SetAgentProps

func (l *Logger) SetAgentProps(ap *AgentProperties)

SetAgentProps sets the agent properties

func (*Logger) SetCloudProps

func (l *Logger) SetCloudProps(cp *CloudProperties)

SetCloudProps sets the cloud properties and ensures that dependent fields are kept in sync.

func (*Logger) Started

func (l *Logger) Started()

Started logs the STARTED status.

func (*Logger) Stopped

func (l *Logger) Stopped()

Stopped logs the STOPPED status.

func (*Logger) Uninstalled

func (l *Logger) Uninstalled()

Uninstalled logs the UNINSTALLED status.

func (*Logger) Updated

func (l *Logger) Updated(version string)

Updated logs the UPDATED status.

type Status

type Status string

Status enumerates the supported usage logging statuses.

const (
	StatusRunning       Status = "RUNNING"
	StatusStarted       Status = "STARTED"
	StatusStopped       Status = "STOPPED"
	StatusConfigured    Status = "CONFIGURED"
	StatusMisconfigured Status = "MISCONFIGURED"
	StatusError         Status = "ERROR"
	StatusInstalled     Status = "INSTALLED"
	StatusUpdated       Status = "UPDATED"
	StatusUninstalled   Status = "UNINSTALLED"
	StatusAction        Status = "ACTION"
)

The following status values are supported.

type TimeSource

type TimeSource interface {
	Now() time.Time
	Since(t time.Time) time.Duration
}

The TimeSource interface is a wrapper around time functionality needed for usage metrics logging. A fake TimeSource can be supplied by tests to ensure test stability.

Jump to

Keyboard shortcuts

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