collectiondefinition

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package collectiondefinition provides utility functions for managing the CollectionDefinition protobuf objects that are used to define a set of configurable metrics that are collected by the Agent for SAP.

Index

Constants

View Source
const (
	// LinuxConfigPath is the path to the customer-defined collection definition file on Linux.
	LinuxConfigPath = `/etc/google-cloud-sap-agent/collection-definition.json`
	// WindowsConfigPath is the path to the customer-defined collection definition file on Windows.
	WindowsConfigPath = `C:\Program Files\Google\google-cloud-sap-agent\conf\collection-definition.json`
)

Variables

This section is empty.

Functions

func FromJSONFile

func FromJSONFile(read ReadFile, path string) (*cdpb.CollectionDefinition, error)

FromJSONFile reads a CollectionDefinition JSON configuration file and unmarshals the data into a CollectionDefinition proto.

func Load

Load prepares a definitive CollectionDefinition ready for use by Agent for SAP services.

The process of loading a collection definition involves the following steps:

  1. Retrieve the default CollectionDefinition for the agent.
  2. Retrieve the configurable CollectionDefinition from the local filesystem.
  3. Merge the two definitions, giving preference to the agent defaults.
  4. Validate the merged CollectionDefinition and log any errors found.

func Merge

func Merge(primary, secondary *cdpb.CollectionDefinition) (merged *cdpb.CollectionDefinition)

Merge produces a CollectionDefinition which is the result of combining a primary definition with additional metric fields specified in a secondary definition.

Said another way, Merge returns a result that is similar to the secondary definition overlayed by the primary definition. The dimension of uniqueness that will be used to compare metrics between the primary and secondary definitions is the composite value of metric type and label. In the event that a particular type + label combination exists in both the primary and secondary definition, then the primary definition for this metric will take precedence, the secondary definition for this metric will be ignored, and a warning will be reported in the agent log file.

Types

type LoadOptions

type LoadOptions struct {
	ReadFile ReadFile
	OSType   string
	Version  string
}

LoadOptions define the parameters required to load a collection definition.

type ReadFile

type ReadFile func(string) ([]byte, error)

ReadFile abstracts the os.ReadFile function for testability.

type ValidationError

type ValidationError struct {
	FailureCount int
}

A ValidationError should be thrown when validation of a CollectionDefinition fails.

func (ValidationError) Error

func (e ValidationError) Error() string

type Validator

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

A Validator holds information necessary for validating a CollectionDefinition.

A Validator should be instantiated using NewValidator() and supplying the agent version and a CollectionDefinition to be validated. Validation is performed by invoking the Validate() method, and the state of the validation can be obtained by invoking the Valid() method to get a boolean result, or the FailureCount() method to get a total number of validation failures. Information regarding each validation failure is output to a log file.

func NewValidator

func NewValidator(version string, collectionDefinition *cdpb.CollectionDefinition) *Validator

NewValidator instantiates Validator for a CollectionDefinition.

func (Validator) FailureCount

func (v Validator) FailureCount() int

FailureCount returns the number of validation failures in the CollectionDefinition.

func (Validator) Valid

func (v Validator) Valid() bool

Valid returns true if the CollectionDefinition has been successfully validated, false otherwise.

func (*Validator) Validate

func (v *Validator) Validate()

Validate checks that a CollectionDefinition is well-formed. (i.e. are there any issues in the definition which would interfere with metric collection.)

The validations performed in this function will be aimed at preventing runtime errors in the agent. Any issues found during validation will be reported in the agent log file. The following validations will be performed:

  • Each metric should have a type and a label specified.
  • Metric type+label should be unique for all metrics within the definition.
  • An OSCommandMetric may reuse a metric type+label if os_vendor is distinct for each entry.
  • A metric should not have a min_version that exceeds the agent version.
  • Regular expressions should compile.
  • A metric should always provide accompanying evaluation rule(s).
  • An evaluation rule should always provide a value to use if true.
  • An OSCommandMetric should always provide a command to run.

Jump to

Keyboard shortcuts

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