Skip to content

Commit

Permalink
NodeDirection / IfDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Feb 21, 2024
1 parent f4d840b commit 840ba66
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 65 deletions.
16 changes: 8 additions & 8 deletions apis/flowmetrics/v1alpha1/flowmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

type MetricType string
type FilterMatchType string
type FlowDirection string
type NodeDirection string

const (
CounterMetric MetricType = "Counter"
Expand All @@ -33,9 +33,9 @@ const (
MatchRegex FilterMatchType = "Regex"
MatchPresence FilterMatchType = "Presence"
MatchAbsence FilterMatchType = "Absence"
Egress FlowDirection = "Egress"
Ingress FlowDirection = "Ingress"
AnyDirection FlowDirection = "Any"
Egress NodeDirection = "Egress"
Ingress NodeDirection = "Ingress"
AnyDirection NodeDirection = "Any"
)

type MetricFilter struct {
Expand Down Expand Up @@ -77,7 +77,7 @@ type FlowMetricSpec struct {
ValueField string `json:"valueField,omitempty"`

// `filters` is a list of fields and values used to restrict which flows are taken into account. Oftentimes, these filters must
// be used to eliminate duplicates: `Duplicate:"false"` and `FlowDirection: "0"`.
// be used to eliminate duplicates: `Duplicate:"false"` and `NodeDirection: "0"`.
// Refer to the documentation for the list of available fields: https://docs.openshift.com/container-platform/latest/networking/network_observability/json-flows-format-reference.html.
// +optional
Filters []MetricFilter `json:"filters"`
Expand All @@ -97,12 +97,12 @@ type FlowMetricSpec struct {
IncludeDuplicates bool `json:"includeDuplicates,omitempty"`

// Filter for ingress, egress or any direction flows.
// When set to `Ingress`, it is equivalent to adding the regex filter on `FlowDirection`: `0|2`.
// When set to `Egress`, it is equivalent to adding the regex filter on `FlowDirection`: `1|2`.
// When set to `Ingress`, it is equivalent to adding the regex filter on `NodeDirection`: `0|2`.
// When set to `Egress`, it is equivalent to adding the regex filter on `NodeDirection`: `1|2`.
// +kubebuilder:validation:Enum:="Any";"Egress";"Ingress"
// +kubebuilder:default:="Any"
// +optional
Direction FlowDirection `json:"direction,omitempty"`
Direction NodeDirection `json:"direction,omitempty"`

// A list of buckets to use when `type` is "Histogram". The list must be parseable as floats. Prometheus default buckets will be used if unset.
// +optional
Expand Down
6 changes: 3 additions & 3 deletions bundle/manifests/flows.netobserv.io_flowmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ spec:
default: Any
description: 'Filter for ingress, egress or any direction flows. When
set to `Ingress`, it is equivalent to adding the regex filter on
`FlowDirection`: `0|2`. When set to `Egress`, it is equivalent to
adding the regex filter on `FlowDirection`: `1|2`.'
`NodeDirection`: `0|2`. When set to `Egress`, it is equivalent to
adding the regex filter on `NodeDirection`: `1|2`.'
enum:
- Any
- Egress
Expand All @@ -61,7 +61,7 @@ spec:
filters:
description: '`filters` is a list of fields and values used to restrict
which flows are taken into account. Oftentimes, these filters must
be used to eliminate duplicates: `Duplicate:"false"` and `FlowDirection:
be used to eliminate duplicates: `Duplicate:"false"` and `NodeDirection:
"0"`. Refer to the documentation for the list of available fields:
https://docs.openshift.com/container-platform/latest/networking/network_observability/json-flows-format-reference.html.'
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ metadata:
"value": "false"
},
{
"field": "FlowDirection",
"field": "NodeDirection",
"matchType": "Regex",
"value": "1|2"
}
Expand Down
6 changes: 3 additions & 3 deletions config/crd/bases/flows.netobserv.io_flowmetrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ spec:
default: Any
description: 'Filter for ingress, egress or any direction flows. When
set to `Ingress`, it is equivalent to adding the regex filter on
`FlowDirection`: `0|2`. When set to `Egress`, it is equivalent to
adding the regex filter on `FlowDirection`: `1|2`.'
`NodeDirection`: `0|2`. When set to `Egress`, it is equivalent to
adding the regex filter on `NodeDirection`: `1|2`.'
enum:
- Any
- Egress
Expand All @@ -63,7 +63,7 @@ spec:
filters:
description: '`filters` is a list of fields and values used to restrict
which flows are taken into account. Oftentimes, these filters must
be used to eliminate duplicates: `Duplicate:"false"` and `FlowDirection:
be used to eliminate duplicates: `Duplicate:"false"` and `NodeDirection:
"0"`. Refer to the documentation for the list of available fields:
https://docs.openshift.com/container-platform/latest/networking/network_observability/json-flows-format-reference.html.'
items:
Expand Down
2 changes: 1 addition & 1 deletion config/samples/flows_v1alpha1_flowmetric.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ spec:
matchType: Regex
- field: Duplicate
value: "false"
- field: FlowDirection
- field: NodeDirection
value: "1|2"
matchType: Regex
58 changes: 35 additions & 23 deletions controllers/consoleplugin/config/static-frontend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,31 @@ columns:
filter: icmp_code
default: false
width: 10
- id: FlowDirection
name: Direction
tooltip: The direction of the flow observed at the Node observation point.
field: FlowDirection
filter: direction
- id: NodeDirection
name: Node Direction
tooltip: The interpreted direction of the flow observed at the Node observation point.
field: NodeDirection
filter: nodedirection
default: false
width: 10
- id: Interface
name: Interface
tooltip: The network interface of the Flow.
field: Interface
filter: interface
- id: Interfaces
name: Interfaces
tooltip: The network interfaces of the Flow.
field: Interfaces
filter: interfaces
default: false
width: 10
- id: IfDirections
name: Interface Directions
tooltip: The directions of the Flow observed at the network interface observation point.
field: IfDirections
filter: ifdirections
default: false
width: 10
- id: FlowDirInts
name: Interfaces and Directions
tooltip: Pairs of network interface and direction of the Flow observed at the Node observation point.
field: FlowDirection
tooltip: Pairs of network interface and direction of the Flow observed at the network interface observation point.
field: Interfaces
default: false
width: 15
- id: Bytes
Expand Down Expand Up @@ -757,21 +764,26 @@ filters:
name: ICMP code
component: number
hint: Specify an ICMP code value as integer number.
- id: direction
name: Direction
- id: nodedirection
name: Node Direction
component: autocomplete
placeholder: 'E.g: Ingress, Egress, Inner'
hint: Specify the direction of the Flow observed at the Node observation point.
hint: Specify the interpreted direction of the Flow observed at the Node observation point.
- id: flow_layer
name: Flow layer
component: text
placeholder: 'Either infra or app'
hint: Specify the layer of Flow.
- id: interface
name: Network interface
- id: interfaces
name: Network interfaces
component: text
placeholder: 'E.g: br-ex, ovn-k8s-mp0'
hint: Specify a network interface.
- id: ifdirections
name: Interface Directions
component: autocomplete
placeholder: 'E.g: Ingress, Egress'
hint: Specify the direction of the Flow observed at the network interface observation point.
- id: id
name: Conversation Id
component: text
Expand Down Expand Up @@ -927,23 +939,23 @@ fields:
type: boolean
description: Indicates if this flow was also captured from another interface on the same host
lokiLabel: true
- name: FlowDirection
- name: NodeDirection
type: number
description: |
Flow direction from the node observation point. Can be one of: +
Flow interpreted direction from the node observation point. Can be one of: +
- 0: Ingress (incoming traffic, from the node observation point) +
- 1: Egress (outgoing traffic, from the node observation point) +
- 2: Inner (with the same source and destination node)
lokiLabel: true
- name: IfDirection
- name: IfDirections
type: number
description: |
Flow direction from the network interface observation point. Can be one of: +
Flow directions from the network interface observation point. Can be one of: +
- 0: Ingress (interface incoming traffic) +
- 1: Egress (interface outgoing traffic)
- name: Interface
- name: Interfaces
type: string
description: Network interface
description: Network interfaces
- name: Flags
type: number
description: |
Expand Down
3 changes: 1 addition & 2 deletions controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ const (
LokiCRReader = "netobserv-reader"
)

var LokiIndexFields = []string{"SrcK8S_Namespace", "SrcK8S_OwnerName", "SrcK8S_Type", "DstK8S_Namespace", "DstK8S_OwnerName", "DstK8S_Type", "K8S_FlowLayer"}
var LokiIndexFields = []string{"SrcK8S_Namespace", "SrcK8S_OwnerName", "SrcK8S_Type", "DstK8S_Namespace", "DstK8S_OwnerName", "DstK8S_Type", "K8S_FlowLayer", "NodeDirection"}
var LokiConnectionIndexFields = []string{"_RecordType"}
var LokiDeduperMarkIndexFields = []string{"FlowDirection"}
var LokiZoneIndexFields = []string{"SrcK8S_Zone", "DstK8S_Zone"}
var FlowCollectorName = types.NamespacedName{Name: "cluster"}
var EnvNoHTTP2 = corev1.EnvVar{
Expand Down
9 changes: 4 additions & 5 deletions controllers/flp/flp_pipeline_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func (b *PipelineBuilder) AddProcessorStages() error {
ReporterIPField: "AgentIP",
SrcHostField: "SrcK8S_HostIP",
DstHostField: "DstK8S_HostIP",
FlowDirectionField: "FlowDirection",
IfDirectionField: "IfDirection",
FlowDirectionField: "NodeDirection",
},
})

Expand Down Expand Up @@ -194,9 +193,9 @@ func flowMetricToFLP(flowMetric *metricslatest.FlowMetricSpec) (*api.MetricsItem
m.Filters = append(m.Filters, api.MetricsFilter{Key: "Duplicate", Value: "false", Type: "exact"})
}
if flowMetric.Direction == metricslatest.Egress {
m.Filters = append(m.Filters, api.MetricsFilter{Key: "FlowDirection", Value: "1|2", Type: "regex"})
m.Filters = append(m.Filters, api.MetricsFilter{Key: "NodeDirection", Value: "1|2", Type: "regex"})
} else if flowMetric.Direction == metricslatest.Ingress {
m.Filters = append(m.Filters, api.MetricsFilter{Key: "FlowDirection", Value: "0|2", Type: "regex"})
m.Filters = append(m.Filters, api.MetricsFilter{Key: "NodeDirection", Value: "0|2", Type: "regex"})
}
for _, b := range flowMetric.Buckets {
f, err := strconv.ParseFloat(b, 64)
Expand Down Expand Up @@ -243,7 +242,7 @@ func (b *PipelineBuilder) addConnectionTracking(lastStage config.PipelineBuilder
ReportMissing: true,
},
{
Name: "FlowDirection",
Name: "NodeDirection",
Operation: "first",
ReportMissing: true,
},
Expand Down
3 changes: 2 additions & 1 deletion controllers/flp/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ func TestConfigMapShouldDeserializeAsJSONWithLokiManual(t *testing.T) {
"DstK8S_OwnerName",
"DstK8S_Type",
"K8S_FlowLayer",
"NodeDirection",
"_RecordType",
}, lokiCfg.Labels)
assert.Equal(`{app="netobserv-flowcollector"}`, fmt.Sprintf("%v", lokiCfg.StaticLabels))
Expand Down Expand Up @@ -711,8 +712,8 @@ func TestConfigMapShouldDeserializeAsJSONWithLokiStack(t *testing.T) {
"DstK8S_OwnerName",
"DstK8S_Type",
"K8S_FlowLayer",
"NodeDirection",
"_RecordType",
"FlowDirection",
}, lokiCfg.Labels)
assert.Equal(`{app="netobserv-flowcollector"}`, fmt.Sprintf("%v", lokiCfg.StaticLabels))

Expand Down
2 changes: 1 addition & 1 deletion controllers/flp/metrics_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestFlowMetricToFLP(t *testing.T) {
Filters: []api.MetricsFilter{
{Key: "f", Value: "v", Type: api.PromFilterRegex},
{Key: "f2", Type: api.PromFilterAbsence},
{Key: "FlowDirection", Value: "1|2", Type: api.PromFilterRegex},
{Key: "NodeDirection", Value: "1|2", Type: api.PromFilterRegex},
},
Labels: []string{"by_field"},
Buckets: []float64{1, 5, 10, 50, 100},
Expand Down
2 changes: 1 addition & 1 deletion docs/flows-format.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The "Loki label" column is useful when querying Loki directly: label fields need
- RST+ACK (0x400)
| n/a
| no
| `FlowDirection`
| `NodeDirection`
| number
| Flow direction from the node observation point. Can be one of: +
- 0: Ingress (incoming traffic, from the node observation point) +
Expand Down
15 changes: 0 additions & 15 deletions pkg/loki/labels.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package loki

import (
"strconv"

flowslatest "github.com/netobserv/network-observability-operator/apis/flowcollector/v1beta2"
"github.com/netobserv/network-observability-operator/controllers/constants"
"github.com/netobserv/network-observability-operator/controllers/ebpf"
"github.com/netobserv/network-observability-operator/pkg/helper"
)

Expand All @@ -24,17 +21,5 @@ func GetLokiLabels(desired *flowslatest.FlowCollectorSpec) []string {
indexFields = append(indexFields, constants.LokiZoneIndexFields...)
}

if helper.UseEBPF(desired) {
dedupJustMark, _ := strconv.ParseBool(ebpf.DedupeJustMarkDefault)
if desired.Agent.EBPF.Advanced != nil {
if v, ok := desired.Agent.EBPF.Advanced.Env[ebpf.EnvDedupeJustMark]; ok {
dedupJustMark, _ = strconv.ParseBool(v)
}
}
if dedupJustMark {
indexFields = append(indexFields, constants.LokiDeduperMarkIndexFields...)
}
}

return indexFields
}
2 changes: 1 addition & 1 deletion pkg/metrics/predefined_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
ValueKey: valueField,
Filters: []flpapi.MetricsFilter{
{Key: "Duplicate", Value: "false"},
{Key: "FlowDirection", Value: mapDirection[dir], Type: flpapi.PromFilterRegex},
{Key: "NodeDirection", Value: mapDirection[dir], Type: flpapi.PromFilterRegex},
},
Labels: labels,
},
Expand Down

0 comments on commit 840ba66

Please sign in to comment.