protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	V1 = 1
	V2 = 2
	V3 = 3
	V4 = 4
)

Protocol Integration versions.

Variables

View Source
var (
	EmptyPayloadErr = errors.New("cannot parse empty integration payload")
)

Errors

View Source
var (
	IntProtocolNotSupportedErr = errors.New("integration protocol version not supported")
)

Functions

func VersionFromPayload

func VersionFromPayload(raw []byte, forceV2ToV3Upgrade bool) (protocolVersion int, err error)

VersionFromPayload determines the protocol version number from integration payload for both inventory and metrics.

func WithAnnotations

func WithAnnotations(a map[string]string) func(EventData)

Builder for NewEventData constructor will add annotations

func WithAttributes

func WithAttributes(a map[string]interface{}) func(EventData)

Builder for NewEventData constructor will add attributes if already exist in the eventData will add it with prefix 'attr.'

func WithEntity

func WithEntity(e entity.Entity) func(EventData)

Builder for NewEventData constructor will add 'entityKey' and 'entityID' keys

func WithEvents

func WithEvents(original EventData) func(EventData)

Builder for NewEventData copying all event fields.

func WithIntegrationUser

func WithIntegrationUser(value string) func(EventData)

Builder for NewEventData constructor will add 'integrationUser' key

func WithLabels

func WithLabels(l map[string]string) func(EventData)

Builder for NewEventData constructor will add labels with prefix 'label.'

Types

type Common

type Common struct {
	Timestamp  *int64                 `json:"timestamp"`
	Interval   *int64                 `json:"interval.ms"`
	Attributes map[string]interface{} `json:"attributes"`
}

type DataV4

type DataV4 struct {
	PluginProtocolVersion
	Integration IntegrationMetadata `json:"integration"`
	DataSets    []Dataset           `json:"data"`
}

func NewData

func NewData(name, version string, ds []Dataset) DataV4

NewData creates a payload from code instead of JSON.

type Dataset

type Dataset struct {
	Common       Common                   `json:"common"`
	Metrics      []Metric                 `json:"metrics"`
	Entity       entity.Fields            `json:"entity"`
	Inventory    map[string]InventoryData `json:"inventory"`
	Events       []EventData              `json:"events"`
	IgnoreEntity bool                     `json:"ignore_entity"`
}

func NewEventDataset

func NewEventDataset(ts int64, event EventData) Dataset

NewEventDataset creates a dataset with jsut a single event.

type EventData

type EventData map[string]interface{}

EventData is the data type for single shot events

func NewEventData

func NewEventData(options ...func(EventData)) (EventData, error)

NewEventData create a new event data from builder func

type IntegrationMetadata

type IntegrationMetadata struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type InventoryData

type InventoryData map[string]interface{}

InventoryData is the data type for inventory data produced by a plugin data source and emitted to the agent's inventory data store

func (InventoryData) SortKey

func (i InventoryData) SortKey() string

type Metric

type Metric struct {
	Name       string                 `json:"name"`
	Type       MetricType             `json:"type"`
	Timestamp  *int64                 `json:"timestamp"`
	Interval   *int64                 `json:"interval.ms"`
	Attributes map[string]interface{} `json:"attributes"`
	Value      json.RawMessage        `json:"value"`
}

func (*Metric) CopyAttrs

func (m *Metric) CopyAttrs() map[string]interface{}

CopyAttrs returns a (shallow) copy of the passed attrs.

func (*Metric) GetPrometheusHistogramValue

func (m *Metric) GetPrometheusHistogramValue() (PrometheusHistogramValue, error)

func (*Metric) GetPrometheusSummaryValue

func (m *Metric) GetPrometheusSummaryValue() (PrometheusSummaryValue, error)

func (*Metric) IntervalDuration

func (m *Metric) IntervalDuration() time.Duration

func (*Metric) NumericValue

func (m *Metric) NumericValue() (float64, error)

func (*Metric) SummaryValue

func (m *Metric) SummaryValue() (SummaryValue, error)

func (*Metric) Time

func (m *Metric) Time() time.Time

Converts timestamp to a Time object, accepting timestamps in both seconds and milliseconds.

type MetricData

type MetricData map[string]interface{}

MetricData is the data type for events produced by a plugin data source and emitted to the agent's metrics data store

type MetricType

type MetricType string
const (
	MetricTypeCount   MetricType = "count"
	MetricTypeSummary MetricType = "summary"
	MetricTypeGauge   MetricType = "gauge"
	MetricTypeRate    MetricType = "rate"

	MetricTypePrometheusSummary   MetricType = "prometheus-summary"
	MetricTypePrometheusHistogram MetricType = "prometheus-histogram"
)

Metric type values

func (MetricType) HasInterval

func (t MetricType) HasInterval() bool

HasInterval does metric type support interval.

type PluginDataSet

type PluginDataSet struct {
	Entity    entity.Fields            `json:"entity"`
	Metrics   []MetricData             `json:"metrics"`
	Inventory map[string]InventoryData `json:"inventory"`
	Events    []EventData              `json:"events"`
	// this is here for backcompat with the SDK, but is ignored
	AddHostname bool `json:"add_hostname"`
}

A collection of data generated by a plugin for a single entity. V2 plugins can produce multiple of these, where V1 produces one per execution.

type PluginDataSetV3

type PluginDataSetV3 struct {
	PluginDataSet
	Cluster string `json:"cluster"`
	Service string `json:"service"`
}

type PluginDataV1

type PluginDataV1 struct {
	PluginOutputIdentifier
	PluginDataSet
}

PluginDataV1 supports a single data set for a single entity

type PluginDataV3

type PluginDataV3 struct {
	PluginOutputIdentifier
	DataSets []PluginDataSetV3 `json:"data"`
}

PluginDataV3 supports an array of data sets, each for a different entity. It's also valid for protocol V2, protocol v3 only adds service & cluster

func ParsePayload

func ParsePayload(raw []byte, protocolVersion int) (dataV3 PluginDataV3, err error)

ParsePayload parses a JSON payload using the integration protocol format. Used for all metrics (events) and inventory.

type PluginOutputIdentifier

type PluginOutputIdentifier struct {
	Name               string      `json:"name"`
	RawProtocolVersion interface{} `json:"protocol_version"` // Left open-ended for validation purposes
	IntegrationVersion string      `json:"integration_version"`
	Status             string      `json:"integration_status"`
}

Basic fields which identify the plugin and the version of its output

type PluginProtocolVersion

type PluginProtocolVersion struct {
	RawProtocolVersion interface{} `json:"protocol_version"` // Left open-ended for validation purposes
}

Minimum information to determine plugin protocol

type PrometheusHistogramValue

type PrometheusHistogramValue struct {
	SampleCount *uint64  `json:"sample_count,omitempty"`
	SampleSum   *float64 `json:"sample_sum,omitempty"`
	// Buckets defines the buckets into which observations are counted. Each
	// element in the slice is the upper inclusive bound of a bucket. The
	// values must are sorted in strictly increasing order.
	Buckets []*bucket `json:"buckets,omitempty"`
}

PrometheusHistogram represents a Prometheus histogram

type PrometheusSummaryValue

type PrometheusSummaryValue struct {
	SampleCount float64    `json:"sample_count,omitempty"`
	SampleSum   float64    `json:"sample_sum,omitempty"`
	Quantiles   []quantile `json:"quantiles,omitempty"`
}

PrometheusSummary represents a Prometheus summary

type SummaryValue

type SummaryValue struct {
	Count float64 `json:"count"`
	Min   float64 `json:"min"`
	Max   float64 `json:"max"`
	Sum   float64 `json:"sum"`
}

Jump to

Keyboard shortcuts

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