graph

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

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 (
	GroupByApp     string = "app"
	GroupByNone    string = "none"
	GroupByVersion string = "version"
	NamespaceIstio string = "istio-system"
)
View Source
const (
	GraphTypeApp          string = "app"
	GraphTypeService      string = "service" // Treated as graphType Workload, with service injection, and then condensed
	GraphTypeVersionedApp string = "versionedApp"
	GraphTypeWorkload     string = "workload"
	NodeTypeApp           string = "app"
	NodeTypeService       string = "service"
	NodeTypeUnknown       string = "unknown" // The special "unknown" traffic gen node
	NodeTypeWorkload      string = "workload"
	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 Protocols []Protocol = []Protocol{GRPC, HTTP, TCP}

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

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 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 Error added in v0.12.0

func Error(message string)

Error panics with InternalServerError 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(serviceNamespace, service, workloadNamespace, workload, app, version, graphType string) (id, nodeType string)

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 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.
	AppendGraph(trafficMap TrafficMap, globalInfo *AppenderGlobalInfo, namespaceInfo *AppenderNamespaceInfo)

	// 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
	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 {
	GroupBy 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

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 (
	DestServices    MetadataKey = "destServices"
	HasCB           MetadataKey = "hasCB"
	HasMissingSC    MetadataKey = "hasMissingSC"
	HasVS           MetadataKey = "hasVS"
	IsDead          MetadataKey = "isDead"
	IsEgressCluster MetadataKey = "isEgressCluster" // PassthroughCluster or BlackHoleCluster
	IsInaccessible  MetadataKey = "isInaccessible"
	IsMisconfigured MetadataKey = "isMisconfigured"
	IsMTLS          MetadataKey = "isMTLS"
	IsOutside       MetadataKey = "isOutside"
	IsRoot          MetadataKey = "isRoot"
	IsServiceEntry  MetadataKey = "isServiceEntry"
	IsUnused        MetadataKey = "isUnused"
	ProtocolKey     MetadataKey = "protocol"
	ResponseTime    MetadataKey = "responseTime"
)

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

func (NamespaceInfoMap) GetIstioNamespaces added in v1.4.0

func (in NamespaceInfoMap) GetIstioNamespaces() []string

GetIstioNamespaces returns all Istio namespaces found in the NamespaceInfo value set

type Node added in v0.6.0

type Node struct {
	ID        string   // unique identifier for the node
	NodeType  string   // Node type
	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 NewNode added in v0.6.0

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

func NewNodeExplicit added in v0.6.0

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

func (*Node) AddEdge added in v0.6.0

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

type NodeOptions added in v0.21.0

type NodeOptions struct {
	App       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

var GRPC Protocol = Protocol{
	Name: grpc,
	EdgeRates: []Rate{
		{Name: grpc, IsTotal: 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: grpcInErr, IsErr: true, Precision: 2},
		{Name: grpcOut, IsOut: true, Precision: 2},
	},
	Unit:      requestsPerSecond,
	UnitShort: rps,
}
var HTTP Protocol = Protocol{
	Name: http,
	EdgeRates: []Rate{
		{Name: http, IsTotal: 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: 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,
}
var TCP Protocol = 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,
}

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 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
}

type ResponseFlags added in v0.17.0

type ResponseFlags map[string]float64

type ResponseHosts added in v1.6.0

type ResponseHosts map[string]float64

type Responses added in v0.17.0

type Responses map[string]*ResponseDetail

type ServiceName added in v1.4.0

type ServiceName struct {
	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
	InjectServiceNodes   bool               // inject destination service nodes between source and destination nodes.
	Namespaces           NamespaceInfoMap
	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

Directories

Path Synopsis
config
cytoscape
Package cytoscape provides conversion from our graph to the CystoscapeJS configuration json model.
Package cytoscape provides conversion from our graph to the CystoscapeJS configuration json model.
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