common

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Overview

Package common contains all of logic that is shared between trace and logs packages. The main concern of this package is to format Hubble flow data using OpenTelemetry structures. A few different formats are implemented to make it easier to optimise the data for different OpenTelemetry backends, e.g. some backends accept arbitrarily nested data, while others only handle flat maps. This package also implements conversion of label and HTTP headers to maps, which makes it easier to query data by label or by header in most of the backends.

Index

Constants

View Source
const (
	OTelAttrHTTPMethod     = "http.method"
	OTelAttrHTTPURL        = "http.url"
	OTelAttrHTTPFlavor     = "http.flavor"
	OTelAttrHTTPHost       = "http.host"
	OTelAttrHTTPUserAgent  = "http.user_agent"
	OTelAttrHTTPStatusCode = "http.status_code"

	OTelAttrHTTPRequestHeader  = "http.request.header."
	OTelAttrHTTPResponseHeader = "http.response.header."
)
View Source
const (
	OTelAttrK8sNodeName      = "k8s.node.name"
	OTelAttrK8sNamespaceName = "k8s.namespace.name"
	OTelAttrK8sPodName       = "k8s.pod.name"
)
View Source
const (
	OTelAttrServiceName      = "service.name"
	OTelAttrServiceNamespace = "service.namespace"

	OTelAttrServiceNameDefaultPrefix = "hubble-otel-unknown"
)
View Source
const (
	AttributeEventKindVersion     = keyNamespaceCilium + "event_kind"
	AttributeEventEncoding        = keyNamespaceCilium + "event_encoding"
	AttributeEventEncodingOptions = keyNamespaceCilium + "event_encoding_options"

	AttributeEventKindVersionFlowV1alpha1 = "flow/v1alpha2"

	// in order to comply with the spec, cilium.flow_event is used with flat maps,
	// and cilium.event_object is used to hold JSON-encoded or nested payloads,
	// so that namespace and standalone key collision is avoided
	AttributeFlowEventNamespace = keyNamespaceCilium + "flow_event"
	AttributeEventObject        = keyNamespaceCilium + "event_object"

	AttributeEventDescription = keyNamespaceCilium + "event_description"

	DefaultLogEncoding       = EncodingTypedMap
	DefaultTraceEncoding     = EncodingFlatStringMap
	EncodingJSON             = "JSON"
	EncodingJSONBASE64       = "JSON+base64"
	EncodingFlatStringMap    = "FlatStringMap"
	EncodingSemiFlatTypedMap = "SemiFlatTypedMap"
	EncodingTypedMap         = "TypedMap"
)

Variables

This section is empty.

Functions

func EncodingFormatsForLogs

func EncodingFormatsForLogs() []string

func EncodingFormatsForTraces

func EncodingFormatsForTraces() []string

func GetAllResourceAttributes

func GetAllResourceAttributes(flow *flowV1.Flow, fallbackServiceNamePrefix string) (resourceAttributes []*commonV1.KeyValue)

func GetHTTPAttributes

func GetHTTPAttributes(l7 *flowV1.Layer7) []*commonV1.KeyValue

func GetKubernetesAttributes

func GetKubernetesAttributes(flow *flowV1.Flow) []*commonV1.KeyValue

func GetServiceAttributes

func GetServiceAttributes(flow *flowV1.Flow, fallbackServiceNamePrefix string) []*commonV1.KeyValue

func MarshalJSON

func MarshalJSON(m proto.Message) ([]byte, error)

func NewStringAttributes

func NewStringAttributes(attributes map[string]string) []*commonV1.KeyValue

func NormaliseHeaderKey

func NormaliseHeaderKey(k string) string

func RunConverter

func RunConverter(ctx context.Context, hubbleConn *grpc.ClientConn, c Converter, flows chan<- protoreflect.Message, errs chan<- error, opts ...grpc.CallOption)

func RunExporter

func RunExporter(ctx context.Context, log *logrus.Logger, s Exporter, flows <-chan protoreflect.Message, errs chan<- error)

Types

type Converter

type Converter interface {
	Convert(*observer.GetFlowsResponse) (protoreflect.Message, error)
	InclusionFilter() []*flowV1.FlowFilter
}

type EncodingOptions

type EncodingOptions struct {
	Encoding         *string `mapstructure:"encoding"`
	TopLevelKeys     *bool   `mapstructure:"top_level_keys"`
	LabelsAsMaps     *bool   `mapstructure:"labels_as_maps"`
	HeadersAsMaps    *bool   `mapstructure:"headers_as_maps"`
	LogPayloadAsBody *bool   `mapstructure:"log_payload_as_body"`
}

func (*EncodingOptions) EncodingFormat

func (o *EncodingOptions) EncodingFormat() string

func (*EncodingOptions) String

func (o *EncodingOptions) String() string

func (*EncodingOptions) ValidForLogs

func (o *EncodingOptions) ValidForLogs() error

func (*EncodingOptions) ValidForTraces

func (o *EncodingOptions) ValidForTraces() error

func (*EncodingOptions) WithHeadersAsMaps

func (o *EncodingOptions) WithHeadersAsMaps() bool

func (*EncodingOptions) WithLabelsAsMaps

func (o *EncodingOptions) WithLabelsAsMaps() bool

func (*EncodingOptions) WithLogPayloadAsBody

func (o *EncodingOptions) WithLogPayloadAsBody() bool

func (*EncodingOptions) WithTopLevelKeys

func (o *EncodingOptions) WithTopLevelKeys() bool

type Exporter

type Exporter interface {
	Export(context.Context, <-chan protoreflect.Message) error
}

type FlowEncoder

type FlowEncoder struct {
	*EncodingOptions
	*IncludeFlowTypes

	Logger *logrus.Logger
}

func (*FlowEncoder) InclusionFilter

func (fe *FlowEncoder) InclusionFilter() []*flowV1.FlowFilter

func (*FlowEncoder) ToValue

func (c *FlowEncoder) ToValue(hubbleResp *observer.GetFlowsResponse) (*commonV1.AnyValue, error)

type IncludeFlowTypes

type IncludeFlowTypes []string

func (IncludeFlowTypes) MakeFilters

func (it IncludeFlowTypes) MakeFilters() []*flowV1.FlowFilter

func (IncludeFlowTypes) Validate

func (it IncludeFlowTypes) Validate() error

type NullExporter

type NullExporter struct{}

func (*NullExporter) Export

func (s *NullExporter) Export(ctx context.Context, flows <-chan protoreflect.Message) error

Jump to

Keyboard shortcuts

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