Skip to content

Commit

Permalink
Added enum for FLP alerts name
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCazade committed Mar 14, 2023
1 parent 5d23deb commit 4b89c94
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
14 changes: 12 additions & 2 deletions api/v1beta1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ type MetricsServerConfig struct {
TLS ServerTLS `json:"tls"`
}

const (
AlertNoFlows = "NetObservNoFlows"
AlertLokiError = "NetObservLokiError"
)

// Name of a processor alert
// Possible values are: `NetObservNoFlows`, which is triggered when no flows are being observed for a certain period, and `NetObservLokiError`, which is triggered when flows are being dropped due to Loki errors.disableAlerts is a list of alerts related to FLP that should not be created
// +kubebuilder:validation:Enum:="NetObservNoFlows";"NetObservLokiError"
type FLPAlert string

// FLPMetrics define the desired FLP configuration regarding metrics
type FLPMetrics struct {
// metricsServer endpoint configuration for Prometheus scraper
Expand All @@ -281,9 +291,9 @@ type FLPMetrics struct {
//+kubebuilder:default:={"egress","packets"}
IgnoreTags []string `json:"ignoreTags,omitempty"`

// disableAlerts is a list of alerts related to FLP that should not be created
// disableAlerts is a list of alerts that should not be created.
// +optional
DisableAlerts []string `json:"disableAlerts,omitempty"`
DisableAlerts []FLPAlert `json:"disableAlerts,omitempty"`
}

const (
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions bundle/manifests/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4082,6 +4082,15 @@ spec:
description: Metrics define the processor configuration regarding
metrics
properties:
disableAlerts:
description: disableAlerts is a list of alerts related to
FLP that should not be created
items:
enum:
- NetObservNoFlows
- NetObservLokiError
type: string
type: array
ignoreTags:
default:
- egress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ metadata:
"kafkaConsumerReplicas": 3,
"logLevel": "info",
"metrics": {
"disableAlerts": [],
"ignoreTags": [
"egress",
"packets"
Expand Down
13 changes: 11 additions & 2 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4070,9 +4070,18 @@ spec:
metrics
properties:
disableAlerts:
description: disableAlerts is a list of alerts related to
FLP that should not be created
description: disableAlerts is a list of alerts that should
not be created.
items:
description: 'Name of a processor alert Possible values
are: `NetObservNoFlows`, which is triggered when no flows
are being observed for a certain period, and `NetObservLokiError`,
which is triggered when flows are being dropped due to
Loki errors.disableAlerts is a list of alerts related
to FLP that should not be created'
enum:
- NetObservNoFlows
- NetObservLokiError
type: string
type: array
ignoreTags:
Expand Down
10 changes: 5 additions & 5 deletions controllers/flowlogspipeline/flp_common_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func (b *builder) serviceMonitor() *monitoringv1.ServiceMonitor {
return &flpServiceMonitorObject
}

func shouldAddAlert(name string, disabledList []string) bool {
func shouldAddAlert(name flowslatest.FLPAlert, disabledList []flowslatest.FLPAlert) bool {
for _, disabledAlert := range disabledList {
if name == disabledAlert {
return false
Expand All @@ -725,9 +725,9 @@ func (b *builder) prometheusRule() *monitoringv1.PrometheusRule {
rules := []monitoringv1.Rule{}

// Not receiving flows
if shouldAddAlert("NetObservNoFlows", b.desired.Processor.Metrics.DisableAlerts) {
if shouldAddAlert(flowslatest.AlertNoFlows, b.desired.Processor.Metrics.DisableAlerts) {
rules = append(rules, monitoringv1.Rule{
Alert: "NetObservNoFlows",
Alert: flowslatest.AlertNoFlows,
Annotations: map[string]string{
"description": "NetObserv flowlogs-pipeline is not receiving any flow, this is either a connection issue with the agent, or an agent issue",
"summary": "NetObserv flowlogs-pipeline is not receiving any flow",
Expand All @@ -741,9 +741,9 @@ func (b *builder) prometheusRule() *monitoringv1.PrometheusRule {
}

// Flows getting dropped by loki library
if shouldAddAlert("NetObservLokiError", b.desired.Processor.Metrics.DisableAlerts) {
if shouldAddAlert(flowslatest.AlertLokiError, b.desired.Processor.Metrics.DisableAlerts) {
rules = append(rules, monitoringv1.Rule{
Alert: "NetObservLokiError",
Alert: flowslatest.AlertLokiError,
Annotations: map[string]string{
"description": "NetObserv flowlogs-pipeline is dropping flows because of loki errors, loki may be down or having issues ingesting every flows. Please check loki and flowlogs-pipeline logs.",
"summary": "NetObserv flowlogs-pipeline is dropping flows because of loki errors",
Expand Down
4 changes: 2 additions & 2 deletions docs/FlowCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -7294,9 +7294,9 @@ Metrics define the processor configuration regarding metrics
</thead>
<tbody><tr>
<td><b>disableAlerts</b></td>
<td>[]string</td>
<td>[]enum</td>
<td>
disableAlerts is a list of alerts related to FLP that should not be created<br/>
disableAlerts is a list of alerts that should not be created.<br/>
</td>
<td>false</td>
</tr><tr>
Expand Down

0 comments on commit 4b89c94

Please sign in to comment.