From 3a12ba2e6dfe980c1cc6d724d97c128ac2f2d2a6 Mon Sep 17 00:00:00 2001
From: Joel Takvorian <joel.takvorian@qaraywa.net>
Date: Mon, 25 Mar 2024 13:21:41 +0100
Subject: [PATCH] Change HOST/PORT env to TARGET_HOST / TARGET_PORT (#303)

As discussed here: https://github.com/netobserv/netobserv-ebpf-agent/pull/291#discussion_r1520076865
HOST and PORT are very generic and don't provide the meaning about what
they are for; An uninformed user would probably think this would be for
a server, of for the agent host itself, rather than a target of
flow/packet collectors.
---
 README.md                             |  6 +++---
 deployments/flp-daemonset-cap.yml     |  4 ++--
 deployments/flp-daemonset.yml         |  4 ++--
 deployments/flp-service.yml           |  4 ++--
 docs/config.md                        |  4 ++--
 e2e/cluster/base/04-agent.yml         |  4 ++--
 e2e/ipfix/manifests/30-agent.yml      |  4 ++--
 examples/flowlogs-dump/README.md      |  2 +-
 examples/packetcapture-dump/README.md |  2 +-
 examples/performance/deployment.yml   |  4 ++--
 examples/systemd/netobserv-ebpf-agent |  4 ++--
 pkg/agent/agent.go                    | 12 ++++++------
 pkg/agent/agent_test.go               |  4 ++--
 pkg/agent/config.go                   | 14 +++++++-------
 pkg/agent/packets_agent.go            |  6 +++---
 scripts/agent.yml                     |  4 ++--
 16 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/README.md b/README.md
index 65f112ca..bd0d3bfb 100644
--- a/README.md
+++ b/README.md
@@ -45,9 +45,9 @@ configured by our [Network Observability Operator](https://github.com/netobserv/
 
 Anyway you can run it directly as an executable from your command line:
 
-```
-export HOST=...
-export PORT=...
+```bash
+export TARGET_HOST=...
+export TARGET_PORT=...
 sudo -E bin/netobserv-ebpf-agent
 ```
 
diff --git a/deployments/flp-daemonset-cap.yml b/deployments/flp-daemonset-cap.yml
index f7dbea2a..ed07702c 100644
--- a/deployments/flp-daemonset-cap.yml
+++ b/deployments/flp-daemonset-cap.yml
@@ -32,11 +32,11 @@ spec:
               - SYS_RESOURCE
           runAsUser: 0
         env:
-          - name: HOST
+          - name: TARGET_HOST
             valueFrom:
               fieldRef:
                 fieldPath: status.hostIP
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
 ---
 apiVersion: apps/v1
diff --git a/deployments/flp-daemonset.yml b/deployments/flp-daemonset.yml
index ab73b730..8be0ff4c 100644
--- a/deployments/flp-daemonset.yml
+++ b/deployments/flp-daemonset.yml
@@ -27,11 +27,11 @@ spec:
           privileged: true
           runAsUser: 0
         env:
-          - name: HOST
+          - name: TARGET_HOST
             valueFrom:
               fieldRef:
                 fieldPath: status.hostIP
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
 ---
 apiVersion: apps/v1
diff --git a/deployments/flp-service.yml b/deployments/flp-service.yml
index e48dd7f9..cdaa158f 100644
--- a/deployments/flp-service.yml
+++ b/deployments/flp-service.yml
@@ -27,9 +27,9 @@ spec:
           privileged: true
           runAsUser: 0
         env:
-          - name: HOST
+          - name: TARGET_HOST
             value: "flp"
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
 ---
 apiVersion: v1
diff --git a/docs/config.md b/docs/config.md
index 5a104b30..9d93e93a 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -5,8 +5,8 @@ _Please also refer to the file [config.go](../pkg/agent/config.go) which is the
 The following environment variables are available to configure the NetObserv eBFP Agent:
 
 * `EXPORT` (default: `grpc`). Flows' exporter protocol. Accepted values are: `grpc`, `kafka`, `ipfix+udp`, `ipfix+tcp` or `direct-flp`. In `direct-flp` mode, [flowlogs-pipeline](https://github.com/netobserv/flowlogs-pipeline) is run internally from the agent, allowing more filtering, transformations and exporting options.
-* `HOST` (required if `EXPORT` is `grpc` or `ipfix+[tcp/udp]`). Host name or IP of the Flow collector.
-* `PORT` (required if `EXPORT` is `grpc` or `ipfix+[tcp/udp]`). Port of the flow collector.
+* `TARGET_HOST` (required if `EXPORT` is `grpc` or `ipfix+[tcp/udp]`). Host name or IP of the target flow or packet collector.
+* `TARGET_PORT` (required if `EXPORT` is `grpc` or `ipfix+[tcp/udp]`). Port of the target flow or packet collector.
 * `GRPC_MESSAGE_MAX_FLOWS` (default: `10000`). Specifies the limit, in number of flows, of each GRPC
   message. Messages larger than that number will be split and submitted sequentially.
 * `AGENT_IP` (optional). Allows overriding the reported Agent IP address on each flow.
diff --git a/e2e/cluster/base/04-agent.yml b/e2e/cluster/base/04-agent.yml
index d79b9ca2..16c27897 100644
--- a/e2e/cluster/base/04-agent.yml
+++ b/e2e/cluster/base/04-agent.yml
@@ -26,11 +26,11 @@ spec:
             value: 200ms
           - name: LOG_LEVEL
             value: debug
-          - name: HOST
+          - name: TARGET_HOST
             valueFrom:
               fieldRef:
                 fieldPath: status.hostIP
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
         volumeMounts:
             - name: bpf-kernel-debug
diff --git a/e2e/ipfix/manifests/30-agent.yml b/e2e/ipfix/manifests/30-agent.yml
index bef3564f..0dbd72e6 100644
--- a/e2e/ipfix/manifests/30-agent.yml
+++ b/e2e/ipfix/manifests/30-agent.yml
@@ -28,11 +28,11 @@ spec:
             value: 200ms
           - name: LOG_LEVEL
             value: debug
-          - name: HOST
+          - name: TARGET_HOST
             valueFrom:
               fieldRef:
                 fieldPath: status.hostIP
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
         volumeMounts:
             - name: bpf-kernel-debug
diff --git a/examples/flowlogs-dump/README.md b/examples/flowlogs-dump/README.md
index 79c307f1..620e7919 100644
--- a/examples/flowlogs-dump/README.md
+++ b/examples/flowlogs-dump/README.md
@@ -14,7 +14,7 @@ go build -mod vendor -o bin/flowlogs-dump-collector examples/flowlogs-dump/serve
 ```
 Start the agent using:
 ```bash
-sudo HOST=127.0.0.1 PORT=9999 ./bin/netobserv-ebpf-agent
+sudo TARGET_HOST=127.0.0.1 TARGET_PORT=9999 ./bin/netobserv-ebpf-agent
 ```
 
 Start the flowlogs-dump-collector using: (in a secondary shell)
diff --git a/examples/packetcapture-dump/README.md b/examples/packetcapture-dump/README.md
index 9f21cf68..906b2cd6 100644
--- a/examples/packetcapture-dump/README.md
+++ b/examples/packetcapture-dump/README.md
@@ -19,7 +19,7 @@ Start the packetcapture-client using: (in a secondary shell)
 
 Start the agent using:
 ```bash
-sudo HOST=localhost PORT=9990 ENABLE_PCA=true PCA_FILTER=tcp,22 ./bin/netobserv-ebpf-agent
+sudo TARGET_HOST=localhost TARGET_PORT=9990 ENABLE_PCA=true PCA_FILTER=tcp,22 ./bin/netobserv-ebpf-agent
 ```
 
 You should see output such as:
diff --git a/examples/performance/deployment.yml b/examples/performance/deployment.yml
index 23007eaf..e55dd778 100644
--- a/examples/performance/deployment.yml
+++ b/examples/performance/deployment.yml
@@ -67,9 +67,9 @@ spec:
           value: call_error,cares_resolver,dns_resolver
         - name: GRPC_DNS_RESOLVER
           value: "ares"
-        - name: HOST
+        - name: TARGET_HOST
           value: "packet-counter"
-        - name: PORT
+        - name: TARGET_PORT
           value: "9999"
 #      resources:
 #        limits:
diff --git a/examples/systemd/netobserv-ebpf-agent b/examples/systemd/netobserv-ebpf-agent
index 585ec9f3..171fde40 100644
--- a/examples/systemd/netobserv-ebpf-agent
+++ b/examples/systemd/netobserv-ebpf-agent
@@ -3,5 +3,5 @@
 # /etc/default/netobserv-ebpf-agent
 
 DIRECTION=both
-HOST=127.0.0.1
-PORT=9999
+TARGET_HOST=127.0.0.1
+TARGET_PORT=9999
diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go
index 00329ed0..c62809a1 100644
--- a/pkg/agent/agent.go
+++ b/pkg/agent/agent.go
@@ -294,11 +294,11 @@ func buildFlowExporter(cfg *Config, m *metrics.Metrics) (node.TerminalFunc[[]*fl
 }
 
 func buildGRPCExporter(cfg *Config, m *metrics.Metrics) (node.TerminalFunc[[]*flow.Record], error) {
-	if cfg.Host == "" || cfg.Port == 0 {
+	if cfg.TargetHost == "" || cfg.TargetPort == 0 {
 		return nil, fmt.Errorf("missing target host or port: %s:%d",
-			cfg.Host, cfg.Port)
+			cfg.TargetHost, cfg.TargetPort)
 	}
-	grpcExporter, err := exporter.StartGRPCProto(cfg.Host, cfg.Port, cfg.GRPCMessageMaxFlows, m)
+	grpcExporter, err := exporter.StartGRPCProto(cfg.TargetHost, cfg.TargetPort, cfg.GRPCMessageMaxFlows, m)
 	if err != nil {
 		return nil, err
 	}
@@ -364,11 +364,11 @@ func buildKafkaExporter(cfg *Config, m *metrics.Metrics) (node.TerminalFunc[[]*f
 }
 
 func buildIPFIXExporter(cfg *Config, proto string) (node.TerminalFunc[[]*flow.Record], error) {
-	if cfg.Host == "" || cfg.Port == 0 {
+	if cfg.TargetHost == "" || cfg.TargetPort == 0 {
 		return nil, fmt.Errorf("missing target host or port: %s:%d",
-			cfg.Host, cfg.Port)
+			cfg.TargetHost, cfg.TargetPort)
 	}
-	ipfix, err := exporter.StartIPFIXExporter(cfg.Host, cfg.Port, proto)
+	ipfix, err := exporter.StartIPFIXExporter(cfg.TargetHost, cfg.TargetPort, proto)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/agent/agent_test.go b/pkg/agent/agent_test.go
index 2768faaa..7c217267 100644
--- a/pkg/agent/agent_test.go
+++ b/pkg/agent/agent_test.go
@@ -29,10 +29,10 @@ func TestFlowsAgent_InvalidConfigs(t *testing.T) {
 		c: Config{Export: "foo"},
 	}, {
 		d: "GRPC: missing host",
-		c: Config{Export: "grpc", Port: 3333},
+		c: Config{Export: "grpc", TargetPort: 3333},
 	}, {
 		d: "GRPC: missing port",
-		c: Config{Export: "grpc", Host: "flp"},
+		c: Config{Export: "grpc", TargetHost: "flp"},
 	}, {
 		d: "Kafka: missing brokers",
 		c: Config{Export: "kafka"},
diff --git a/pkg/agent/config.go b/pkg/agent/config.go
index 2e408bef..4fdcda28 100644
--- a/pkg/agent/config.go
+++ b/pkg/agent/config.go
@@ -42,11 +42,11 @@ type Config struct {
 	// Accepted values for Flows are: grpc (default), kafka, ipfix+udp, ipfix+tcp or direct-flp.
 	// Accepted values for Packets are: grpc (default) or tcp
 	Export string `env:"EXPORT" envDefault:"grpc"`
-	// Host is the host name or IP of the Flow collector, when the EXPORT variable is
+	// Host is the host name or IP of the flow or packet collector, when the EXPORT variable is
 	// set to "grpc"
-	Host string `env:"HOST"`
-	// Port is the port the Flow collector, when the EXPORT variable is set to "grpc"
-	Port int `env:"PORT"`
+	TargetHost string `env:"TARGET_HOST"`
+	// Port is the port the flow or packet collector, when the EXPORT variable is set to "grpc"
+	TargetPort int `env:"TARGET_PORT"`
 	// GRPCMessageMaxFlows specifies the limit, in number of flows, of each GRPC message. Messages
 	// larger than that number will be split and submitted sequentially.
 	GRPCMessageMaxFlows int `env:"GRPC_MESSAGE_MAX_FLOWS" envDefault:"10000"`
@@ -193,14 +193,14 @@ type Config struct {
 func manageDeprecatedConfigs(cfg *Config) {
 	if len(cfg.FlowsTargetHost) != 0 {
 		clog.Infof("Using deprecated FlowsTargetHost %s", cfg.FlowsTargetHost)
-		cfg.Host = cfg.FlowsTargetHost
+		cfg.TargetHost = cfg.FlowsTargetHost
 	}
 
 	if cfg.FlowsTargetPort != 0 {
 		clog.Infof("Using deprecated FlowsTargetPort %d", cfg.FlowsTargetPort)
-		cfg.Port = cfg.FlowsTargetPort
+		cfg.TargetPort = cfg.FlowsTargetPort
 	} else if cfg.PCAServerPort != 0 {
 		clog.Infof("Using deprecated PCAServerPort %d", cfg.PCAServerPort)
-		cfg.Port = cfg.PCAServerPort
+		cfg.TargetPort = cfg.PCAServerPort
 	}
 }
diff --git a/pkg/agent/packets_agent.go b/pkg/agent/packets_agent.go
index cea30eeb..fd3df0af 100644
--- a/pkg/agent/packets_agent.go
+++ b/pkg/agent/packets_agent.go
@@ -135,12 +135,12 @@ func packetsAgent(cfg *Config,
 }
 
 func buildGRPCPacketExporter(cfg *Config) (node.TerminalFunc[[]*flow.PacketRecord], error) {
-	if cfg.Host == "" || cfg.Port == 0 {
+	if cfg.TargetHost == "" || cfg.TargetPort == 0 {
 		return nil, fmt.Errorf("missing target host or port for PCA: %s:%d",
-			cfg.Host, cfg.Port)
+			cfg.TargetHost, cfg.TargetPort)
 	}
 	plog.Info("starting gRPC Packet send")
-	pcapStreamer, err := exporter.StartGRPCPacketSend(cfg.Host, cfg.Port)
+	pcapStreamer, err := exporter.StartGRPCPacketSend(cfg.TargetHost, cfg.TargetPort)
 	if err != nil {
 		return nil, err
 	}
diff --git a/scripts/agent.yml b/scripts/agent.yml
index c7ad86c2..d6718481 100644
--- a/scripts/agent.yml
+++ b/scripts/agent.yml
@@ -34,11 +34,11 @@ spec:
             value: 200ms
           - name: LOG_LEVEL
             value: debug
-          - name: HOST
+          - name: TARGET_HOST
             valueFrom:
               fieldRef:
                 fieldPath: status.hostIP
-          - name: PORT
+          - name: TARGET_PORT
             value: "9999"
           - name: ENABLE_RTT
             value: "true"
-- 
GitLab