Documentation ¶
Overview ¶
Package conditional provides conditional gatherer which runs gatherings based on the rules and only if the provided conditions are satisfied. The rules are fetched from Insights Operator Gathering Conditions Service https://github.com/RedHatInsights/insights-operator-gathering-conditions-service . The rules are validated to check that they make sense (for example we don't allow collecting logs from non openshift namespaces).
To add a new condition, follow the steps described in conditions.go file. To add a new gathering function, follow the steps described in gathering_functions.go file.
Index ¶
- type APIRequestCount
- type AlertConditionParams
- type AlertLabels
- type ClusterVersionMatchesConditionParams
- type ConditionType
- type ConditionWithParams
- type GatherAPIRequestCountsParams
- type GatherContainersLogsParams
- type GatherImageStreamsOfNamespaceParams
- type GatherLogsOfNamespaceParams
- type GatherPodDefinitionParams
- type Gatherer
- func (g *Gatherer) BuildGatherAPIRequestCounts(paramsInterface interface{}) (gatherers.GatheringClosure, error)
- func (g *Gatherer) BuildGatherContainersLogs(paramsInterface interface{}) (gatherers.GatheringClosure, error)
- func (g *Gatherer) BuildGatherImageStreamsOfNamespace(paramsInterface interface{}) (gatherers.GatheringClosure, error)
- func (g *Gatherer) BuildGatherLogsOfNamespace(paramsInterface interface{}) (gatherers.GatheringClosure, error)
- func (g *Gatherer) BuildGatherPodDefinition(paramsInterface interface{}) (gatherers.GatheringClosure, error)
- func (g *Gatherer) GetGatheringFunctions(ctx context.Context) (map[string]gatherers.GatheringClosure, error)
- func (g *Gatherer) GetName() string
- type GathererFunctionBuilderPtr
- type GatheringFunctionName
- type GatheringFunctions
- type GatheringRule
- type GatheringRuleMetadata
- type GatheringRules
- type GatheringRulesMetadata
- type GatheringRulesServiceClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIRequestCount ¶
type APIRequestCount struct { ResourceName string `json:"resource"` RemovedInRelease string `json:"removed_in_release"` TotalRequestCount int64 `json:"total_request_count"` LastDayRequestCount int64 `json:"last_day_request_count"` }
APIRequestCount defines a type used when marshaling into JSON
type AlertConditionParams ¶
type AlertConditionParams struct { // Name of the alert Name string `json:"name"` }
AlertConditionParams is a type holding params for alert_is_firing condition
type AlertLabels ¶
AlertLabels defines alert labels as a string key/value pairs
type ClusterVersionMatchesConditionParams ¶
type ClusterVersionMatchesConditionParams struct { // Version is a semantic versioning expression Version string `json:"version"` }
ClusterVersionMatchesConditionParams is a type holding params for cluster_version_matches condition
type ConditionType ¶
type ConditionType string
ConditionType defines conditions to check
const AlertIsFiring ConditionType = "alert_is_firing"
AlertIsFiring is a condition to check that alert is firing the params are in the field `alert`
const ClusterVersionMatches ConditionType = "cluster_version_matches"
ClusterVersionMatches is a condition to check that the current cluster version matches the provided semantic versioning expression
type ConditionWithParams ¶
type ConditionWithParams struct { Type ConditionType `json:"type"` Alert *AlertConditionParams `json:"alert,omitempty"` ClusterVersionMatches *ClusterVersionMatchesConditionParams `json:"cluster_version_matches,omitempty"` }
ConditionWithParams is a type holding a condition with its params
type GatherAPIRequestCountsParams ¶
type GatherAPIRequestCountsParams struct {
AlertName string `json:"alert_name"`
}
GatherAPIRequestCountsParams defines parameters for api_request_counts gatherer
type GatherContainersLogsParams ¶
type GatherContainersLogsParams struct { AlertName string `json:"alert_name"` Namespace string `json:"namespace,omitempty"` Container string `json:"container,omitempty"` TailLines int64 `json:"tail_lines"` Previous bool `json:"previous,omitempty"` }
GatherContainersLogsParams defines parameters for container_logs gatherer
type GatherImageStreamsOfNamespaceParams ¶
type GatherImageStreamsOfNamespaceParams struct { // Namespace from which to collect image streams Namespace string `json:"namespace"` }
GatherImageStreamsOfNamespaceParams defines parameters for image streams of namespace gatherer
type GatherLogsOfNamespaceParams ¶
type GatherLogsOfNamespaceParams struct { // Namespace from which to collect logs Namespace string `json:"namespace"` // A number of log lines to keep for each container TailLines int64 `json:"tail_lines"` }
GatherLogsOfNamespaceParams defines parameters for logs of namespace gatherer
type GatherPodDefinitionParams ¶
type GatherPodDefinitionParams struct {
AlertName string `json:"alert_name"`
}
GatherPodDefinitionParams defines parameters for pod_definition gatherer
type Gatherer ¶
type Gatherer struct {
// contains filtered or unexported fields
}
Gatherer implements the conditional gatherer
func New ¶
func New( gatherProtoKubeConfig, metricsGatherKubeConfig, gatherKubeConfig *rest.Config, configurator configobserver.Interface, gatheringRulesServiceClient GatheringRulesServiceClient, ) *Gatherer
New creates a new instance of conditional gatherer with the appropriate configs
func (*Gatherer) BuildGatherAPIRequestCounts ¶
func (g *Gatherer) BuildGatherAPIRequestCounts(paramsInterface interface{}) (gatherers.GatheringClosure, error)
BuildGatherAPIRequestCounts Collects API requests counts for the resources mentioned in the alert provided as a string parameter.
### API Reference None
### Sample data - docs/insights-archive-sample/conditional/alerts/APIRemovedInNextEUSReleaseInUse/api_request_counts.json
### Location in archive - `conditional/alerts/{alert_name}/api_request_counts.json`
### Config ID `conditional/api_request_counts_of_resource_from_alert`
### Released version - 4.10.0
### Backported versions - 4.9.6+
### Changes None
func (*Gatherer) BuildGatherContainersLogs ¶
func (g *Gatherer) BuildGatherContainersLogs(paramsInterface interface{}) (gatherers.GatheringClosure, error)
BuildGatherContainersLogs Collects either current or previous containers logs for pods firing one of the alerts from the conditions fetched from insights conditions service.
### API Reference None
### Sample data - docs/insights-archive-sample/conditional/namespaces/openshift-cluster-samples-operator/pods/cluster-samples-operator-8ffb9b45f-49mjr/containers/cluster-samples-operator-watch/logs/last-100-lines.log
### Location in archive - `conditional/namespaces/{namespace}/pods/{pod}/containers/{container}/{logs|logs-previous}/last-{tail-length}-lines.log`
### Config ID `conditional/containers_logs`
### Released version - 4.10.0
### Backported versions None
### Changes None
func (*Gatherer) BuildGatherImageStreamsOfNamespace ¶
func (g *Gatherer) BuildGatherImageStreamsOfNamespace(paramsInterface interface{}) (gatherers.GatheringClosure, error)
BuildGatherImageStreamsOfNamespace Closure which collects image streams from the provided namespace
### API Reference - https://docs.openshift.com/container-platform/4.7/rest_api/image_apis/imagestream-image-openshift-io-v1.html#apisimage-openshift-iov1namespacesnamespaceimagestreams
### Sample data - docs/insights-archive-sample/conditional/namespaces/openshift-cluster-samples-operator/imagestreams/example.json
### Location in archive | Version | Path | | --------- | -------------------------------------------------------- | | >= 4.9.0 | conditional/namespaces/{namespace}/imagestreams/{name}.json |
### Config ID `conditional/image_streams_of_namespace`
### Released version - 4.9.0
### Backported versions None
### Changes None
func (*Gatherer) BuildGatherLogsOfNamespace ¶
func (g *Gatherer) BuildGatherLogsOfNamespace(paramsInterface interface{}) (gatherers.GatheringClosure, error)
BuildGatherLogsOfNamespace Collects logs from pods in the provided namespace.
### API Reference - https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/core/v1/pod_expansion.go#L48 - https://docs.openshift.com/container-platform/4.6/rest_api/workloads_apis/pod-core-v1.html#apiv1namespacesnamespacepodsnamelog
### Sample data - docs/insights-archive-sample/conditional/namespaces/openshift-cluster-samples-operator/pods/cluster-samples-operator-8ffb9b45f-49mjr/containers/cluster-samples-operator/logs/last-100-lines.log
### Location in archive - `conditional/namespaces/{namespace}/pods/{pod_name}/containers/{container_name}/logs/last-{n}-lines.log`
### Config ID `conditional/logs_of_namespace`
### Released version - 4.9.0
### Backported versions None
### Changes None
func (*Gatherer) BuildGatherPodDefinition ¶
func (g *Gatherer) BuildGatherPodDefinition(paramsInterface interface{}) (gatherers.GatheringClosure, error)
BuildGatherPodDefinition Collects pod definition from pods that are firing one of the configured alerts.
### API Reference None
### Sample data - docs/insights-archive-sample/conditional/namespaces/openshift-monitoring/pods/alertmanager-main-0/alertmanager-main-0.json
### Location in archive - `conditional/namespaces/{namespace}/pods/{name}/{name}.json`
### Config ID `conditional/pod_definition`
### Released version - 4.11.0
### Backported versions None
### Changes None
func (*Gatherer) GetGatheringFunctions ¶
func (g *Gatherer) GetGatheringFunctions(ctx context.Context) (map[string]gatherers.GatheringClosure, error)
GetGatheringFunctions returns gathering functions that should be run considering the conditions + the gathering function producing metadata for the conditional gatherer
type GathererFunctionBuilderPtr ¶
type GathererFunctionBuilderPtr = func(*Gatherer, interface{}) (gatherers.GatheringClosure, error)
GathererFunctionBuilderPtr defines a pointer to a gatherer function builder
type GatheringFunctionName ¶
type GatheringFunctionName string
GatheringFunctionName defines functions of conditional gatherer
const ( // GatherLogsOfNamespace is a function collecting logs of the provided namespace. // See file gather_logs_of_namespace.go GatherLogsOfNamespace GatheringFunctionName = "logs_of_namespace" // GatherImageStreamsOfNamespace is a function collecting image streams of the provided namespace. // See file gather_image_streams_of_namespace.go GatherImageStreamsOfNamespace GatheringFunctionName = "image_streams_of_namespace" // GatherAPIRequestCounts is a function collecting api request counts for the resources read // from the corresponding alert // See file gather_api_requests_count.go GatherAPIRequestCounts GatheringFunctionName = "api_request_counts_of_resource_from_alert" // GatherContainersLogs is a function that collects logs from pod's containers // See file gather_containers_logs.go GatherContainersLogs GatheringFunctionName = "containers_logs" // GatherPodDefinition is a function that collects the pod definitions // See file gather_pod_definition.go GatherPodDefinition GatheringFunctionName = "pod_definition" )
func (GatheringFunctionName) NewParams ¶
func (name GatheringFunctionName) NewParams(jsonParams []byte) (interface{}, error)
type GatheringFunctions ¶
type GatheringFunctions = map[GatheringFunctionName]interface{}
GatheringFunctions is a type to map gathering function name to its params
type GatheringRule ¶
type GatheringRule struct { // conditions can be empty Conditions []ConditionWithParams `json:"conditions"` // gathering functions can't be empty GatheringFunctions GatheringFunctions `json:"gathering_functions"` }
GatheringRule is a rule consisting of conditions and gathering functions to run if all conditions are met, gathering_rule.schema.json describes valid values for this struct. An example of it:
{ "conditions": [ { "type": "alert_is_firing", "alert": { "name": "ClusterVersionOperatorIsDown" } }, { "type": "cluster_version_matches", "cluster_version": { "version": "4.8.x" } } ], "gathering_functions": { "gather_logs_of_namespace": { "namespace": "openshift-cluster-version", "keep_lines": 100 } } }
Which means to collect logs of all containers from all pods in namespace openshift-monitoring keeping last 100 lines per container only if cluster version is 4.8 (not implemented, just an example of possible use) and alert ClusterVersionOperatorIsDown is firing
type GatheringRuleMetadata ¶
type GatheringRuleMetadata struct { Rule GatheringRule `json:"rule"` Errors []string `json:"errors"` WasTriggered bool `json:"was_triggered"` }
GatheringRuleMetadata stores metadata about a gathering rule
type GatheringRules ¶
type GatheringRules struct { Version string `json:"version"` Rules []GatheringRule `json:"rules"` }
GatheringRules is a structure to hold gathering rules with their version
type GatheringRulesMetadata ¶
type GatheringRulesMetadata struct { Version string `json:"version"` Rules []GatheringRuleMetadata `json:"rules"` Endpoint string `json:"endpoint"` }
GatheringRulesMetadata stores metadata about gathering rules