Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LabelValue obtain pod information function to add default value parameter #98

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions configs/rover_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
76 changes: 38 additions & 38 deletions docs/en/setup/configuration/process_discovery/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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). |
| 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). |
8 changes: 2 additions & 6 deletions pkg/process/finders/kubernetes/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,15 @@ 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]
if val != "" {
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 {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cases/profiling/task/network/base/rover_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
Loading
Loading