You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2023/08/23 08:01:12 UTC

[skywalking-rover] branch main updated: Update `LabelValue` obtain pod information function to add default value parameter (#98)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git


The following commit(s) were added to refs/heads/main by this push:
     new 1201363  Update `LabelValue` obtain pod information function to add default value parameter (#98)
1201363 is described below

commit 1201363f4526660bb2d3cf5ad3b11a2b9aee3a48
Author: mrproliu <74...@qq.com>
AuthorDate: Wed Aug 23 16:01:06 2023 +0800

    Update `LabelValue` obtain pod information function to add default value parameter (#98)
---
 CHANGES.md                                         |  1 +
 configs/rover_configs.yaml                         |  4 +-
 .../configuration/process_discovery/kubernetes.md  | 76 +++++++++++-----------
 pkg/process/finders/kubernetes/template.go         |  8 +--
 .../profiling/task/network/base/rover_configs.yaml |  4 +-
 .../cases/profiling/task/network/envoy/rover.yaml  |  4 +-
 6 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index e66497d..dfb6eca 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,7 @@ Release Notes.
 ------------------
 #### Features
 * Enhance compatibility when profiling with SSL.
+* Update `LabelValue` obtain pod information function to add default value parameter.
 
 #### Bug Fixes
 
diff --git a/configs/rover_configs.yaml b/configs/rover_configs.yaml
index f9af6c9..90132d5 100644
--- a/configs/rover_configs.yaml
+++ b/configs/rover_configs.yaml
@@ -83,7 +83,7 @@ process_discovery:
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_HAS_ENVOY:.Pod.HasContainer "istio-proxy"}
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_CONTAINER_IS_ENVOY:eq .Container.Name "istio-proxy"}
         layer: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_LAYER:MESH_DP}
-        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" }}}
+        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" ""}}}
         instance_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_INSTANCE_NAME:{{.Pod.Name}}}
         process_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_PROCESS_NAME:{{.Process.ExeName}}}
         labels: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_LABELS:mesh-envoy}
@@ -92,7 +92,7 @@ process_discovery:
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_HAS_ENVOY:.Pod.HasContainer "istio-proxy"}
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_CONTAINER_NOT_ENVOY:ne .Container.Name "istio-proxy"}
         layer: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_LAYER:MESH}
-        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" }}}
+        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" ""}}}
         instance_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_INSTANCE_NAME:{{.Pod.Name}}}
         process_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_PROCESS_NAME:{{.Process.ExeName}}}
         labels: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_LABELS:mesh-application}
diff --git a/docs/en/setup/configuration/process_discovery/kubernetes.md b/docs/en/setup/configuration/process_discovery/kubernetes.md
index 87fd93a..2640427 100644
--- a/docs/en/setup/configuration/process_discovery/kubernetes.md
+++ b/docs/en/setup/configuration/process_discovery/kubernetes.md
@@ -6,18 +6,18 @@ After finding the process, it would collect the metadata of the process when the
 
 ## Configuration
 
-| Name | Default | Environment Key | Description |
-|------|---------|-----------------|-------------|
-| process_discovery.kubernetes.active | false | ROVER_PROCESS_DISCOVERY_KUBERNETES_ACTIVE | Is active the kubernetes process discovery. |
-| process_discovery.kubernetes.node_name |  | ROVER_PROCESS_DISCOVERY_KUBERNETES_NODE_NAME | Current deployed node name, it could be inject by `spec.nodeName`. |
-| process_discovery.kubernetes.namespaces | | ROVER_PROCESS_DISCOVERY_KUBERNETES_NAMESPACES | Including pod by namespaces, if empty means including all namespaces. Multiple namespaces split by ",". |
-| process_discovery.kubernetes.analyzers | | | Declare how to build the process. The istio and k8s resources are active by default. |
-| process_discovery.kubernetes.analyzers.active | | | Set is active analyzer. |
-| process_discovery.kubernetes.analyzers.filters | | | Define which process is match to current process builder. |
-| process_discovery.kubernetes.analyzers.service_name | | | The Service Name of the process entity. |
-| process_discovery.kubernetes.analyzers.instance_name | | | The Service Instance Name of the process entity, by default, the instance name is the host IP v4 address from "en0" net interface. |
-| process_discovery.kubernetes.analyzers.process_name | | | The Process Name of the process entity, by default, the process name is the executable name of the process. |
-| process_discovery.kubernetes.analyzers.labels | | | The Process Labels, used to aggregate similar process from service entity. Multiple labels split by ",". |
+| Name                                                 | Default | Environment Key                               | Description                                                                                                                        |
+|------------------------------------------------------|---------|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
+| process_discovery.kubernetes.active                  | false   | ROVER_PROCESS_DISCOVERY_KUBERNETES_ACTIVE     | Is active the kubernetes process discovery.                                                                                        |
+| process_discovery.kubernetes.node_name               |         | ROVER_PROCESS_DISCOVERY_KUBERNETES_NODE_NAME  | Current deployed node name, it could be inject by `spec.nodeName`.                                                                 |
+| process_discovery.kubernetes.namespaces              |         | ROVER_PROCESS_DISCOVERY_KUBERNETES_NAMESPACES | Including pod by namespaces, if empty means including all namespaces. Multiple namespaces split by ",".                            |
+| process_discovery.kubernetes.analyzers               |         |                                               | Declare how to build the process. The istio and k8s resources are active by default.                                               |
+| process_discovery.kubernetes.analyzers.active        |         |                                               | Set is active analyzer.                                                                                                            |
+| process_discovery.kubernetes.analyzers.filters       |         |                                               | Define which process is match to current process builder.                                                                          |
+| process_discovery.kubernetes.analyzers.service_name  |         |                                               | The Service Name of the process entity.                                                                                            |
+| process_discovery.kubernetes.analyzers.instance_name |         |                                               | The Service Instance Name of the process entity, by default, the instance name is the host IP v4 address from "en0" net interface. |
+| process_discovery.kubernetes.analyzers.process_name  |         |                                               | The Process Name of the process entity, by default, the process name is the executable name of the process.                        |
+| process_discovery.kubernetes.analyzers.labels        |         |                                               | The Process Labels, used to aggregate similar process from service entity. Multiple labels split by ",".                           |
 
 ## Process Analyze
 
@@ -39,24 +39,24 @@ Is the same with the [process context in scanner](./scanner.md#process), but doe
 
 Provide current pod information and judgments.
 
-| Name | Argument |  Example  | Description |
-|------|--------- |-----------|-------------|
-| Name | None | `eq .Pod.Name "test-pod-name"` | The name of the current pod. The example shows the pod name is equal to `test-pod-name`. |
-| Namespace | None | `eq .Pod.Namespace "test-namesapce"` | The name of the current pod namespace. The example shows the pod namespace name is equal to `test-namespace`. |
-| Node | None | `eq .Pod.Node "test-node"` | The name of the node deployed. The example shows the pod node name is equal to `test-node`. |
-| LabelValue | KeyNames | `eq .Pod.LavelValue "a,b" "v"` | The label value of the label keys, If provide multiple keys, if any key has value, then don't need to get other values. The example shows the pod has anyone `a` or `b` label key, and the value matches to `v`. |
-| ServiceName | None | `eq .Pod.ServiceName "test-service"` | The service name of the pod. The example shows current pods matched service name is `test-service`. |
-| HasContainer | Container name | `.Pod.HasContainer "istio-proxy"` | The pod has the appointed container name. |
-| LabelSelector | selector | `.Pod.LabelSelector` | The pod is matches the label selector. For more details, please read the [official documentation](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors). |
-| HasServiceName | None | `.Pod.HasServiceName` | The pod has the matched service. |
+| Name           | Argument       | Example                              | Description                                                                                                                                                                                                      |
+|----------------|----------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Name           | None           | `eq .Pod.Name "test-pod-name"`       | The name of the current pod. The example shows the pod name is equal to `test-pod-name`.                                                                                                                         |
+| Namespace      | None           | `eq .Pod.Namespace "test-namesapce"` | The name of the current pod namespace. The example shows the pod namespace name is equal to `test-namespace`.                                                                                                    |
+| Node           | None           | `eq .Pod.Node "test-node"`           | The name of the node deployed. The example shows the pod node name is equal to `test-node`.                                                                                                                      |
+| LabelValue     | KeyNames       | `eq .Pod.LavelValue "a,b" "v"`       | The label value of the label keys, If provide multiple keys, if any key has value, then don't need to get other values. The example shows the pod has anyone `a` or `b` label key, and the value matches to `v`. |
+| ServiceName    | None           | `eq .Pod.ServiceName "test-service"` | The service name of the pod. The example shows current pods matched service name is `test-service`.                                                                                                              |
+| HasContainer   | Container name | `.Pod.HasContainer "istio-proxy"`    | The pod has the appointed container name.                                                                                                                                                                        |
+| LabelSelector  | selector       | `.Pod.LabelSelector`                 | The pod is matches the label selector. For more details, please read the [official documentation](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors).                    |
+| HasServiceName | None           | `.Pod.HasServiceName`                | The pod has the matched service.                                                                                                                                                                                 |
 
 #### Container Context
 
 Provide current container(under the pod) information.
 
-| Name | Argument | Example | Description |
-|------|--------- |-----------|-------------|
-| Name | None | `eq .Container.Name "istio-proxy"`| The name of the current container under the pod. The examples show the container name is equal to `istio-proxy`. |
+| Name  | Argument | Example                             | Description                                                                                                      |
+|-------|----------|-------------------------------------|------------------------------------------------------------------------------------------------------------------|
+| Name  | None     | `eq .Container.Name "istio-proxy"`  | The name of the current container under the pod. The examples show the container name is equal to `istio-proxy`. |
 
 ### Entity
 The entity including `layer`, `serviceName`, `instanceName`, `processName` and `labels` properties.
@@ -75,21 +75,21 @@ Same with the [process context in the scanner](./scanner.md#process).
 
 The information on the current pod.
 
-| Name | Argument |  Example  | Description |
-|------|--------- |-----------|-------------|
-| Name | None | `{{.Pod.Name}}` | The name of current pod. |
-| Namespace | None | `{{.Pod.Namespace}}` | The name of current pod namespace. |
-| Node | None | `{{.Pod.Node}}` | The name of the node deployed. |
-| LabelValue | KeyNames | `{{.Pod.LavelValue "a,b"}}` | The label value of the label keys, If provide multiple keys, if any key has value, then don't need to get other values. |
-| ServiceName | None | `{{.Pod.ServiceName}}` | The service name of the pod. If the pod hasn't matched service, then return an empty string. |
-| FindContainer | ContainerName | `{{.Pod.FindContainer "test"}}` | Find the Container context by container name. |
+| Name          | Argument          | Example                           | Description                                                                                                                                                                          |
+|---------------|-------------------|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| Name          | None              | `{{.Pod.Name}}`                   | The name of current pod.                                                                                                                                                             |
+| Namespace     | None              | `{{.Pod.Namespace}}`              | The name of current pod namespace.                                                                                                                                                   |
+| Node          | None              | `{{.Pod.Node}}`                   | The name of the node deployed.                                                                                                                                                       |
+| LabelValue    | KeyNames, Default | `{{.Pod.LabelValue "a,b" "v"}}`   | The label value of the label keys, If provide multiple keys, if any key has value, then don't need to get other values. If all keys don't have value, then return the default value. |
+| ServiceName   | None              | `{{.Pod.ServiceName}}`            | The service name of the pod. If the pod hasn't matched service, then return an empty string.                                                                                         |
+| FindContainer | ContainerName     | `{{.Pod.FindContainer "test"}}`   | Find the Container context by container name.                                                                                                                                        |
 
 #### Container
 
 The information of the current container under the pod.
 
-| Name | Argument | Example | Description |
-|------|--------- |-----------|-------------|
-| Name | None | `{{.Container.Name}}`| The name of the current container under the pod. |
-| ID | None | `{{.Container.ID}}`| The id of the current container under the pod. |
-| EnvValue | KeyNames | `{{.Container.EnvValue "a,b"}}`| The environment value of the first non-value key in the provided candidates(Iterate from left to right).  |
\ No newline at end of file
+| Name     | Argument | Example                                                                 | Description                                                                                              |
+|----------|----------|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
+| Name     | None     | `{{.Container.Name}}`  The name of the current container under the pod. |                                                                                                          |
+| ID       | None     | `{{.Container.ID}}`                                                     | The id of the current container under the pod.                                                           |
+| EnvValue | KeyNames | `{{.Container.EnvValue "a,b"}}`                                         | The environment value of the first non-value key in the provided candidates(Iterate from left to right). |
\ No newline at end of file
diff --git a/pkg/process/finders/kubernetes/template.go b/pkg/process/finders/kubernetes/template.go
index f77c409..d54e3c5 100644
--- a/pkg/process/finders/kubernetes/template.go
+++ b/pkg/process/finders/kubernetes/template.go
@@ -107,7 +107,7 @@ func (p *TemplatePod) FindContainer(name string) (*TemplateContainer, error) {
 	return &TemplateContainer{pc: container}, nil
 }
 
-func (p *TemplatePod) LabelValue(names string) (string, error) {
+func (p *TemplatePod) LabelValue(names, def string) (string, error) {
 	namesArray := strings.Split(names, ",")
 	for _, name := range namesArray {
 		val := p.pc.Pod.Labels[name]
@@ -115,11 +115,7 @@ func (p *TemplatePod) LabelValue(names string) (string, error) {
 			return val, nil
 		}
 	}
-	actualNames := make([]string, 0)
-	for k := range p.pc.Pod.Labels {
-		actualNames = append(actualNames, k)
-	}
-	return "", fmt.Errorf("could not found matches label, want names: %v, actual names: %v", namesArray, actualNames)
+	return def, nil
 }
 
 func (p *TemplatePod) ServiceName() string {
diff --git a/test/e2e/cases/profiling/task/network/base/rover_configs.yaml b/test/e2e/cases/profiling/task/network/base/rover_configs.yaml
index 4bbf8cb..1f0def5 100644
--- a/test/e2e/cases/profiling/task/network/base/rover_configs.yaml
+++ b/test/e2e/cases/profiling/task/network/base/rover_configs.yaml
@@ -97,7 +97,7 @@ process_discovery:
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_HAS_ENVOY:.Pod.HasContainer "istio-proxy"}
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_CONTAINER_IS_ENVOY:eq .Container.Name "istio-proxy"}
         layer: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_LAYER:MESH_DP}
-        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" }}}
+        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" ""}}}
         instance_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_INSTANCE_NAME:{{.Pod.Name}}}
         process_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_PROCESS_NAME:{{.Process.ExeName}}}
         labels: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_LABELS:mesh-envoy}
@@ -106,7 +106,7 @@ process_discovery:
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_HAS_ENVOY:.Pod.HasContainer "istio-proxy"}
           - ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_CONTAINER_NOT_ENVOY:ne .Container.Name "istio-proxy"}
         layer: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_LAYER:MESH}
-        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" }}}
+        service_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_SERVICE_NAME:{{.Pod.Namespace}}::{{.Pod.LabelValue "service.istio.io/canonical-name,app.kubernetes.io/name,app" ""}}}
         instance_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_INSTANCE_NAME:{{.Pod.Name}}}
         process_name: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_PROCESS_NAME:{{.Process.ExeName}}}
         labels: ${ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_LABELS:mesh-application}
diff --git a/test/e2e/cases/profiling/task/network/envoy/rover.yaml b/test/e2e/cases/profiling/task/network/envoy/rover.yaml
index 90fa0de..de72937 100644
--- a/test/e2e/cases/profiling/task/network/envoy/rover.yaml
+++ b/test/e2e/cases/profiling/task/network/envoy/rover.yaml
@@ -90,9 +90,9 @@ spec:
             - name: ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_PROCESS_NAME
               value: "{{.Process.ExeNameInCommandLine}}"
             - name: ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_ENVOY_INSTANCE_NAME
-              value: "{{.Pod.LabelValue \"service.istio.io/canonical-name,app.kubernetes.io/name,app\" }}"
+              value: "{{.Pod.LabelValue \"service.istio.io/canonical-name,app.kubernetes.io/name,app\" \"\"}}"
             - name: ROVER_PROCESS_DISCOVERY_KUBERNETES_ANALYZER_ISTIO_APPLICATION_INSTANCE_NAME
-              value: "{{.Pod.LabelValue \"service.istio.io/canonical-name,app.kubernetes.io/name,app\" }}"
+              value: "{{.Pod.LabelValue \"service.istio.io/canonical-name,app.kubernetes.io/name,app\" \"\"}}"
       hostPID: true
       hostNetwork: true
       dnsPolicy: ClusterFirstWithHostNet