profiledefinition

package
v0.63.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

Generate Json Schema

cd pkg/networkdevice/profile/profiledefinition/schema_cmd
go generate

The command above will generate this jsonschema file profiledefinition/schema/profile_rc_schema.json.

Documentation

Overview

Package profiledefinition contain the structure used to parse SNMP Profiles

Index

Constants

View Source
const MetadataDeviceResource = "device"

MetadataDeviceResource is the device resource name

Variables

This section is empty.

Functions

func IsMetadataResourceWithScalarOids

func IsMetadataResourceWithScalarOids(resource string) bool

IsMetadataResourceWithScalarOids returns true if the resource is based on scalar OIDs at the moment, we only expect "device" resource to be based on scalar OIDs

func NormalizeMetrics

func NormalizeMetrics(metrics []MetricsConfig)

NormalizeMetrics converts legacy syntax to new syntax 1/ converts old symbol syntax to new symbol syntax metric.Name and metric.OID info are moved to metric.Symbol.Name and metric.Symbol.OID

Types

type DeviceMeta

type DeviceMeta struct {
	// deprecated in favour of new `ProfileDefinition.Metadata` syntax
	Vendor string `yaml:"vendor,omitempty" json:"vendor,omitempty"`
}

DeviceMeta holds device related static metadata DEPRECATED in favour of profile metadata syntax

type DeviceProfileRcConfig

type DeviceProfileRcConfig struct {
	Profile ProfileDefinition `json:"profile_definition"`
}

DeviceProfileRcConfig represent the profile stored in remote config.

type ListMap

type ListMap[T any] map[string]T

ListMap is used to marshall a map into a list (map[string]T to []MapItem[T]) and vice versa.

func (ListMap[T]) JSONSchema

func (lm ListMap[T]) JSONSchema() *jsonschema.Schema

JSONSchema is needed to customize jsonschema to match []MapItem[T] used in json format

func (ListMap[T]) MarshalJSON

func (lm ListMap[T]) MarshalJSON() ([]byte, error)

MarshalJSON marshalls map to list

func (*ListMap[T]) UnmarshalJSON

func (lm *ListMap[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshalls list to map

type MapItem

type MapItem[T any] struct {
	Key   string `json:"key"`
	Value T      `json:"value"`
}

MapItem is used for ListMap marshalling/unmarshalling

type MetadataConfig

type MetadataConfig ListMap[MetadataResourceConfig]

MetadataConfig holds configs per resource type

func (MetadataConfig) JSONSchema

func (mc MetadataConfig) JSONSchema() *jsonschema.Schema

JSONSchema defines the JSON schema for MetadataConfig

func (MetadataConfig) MarshalJSON

func (mc MetadataConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals the metadata config

func (*MetadataConfig) UnmarshalJSON

func (mc *MetadataConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the metadata config

type MetadataField

type MetadataField struct {
	Symbol  SymbolConfig   `yaml:"symbol,omitempty" json:"symbol,omitempty"`
	Symbols []SymbolConfig `yaml:"symbols,omitempty" json:"symbols,omitempty"`
	Value   string         `yaml:"value,omitempty" json:"value,omitempty"`
}

MetadataField holds configs for a metadata field

type MetadataResourceConfig

type MetadataResourceConfig struct {
	Fields ListMap[MetadataField] `yaml:"fields" json:"fields"`
	IDTags MetricTagConfigList    `yaml:"id_tags,omitempty" json:"id_tags,omitempty"`
}

MetadataResourceConfig holds configs for a metadata resource

func NewMetadataResourceConfig

func NewMetadataResourceConfig() MetadataResourceConfig

NewMetadataResourceConfig returns a new metadata resource config

type MetricIndexTransform

type MetricIndexTransform struct {
	Start uint `yaml:"start" json:"start"`
	End   uint `yaml:"end" json:"end"`
}

MetricIndexTransform holds configs for metric index transform

type MetricTagConfig

type MetricTagConfig struct {
	Tag string `yaml:"tag" json:"tag"`

	// Table config
	Index uint `yaml:"index,omitempty" json:"index,omitempty"`

	// DEPRECATED: Use .Symbol instead
	Column SymbolConfig `yaml:"column,omitempty" json:"-"`

	// DEPRECATED: use .Symbol instead
	OID string `yaml:"OID,omitempty" json:"-"  jsonschema:"-"`
	// Symbol records the OID to be parsed. Note that .Symbol.Name is ignored:
	// set .Tag to specify the tag name. If a serialized Symbol is a string
	// instead of an object, it will be treated like {name: <value>}; this use
	// pattern is deprecated
	Symbol SymbolConfigCompat `yaml:"symbol,omitempty" json:"symbol,omitempty"`

	IndexTransform []MetricIndexTransform `yaml:"index_transform,omitempty" json:"index_transform,omitempty"`

	Mapping ListMap[string] `yaml:"mapping,omitempty" json:"mapping,omitempty"`

	// Regex
	// Match/Tags are not exposed as json (UI) since ExtractValue can be used instead
	Match   string            `yaml:"match,omitempty" json:"-"`
	Tags    map[string]string `yaml:"tags,omitempty" json:"-"`
	Pattern *regexp.Regexp    `yaml:"-" json:"-"`

	SymbolTag string `yaml:"-" json:"-"`
}

MetricTagConfig holds metric tag info

type MetricTagConfigList

type MetricTagConfigList []MetricTagConfig

MetricTagConfigList holds configs for a list of metric tags

func (*MetricTagConfigList) UnmarshalYAML

func (mtcl *MetricTagConfigList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls MetricTagConfigList

type MetricsConfig

type MetricsConfig struct {
	// MIB the MIB used for this metric
	MIB string `yaml:"MIB,omitempty" json:"MIB,omitempty"`

	// Table the table OID
	Table SymbolConfig `yaml:"table,omitempty" json:"table,omitempty"`

	// Symbol configs
	Symbol SymbolConfig `yaml:"symbol,omitempty" json:"symbol,omitempty"`

	// DEPRECATED: Use .Symbol instead
	OID string `yaml:"OID,omitempty" json:"OID,omitempty" jsonschema:"-"`
	// DEPRECATED: Use .Symbol instead
	Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"-"`

	// Table configs
	Symbols []SymbolConfig `yaml:"symbols,omitempty" json:"symbols,omitempty"`

	// `static_tags` is not exposed as json at the moment since we need to evaluate if we want to expose it via UI
	StaticTags []string            `yaml:"static_tags,omitempty" json:"-"`
	MetricTags MetricTagConfigList `yaml:"metric_tags,omitempty" json:"metric_tags,omitempty"`

	// DEPRECATED: use MetricType instead.
	ForcedType ProfileMetricType `yaml:"forced_type,omitempty" json:"forced_type,omitempty" jsonschema:"-"`
	MetricType ProfileMetricType `yaml:"metric_type,omitempty" json:"metric_type,omitempty"`

	Options MetricsConfigOption `yaml:"options,omitempty" json:"options,omitempty"`
}

MetricsConfig holds configs for a metric

func (*MetricsConfig) GetSymbolTags

func (m *MetricsConfig) GetSymbolTags() []string

GetSymbolTags returns symbol tags

func (*MetricsConfig) IsColumn

func (m *MetricsConfig) IsColumn() bool

IsColumn returns true if the metrics config define columns metrics

func (*MetricsConfig) IsScalar

func (m *MetricsConfig) IsScalar() bool

IsScalar returns true if the metrics config define scalar metrics

type MetricsConfigOption

type MetricsConfigOption struct {
	Placement    uint   `yaml:"placement,omitempty" json:"placement,omitempty"`
	MetricSuffix string `yaml:"metric_suffix,omitempty" json:"metric_suffix,omitempty"`
}

MetricsConfigOption holds config for metrics options

type ProfileBundle added in v0.50.0

type ProfileBundle struct {
	CreatedTimestamp int64                      `json:"created_timestamp"` // Millisecond
	Profiles         []ProfileBundleProfileItem `json:"profiles"`
}

ProfileBundle represent a list of profiles meant to be downloaded by user.

type ProfileBundleProfileItem added in v0.50.0

type ProfileBundleProfileItem struct {
	Profile ProfileDefinition `json:"profile"`
}

ProfileBundleProfileItem represent a profile entry with metadata.

type ProfileDefinition

type ProfileDefinition struct {
	Name         string            `yaml:"name" json:"name"`
	Description  string            `yaml:"description,omitempty" json:"description,omitempty"`
	SysObjectIDs StringArray       `yaml:"sysobjectid,omitempty" json:"sysobjectid,omitempty"`
	Extends      []string          `yaml:"extends,omitempty" json:"extends,omitempty"`
	Metadata     MetadataConfig    `yaml:"metadata,omitempty" json:"metadata,omitempty"`
	MetricTags   []MetricTagConfig `yaml:"metric_tags,omitempty" json:"metric_tags,omitempty"`
	StaticTags   []string          `yaml:"static_tags,omitempty" json:"static_tags,omitempty"`
	Metrics      []MetricsConfig   `yaml:"metrics,omitempty" json:"metrics,omitempty"`

	// DEPRECATED: Use metadata directly
	Device DeviceMeta `yaml:"device,omitempty" json:"device,omitempty" jsonschema:"device,omitempty"`

	// Version is the profile version.
	// It is currently used only with downloaded/RC profiles.
	Version uint64 `yaml:"version,omitempty" json:"version"`
}

ProfileDefinition is the root profile structure. The ProfileDefinition is currently used in: 1/ SNMP Integration: the profiles are in yaml profiles. Yaml profiles include default datadog profiles and user custom profiles. The serialisation of yaml profiles are defined by the yaml annotation and few custom unmarshaller (see yaml_utils.go). 2/ Datadog backend: the profiles are in json format, they are used to store profiles created via UI. The serialisation of json profiles are defined by the json annotation.

func NewProfileDefinition

func NewProfileDefinition() *ProfileDefinition

NewProfileDefinition creates a new ProfileDefinition

func (*ProfileDefinition) GetVendor

func (p *ProfileDefinition) GetVendor() string

GetVendor returns the static vendor for this profile, if one is set

func (*ProfileDefinition) SplitOIDs

func (p *ProfileDefinition) SplitOIDs(includeMetadata bool) ([]string, []string)

SplitOIDs returns two slices (scalars, columns) of all scalar and column OIDs requested by this profile.

type ProfileMetricType

type ProfileMetricType string

ProfileMetricType metric type used to override default type of the metric By default metric type is derived from the type of the SNMP value, for example Counter32/64 -> rate.

const (
	// ProfileMetricTypeGauge is used to create a gauge metric
	ProfileMetricTypeGauge ProfileMetricType = "gauge"

	// ProfileMetricTypeMonotonicCount is used to create a monotonic_count metric
	ProfileMetricTypeMonotonicCount ProfileMetricType = "monotonic_count"

	// ProfileMetricTypeMonotonicCountAndRate is used to create a monotonic_count and rate metric
	ProfileMetricTypeMonotonicCountAndRate ProfileMetricType = "monotonic_count_and_rate"

	// ProfileMetricTypeRate is used to create a rate metric
	ProfileMetricTypeRate ProfileMetricType = "rate"

	// ProfileMetricTypeFlagStream is used to create metric based on a value that represent flags
	// See details in https://github.com/DataDog/integrations-core/pull/7072
	ProfileMetricTypeFlagStream ProfileMetricType = "flag_stream"

	// ProfileMetricTypeCounter is DEPRECATED
	// `counter` is deprecated in favour of `rate`
	ProfileMetricTypeCounter ProfileMetricType = "counter"

	// ProfileMetricTypePercent is DEPRECATED
	// `percent` is deprecated in favour of `scale_factor`
	ProfileMetricTypePercent ProfileMetricType = "percent"
)

type StringArray

type StringArray []string

StringArray is list of string with a yaml un-marshaller that support both array and string. See test file for example usage. Credit: https://github.com/go-yaml/yaml/issues/100#issuecomment-324964723

func (*StringArray) UnmarshalYAML

func (a *StringArray) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls StringArray

type SymbolConfig

type SymbolConfig struct {
	OID  string `yaml:"OID,omitempty" json:"OID,omitempty"`
	Name string `yaml:"name,omitempty" json:"name,omitempty"`

	ExtractValue         string         `yaml:"extract_value,omitempty" json:"extract_value,omitempty"`
	ExtractValueCompiled *regexp.Regexp `yaml:"-" json:"-"`

	// MatchPattern/MatchValue are not exposed as json (UI) since ExtractValue can be used instead
	MatchPattern         string         `yaml:"match_pattern,omitempty" json:"-"`
	MatchValue           string         `yaml:"match_value,omitempty" json:"-"`
	MatchPatternCompiled *regexp.Regexp `yaml:"-" json:"-"`

	ScaleFactor      float64 `yaml:"scale_factor,omitempty" json:"scale_factor,omitempty"`
	Format           string  `yaml:"format,omitempty" json:"format,omitempty"`
	ConstantValueOne bool    `yaml:"constant_value_one,omitempty" json:"constant_value_one,omitempty"`

	// `metric_type` is used for force the metric type
	//   When empty, by default, the metric type is derived from SNMP OID value type.
	//   Valid `metric_type` types: `gauge`, `rate`, `monotonic_count`, `monotonic_count_and_rate`
	//   Deprecated types: `counter` (use `rate` instead), percent (use `scale_factor` instead)
	MetricType ProfileMetricType `yaml:"metric_type,omitempty" json:"metric_type,omitempty"`
}

SymbolConfig holds info for a single symbol/oid

type SymbolConfigCompat added in v0.50.0

type SymbolConfigCompat SymbolConfig

SymbolConfigCompat is used to deserialize string field or SymbolConfig. For OID/Name to Symbol harmonization: When users declare metric tag like:

metric_tags:
  - OID: 1.2.3
    symbol: aSymbol

this will lead to OID stored as MetricTagConfig.OID and name stored as MetricTagConfig.Symbol.Name When this happens, in ValidateEnrichMetricTags we harmonize by moving MetricTagConfig.OID to MetricTagConfig.Symbol.OID.

func (*SymbolConfigCompat) UnmarshalYAML added in v0.50.0

func (a *SymbolConfigCompat) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls SymbolConfig

Directories

Path Synopsis
Package schema contain json schema related code
Package schema contain json schema related code
Package main holds main related files
Package main holds main related files

Jump to

Keyboard shortcuts

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