graph

package
v1.65.9 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 15 Imported by: 56

Documentation

Overview

Graph package provides support for the graph handlers such as supported path variables and query params, as well as types for graph processing.

Index

Constants

View Source
const (
	VendorCytoscape string = "cytoscape"
	VendorIstio     string = "istio"
)

The supported vendors

View Source
const (
	BoxByApp       string = "app"
	BoxByCluster   string = "cluster"
	BoxByNamespace string = "namespace"
	BoxByNone      string = "none"
	RateNone       string = "none"
	RateReceived   string = "received" // tcp bytes received, grpc response messages, etc
	RateRequests   string = "requests" // request count
	RateSent       string = "sent"     // tcp bytes sent, grpc request messages, etc
	RateTotal      string = "total"    // Sent+Received

)
View Source
const (
	BlackHoleCluster      string = "BlackHoleCluster"
	GraphTypeApp          string = "app"
	GraphTypeService      string = "service" // Treated as graphType Workload, with service injection, and then condensed
	GraphTypeVersionedApp string = "versionedApp"
	GraphTypeWorkload     string = "workload"
	NodeTypeAggregate     string = "aggregate" // The special "aggregate" traffic node
	NodeTypeApp           string = "app"
	NodeTypeBox           string = "box" // The special "box" node. isBox will be set to "app" | "cluster" | "namespace"
	NodeTypeService       string = "service"
	NodeTypeUnknown       string = "unknown" // The special "unknown" traffic gen node
	NodeTypeWorkload      string = "workload"
	PassthroughCluster    string = "PassthroughCluster"
	TF                    string = "2006-01-02 15:04:05" // TF is the TimeFormat for timestamps
	Unknown               string = "unknown"             // Istio unknown label value
)

Variables

View Source
var GRPC = Protocol{
	Name: grpc,
	EdgeRates: []Rate{
		{Name: grpc, IsTotal: true, Precision: 2},
		{Name: grpcNoResponse, IsErr: true, Precision: 2},
		{Name: grpcErr, IsErr: true, Precision: 2},
		{Name: grpcPercentErr, IsPercentErr: true, Precision: 1},
		{Name: grpcPercentReq, IsPercentReq: true, Precision: 1},
	},
	EdgeResponses: grpcResponses,
	NodeRates: []Rate{
		{Name: grpcIn, IsIn: true, Precision: 2},
		{Name: grpcInNoResponse, IsErr: true, Precision: 2},
		{Name: grpcInErr, IsErr: true, Precision: 2},
		{Name: grpcOut, IsOut: true, Precision: 2},
	},
	Unit:      requestsPerSecond,
	UnitShort: rps,
}
View Source
var HTTP = Protocol{
	Name: http,
	EdgeRates: []Rate{
		{Name: http, IsTotal: true, Precision: 2},
		{Name: httpNoResponse, IsErr: true, Precision: 2},
		{Name: http3xx, Precision: 2},
		{Name: http4xx, IsErr: true, Precision: 2},
		{Name: http5xx, IsErr: true, Precision: 2},
		{Name: httpPercentErr, IsPercentErr: true, Precision: 1},
		{Name: httpPercentReq, IsPercentReq: true, Precision: 1},
	},
	EdgeResponses: httpResponses,
	NodeRates: []Rate{
		{Name: httpIn, IsIn: true, Precision: 2},
		{Name: httpInNoResponse, IsErr: true, Precision: 2},
		{Name: httpIn3xx, Precision: 2},
		{Name: httpIn4xx, IsErr: true, Precision: 2},
		{Name: httpIn5xx, IsErr: true, Precision: 2},
		{Name: httpOut, IsOut: true, Precision: 2},
	},
	Unit:      requestsPerSecond,
	UnitShort: rps,
}
View Source
var Protocols = []Protocol{GRPC, HTTP, TCP}

Protocols defines the supported protocols to be handled by the vendor code.

View Source
var TCP = Protocol{
	Name: tcp,
	EdgeRates: []Rate{
		{Name: tcp, IsTotal: true, Precision: 2},
	},
	EdgeResponses: tcpResponses,
	NodeRates: []Rate{
		{Name: tcpIn, IsIn: true, Precision: 2},
		{Name: tcpOut, IsOut: true, Precision: 2},
	},
	Unit:      bytesPerSecond,
	UnitShort: bps,
}

Functions

func AddOutgoingEdgeToMetadata added in v0.14.0

func AddOutgoingEdgeToMetadata(sourceMetadata, edgeMetadata Metadata)

AddOutgoingEdgeToMetadata updates the source node's outgoing traffic with the outgoing edge traffic value

func AddToMetadata added in v0.14.0

func AddToMetadata(protocol string, val float64, code, flags, host string, sourceMetadata, destMetadata, edgeMetadata Metadata)

AddToMetadata takes a single traffic value and adds it appropriately as source, dest and edge traffic

func AggregateEdgeTraffic added in v1.0.0

func AggregateEdgeTraffic(edge, aggregateEdge *Edge)

AggregateEdgeTraffic is for aggregating edge traffic when reducing multiple edges into one edge (e.g. when generating service graph from workload graph, or aggregating serviceEntry nodes).

func AggregateID added in v1.21.0

func AggregateID(cluster, namespace, aggregate, aggregateVal, svcName string) (id string)

AggregateID returns the unique node ID

func AggregateNodeTraffic added in v1.0.0

func AggregateNodeTraffic(node, aggregateNode *Node)

AggregateNodeTraffic adds all <nodeMetadata> values (for all protocols) into aggregateNodeMetadata.

func BadRequest added in v0.12.0

func BadRequest(message string)

BadRequest panics with BadRequest and the provided message

func CheckError added in v0.12.0

func CheckError(err error)

CheckError panics with the supplied error if it is non-nil

func CheckUnavailable added in v1.35.0

func CheckUnavailable(err error)

CheckUnavailable panics with StatusServiceUnavailable (503) and the supplied error if it is non-nil

func Error added in v0.12.0

func Error(message string)

Error panics with InternalServerError (500) and the provided message

func Forbidden added in v0.12.0

func Forbidden(message string)

Forbidden panics with Forbidden and the provided message

func Id

func Id(cluster, serviceNamespace, service, workloadNamespace, workload, app, version, graphType string) (id, nodeType string, err error)

Id returns the unique node ID

func IsGRPCErr added in v1.12.1

func IsGRPCErr(code string) bool

IsGRPCErr return true if code != 0

func IsHTTPErr added in v1.12.1

func IsHTTPErr(code string) bool

IsHTTPErr return true if code is 4xx or 5xx

func IsOK added in v0.12.0

func IsOK(telemetryVal string) bool

IsOK just validates that a telemetry label value is not empty or unknown

func IsOKVersion added in v1.32.0

func IsOKVersion(telemetryVal string) bool

IsOKVersion does standard validation and also rejects "latest", which is equivalent to "unknown" when using canonical_revision

func ResetOutgoingMetadata added in v1.12.6

func ResetOutgoingMetadata(sourceMetadata Metadata)

ResetOutgoingMetadata sets outgoing traffic to zero. This is useful for some graph type manipulations.

Types

type Appender added in v0.21.0

type Appender interface {
	// AppendGraph performs the appender work on the provided traffic map. The map may be initially empty.
	// An appender is allowed to add or remove map entries. namespaceInfo will be nil for Finalizer appenders.
	AppendGraph(trafficMap TrafficMap, globalInfo *AppenderGlobalInfo, namespaceInfo *AppenderNamespaceInfo)

	// IsFinalizer returns true if the appender should run only on the final TrafficMap, or false if the appender should
	// run against every requested namespace.
	IsFinalizer() bool

	// Name returns a unique appender name and which is the name used to identify the appender (e.g in 'appenders' query param)
	Name() string
}

Appender is implemented by any code offering to append a service graph with supplemental information. On error the appender should panic and it will be handled as an error response.

type AppenderGlobalInfo added in v0.21.0

type AppenderGlobalInfo struct {
	Business    *business.Layer
	Context     context.Context
	HomeCluster string
	PromClient  *prometheus.Client
	Vendor      AppenderVendorInfo // telemetry vendor's global info
}

AppenderGlobalInfo caches information relevant to a single graph. It allows an appender to populate the cache and then it, or another appender can re-use the information. A new instance is generated for graph and is initially empty.

func NewAppenderGlobalInfo added in v0.21.0

func NewAppenderGlobalInfo() *AppenderGlobalInfo

type AppenderNamespaceInfo added in v0.21.0

type AppenderNamespaceInfo struct {
	Namespace string             // always provided
	Vendor    AppenderVendorInfo // telemetry vendor's namespace info
}

AppenderNamespaceInfo caches information relevant to a single namespace. It allows one appender to populate the cache and another to then re-use the information. A new instance is generated for each namespace of a single graph and is initially seeded with only Namespace.

func NewAppenderNamespaceInfo added in v0.21.0

func NewAppenderNamespaceInfo(namespace string) *AppenderNamespaceInfo

type AppenderVendorInfo added in v0.21.0

type AppenderVendorInfo map[string]interface{}

func NewAppenderVendorInfo added in v0.21.0

func NewAppenderVendorInfo() AppenderVendorInfo

type CommonOptions added in v0.21.0

type CommonOptions struct {
	Duration  time.Duration
	GraphType string
	Params    url.Values // make available the raw query params for vendor-specific handling
	QueryTime int64      // unix time in seconds
}

CommonOptions are those supplied to Telemetry and Config Vendors

type ConfigOptions added in v0.21.0

type ConfigOptions struct {
	BoxBy string
	CommonOptions
}

ConfigOptions are those supplied to Config Vendors

type ConfigVendor added in v0.21.0

type ConfigVendor interface {

	// NewConfig is required by the ConfigVendor interface.  It must produce a valid
	// Config for the provided TrafficMap, It is recommended to use the graph/util.go
	// definitions for error handling. Refer to the Cytoscape implementation as an example.
	NewConfig(trafficMap TrafficMap, o ConfigOptions) interface{}
}

ConfigVendor is an interface that must be satisfied for each config vendor implementation.

type DestServicesMetadata added in v1.0.0

type DestServicesMetadata map[string]ServiceName

DestServicesMetadata key=Service.Key()

func NewDestServicesMetadata added in v1.0.0

func NewDestServicesMetadata() DestServicesMetadata

NewDestServicesMetadata returns an empty DestServicesMetadata map

func (DestServicesMetadata) Add added in v1.0.0

Add adds or replaces a destService

type Edge

type Edge struct {
	Source   *Node
	Dest     *Node
	Metadata Metadata // app-specific data
}

func NewEdge

func NewEdge(source, dest *Node) Edge

NewEdge constructor

type GatewaysMetadata added in v1.38.1

type GatewaysMetadata map[string][]string

type LabelsMetadata added in v1.48.0

type LabelsMetadata map[string]string

type Metadata added in v0.21.0

type Metadata map[MetadataKey]interface{}

Metadata is a map for storing node and edge metadata values reported by the vendors

func NewMetadata added in v0.21.0

func NewMetadata() Metadata

NewMetadata returns an empty Metadata map

type MetadataKey added in v0.21.0

type MetadataKey string

MetadataKey is a mnemonic type name for string

const (
	Aggregate             MetadataKey = "aggregate" // the prom attribute used for aggregation
	AggregateValue        MetadataKey = "aggregateValue"
	DestPrincipal         MetadataKey = "destPrincipal"
	DestServices          MetadataKey = "destServices"
	HealthData            MetadataKey = "healthData"
	HealthDataApp         MetadataKey = "healthDataApp" // for storing app health on versioned app nodes
	HasCB                 MetadataKey = "hasCB"
	HasFaultInjection     MetadataKey = "hasFaultInjection"
	HasHealthConfig       MetadataKey = "hasHealthConfig"
	HasMirroring          MetadataKey = "hasMirroring"
	HasMissingSC          MetadataKey = "hasMissingSC"
	HasTCPTrafficShifting MetadataKey = "hasTCPTrafficShifting"
	HasTrafficShifting    MetadataKey = "hasTrafficShifting"
	HasRequestRouting     MetadataKey = "hasRequestRouting"
	HasRequestTimeout     MetadataKey = "hasRequestTimeout"
	HasVS                 MetadataKey = "hasVS"
	HasWorkloadEntry      MetadataKey = "hasWorkloadEntry"
	IsDead                MetadataKey = "isDead"
	IsEgressCluster       MetadataKey = "isEgressCluster"  // PassthroughCluster or BlackHoleCluster
	IsEgressGateway       MetadataKey = "isEgressGateway"  // Identifies a node that is an Istio egress gateway
	IsGatewayAPI          MetadataKey = "isGatewayAPI"     // Identifies a node that is a Gateway API gateway (ingress)
	IsIngressGateway      MetadataKey = "isIngressGateway" // Identifies a node that is an Istio ingress gateway
	IsIdle                MetadataKey = "isIdle"
	IsInaccessible        MetadataKey = "isInaccessible"
	IsMTLS                MetadataKey = "isMTLS"
	IsOutside             MetadataKey = "isOutside"
	IsRoot                MetadataKey = "isRoot"
	IsServiceEntry        MetadataKey = "isServiceEntry"
	Labels                MetadataKey = "labels"
	ProtocolKey           MetadataKey = "protocol"
	ResponseTime          MetadataKey = "responseTime"
	SourcePrincipal       MetadataKey = "sourcePrincipal"
	Throughput            MetadataKey = "throughput"
)

Metadata keys to be used instead of literal strings

type NamespaceInfo added in v0.9.1

type NamespaceInfo struct {
	Name     string
	Duration time.Duration
	IsIstio  bool
}

type NamespaceInfoMap added in v1.4.0

type NamespaceInfoMap map[string]NamespaceInfo

func NewNamespaceInfoMap added in v1.4.0

func NewNamespaceInfoMap() NamespaceInfoMap

type Node added in v0.6.0

type Node struct {
	ID        string   // unique identifier for the node
	NodeType  string   // Node type
	Cluster   string   // Cluster
	Namespace string   // Namespace
	Workload  string   // Workload (deployment) name
	App       string   // Workload app label value
	Version   string   // Workload version label value
	Service   string   // Service name
	Edges     []*Edge  // child nodes
	Metadata  Metadata // app-specific data
}

func NewAggregateNode added in v1.21.0

func NewAggregateNode(cluster, namespace, aggregate, aggregateValue, svcName, app string) Node

NewAggregateNode constructor, set svcName and app to "" when not service-specific aggregate

func NewAggregateNodeExplicit added in v1.21.0

func NewAggregateNodeExplicit(id, cluster, namespace, aggregate, aggregateValue, svcName, app string) Node

NewAggregateNodeExplicit constructor assigns the specified ID, , set svcName and app to "" when not service-specific aggregate

func NewNode added in v0.6.0

func NewNode(cluster, serviceNamespace, service, workloadNamespace, workload, app, version, graphType string) (*Node, error)

NewNode constructor

func NewNodeExplicit added in v0.6.0

func NewNodeExplicit(id, cluster, namespace, workload, app, version, service, nodeType, graphType string) *Node

NewNodeExplicit constructor assigns the specified ID

func (*Node) AddEdge added in v0.6.0

func (s *Node) AddEdge(dest *Node) *Edge

AddEdge adds an edge to the specified dest node

type NodeOptions added in v0.21.0

type NodeOptions struct {
	Aggregate      string
	AggregateValue string
	App            string
	Cluster        string
	Namespace      string
	Service        string
	Version        string
	Workload       string
}

NodeOptions are those that apply only to node-detail graphs

type Options added in v0.21.0

type Options struct {
	ConfigVendor    string
	TelemetryVendor string
	ConfigOptions
	TelemetryOptions
}

Options comprises all available options

func NewOptions added in v0.21.0

func NewOptions(r *net_http.Request) Options

type Protocol added in v0.14.0

type Protocol struct {
	Name          string
	EdgeRates     []Rate
	EdgeResponses MetadataKey
	NodeRates     []Rate
	Unit          string
	UnitShort     string
}

Protocol describes a supported protocol and the rates it provides

type Rate added in v0.14.0

type Rate struct {
	Name         MetadataKey
	IsErr        bool
	IsIn         bool
	IsOut        bool
	IsPercentErr bool
	IsPercentReq bool
	IsTotal      bool
	Precision    int
}

Rate describes one rate provided by a protocol

type RequestedAppenders added in v0.21.0

type RequestedAppenders struct {
	All           bool
	AppenderNames []string
}

type RequestedRates added in v1.38.1

type RequestedRates struct {
	Grpc string
	Http string
	Tcp  string
}

type Response added in v0.12.0

type Response struct {
	Message string
	Code    int
}

func Panic added in v0.12.0

func Panic(message string, code int) Response

Panic panics with the provided HTTP response code and message

type ResponseDetail added in v1.6.0

type ResponseDetail struct {
	Flags ResponseFlags
	Hosts ResponseHosts
}

ResponseDetail consolidates response detail for a response code

type ResponseFlags added in v0.17.0

type ResponseFlags map[string]float64

ResponseFlags maps flags to request percentage

type ResponseHosts added in v1.6.0

type ResponseHosts map[string]float64

ResponseHosts maps hosts to request percentage

type Responses added in v0.17.0

type Responses map[string]*ResponseDetail

Responses maps codes to ResponseDetail

type SEInfo added in v1.31.0

type SEInfo struct {
	Hosts     []string `json:"hosts"`     // configured list of hosts
	Location  string   `json:"location"`  // e.g. MESH_EXTERNAL, MESH_INTERNAL
	Namespace string   `json:"namespace"` // the definition namespace
}

SEInfo provides static information about the service entry

type ServiceName added in v1.4.0

type ServiceName struct {
	Cluster   string `json:"cluster"`
	Namespace string `json:"namespace"`
	Name      string `json:"name"`
}

func (*ServiceName) Key added in v1.4.0

func (s *ServiceName) Key() string

type TelemetryOptions added in v0.21.0

type TelemetryOptions struct {
	AccessibleNamespaces map[string]time.Time
	Appenders            RequestedAppenders // requested appenders, nil if param not supplied
	IncludeIdleEdges     bool               // include edges with request rates of 0
	InjectServiceNodes   bool               // inject destination service nodes between source and destination nodes.
	Namespaces           NamespaceInfoMap
	Rates                RequestedRates
	CommonOptions
	NodeOptions
}

TelemetryOptions are those supplied to Telemetry Vendors

func (*TelemetryOptions) GetGraphKind added in v0.21.0

func (o *TelemetryOptions) GetGraphKind() string

GetGraphKind will return the kind of graph represented by the options.

type TelemetryVendor added in v0.21.0

type TelemetryVendor interface {

	// BuildNamespaceTrafficMap is required by the TelemetryVendor interface.  It must produce a valid
	// TrafficMap for the requested namespaces, It is recommended to use the graph/util.go definitions for
	// error handling. It should be modeled after the Istio implementation.
	BuildNamespacesTrafficMap(o TelemetryOptions, client *prometheus.Client, globalInfo *AppenderGlobalInfo) TrafficMap

	// BuildNodeTrafficMap is required by the TelemetryVendor interface.  It must produce a valid
	// TrafficMap for the requested node, It is recommended to use the graph/util.go definitions for
	// error handling. It should be modeled after the Istio implementation.
	BuildNodeTrafficMap(o TelemetryOptions, client *prometheus.Client, globalInfo *AppenderGlobalInfo) TrafficMap
}

TelemetryVendor is an interface that must be satisfied for each telemetry implementation.

type TrafficMap

type TrafficMap map[string]*Node

TrafficMap is a map of app Nodes, each optionally holding Edge data. Metadata is a general purpose map for holding any desired node or edge information. Each app node should have a unique namespace+workload. Note that it is feasible but likely unusual to have two nodes with the same name+version in the same namespace.

func NewTrafficMap

func NewTrafficMap() TrafficMap

NewTrafficMap constructor

func (TrafficMap) Edges added in v1.56.0

func (tm TrafficMap) Edges() []*Edge

Edges returns all of the edges in the traffic map.

type VirtualServicesMetadata added in v1.38.1

type VirtualServicesMetadata map[string][]string

type WEInfo added in v1.41.0

type WEInfo struct {
	// Name of the workload entry object
	// required:true
	Name string `json:"name"`
}

WEInfo provides static information about a workload entry associated with a workload node.

Directories

Path Synopsis
config
Package telemtry contains telemetry provider implementations as well as common code that can be shared by each telemetry vendor.
Package telemtry contains telemetry provider implementations as well as common code that can be shared by each telemetry vendor.
istio
Package istio provides the Istio implementation of graph/TelemetryProvider.
Package istio provides the Istio implementation of graph/TelemetryProvider.

Jump to

Keyboard shortcuts

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