Skip to content

Commit f331816

Browse files
committed
Spike: test istio k8s discovery
1 parent 5268846 commit f331816

File tree

23 files changed

+762
-3
lines changed

23 files changed

+762
-3
lines changed

.github/workflows/integration-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ jobs:
402402
id: get-matrix-k8s
403403
run: |
404404
includes=""
405-
for service in "envoy"; do
405+
for service in "envoy" "istio"; do
406406
for arch in "amd64"; do
407407
includes="${includes},{\"SERVICE\": \"${service}\", \"ARCH\": \"${arch}\"}"
408408
done
@@ -430,7 +430,9 @@ jobs:
430430
cluster_name: kind
431431
- name: Deploy service under test
432432
run: |
433-
kubectl apply -f k8s/${{ matrix.SERVICE }}/*.yaml
433+
for f in k8s/${{ matrix.SERVICE }}/*.sh; do
434+
bash "$f"
435+
done
434436
- uses: actions/setup-go@v5
435437
with:
436438
go-version: ${{ env.GO_VERSION }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ smartagent-integration-test:
131131
integration-test-envoy-discovery-k8s:
132132
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_envoy_k8s -v -timeout 5m -count 1 ./...
133133

134+
.PHONY: integration-test-istio-discovery-k8s
135+
integration-test-istio-discovery-k8s:
136+
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_istio_k8s -v -timeout 5m -count 1 ./...
137+
134138
.PHONY: test-with-cover
135139
test-with-cover:
136140
@echo Verifying that all packages have test files to count in coverage
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#####################################################################################
2+
# This file is generated by the Splunk Distribution of the OpenTelemetry Collector. #
3+
# #
4+
# It reflects the default configuration bundled in the Collector executable for use #
5+
# in discovery mode (--discovery) and is provided for reference or customization. #
6+
# Please note that any changes made to this file will need to be reconciled during #
7+
# upgrades of the Collector. #
8+
#####################################################################################
9+
# prometheus/istio:
10+
# enabled: true
11+
# rule:
12+
# k8s_observer: type == "pod.container" and container_image matches "istio"
13+
# config:
14+
# default:
15+
# config:
16+
# scrape_configs:
17+
# - job_name: 'envoy'
18+
# metrics_path: /stats/prometheus
19+
# scrape_interval: 10s
20+
# static_configs:
21+
# - targets: ['`endpoint`']
22+
# metric_relabel_configs:
23+
# - source_labels: [__name__]
24+
# action: keep
25+
# regex: '(envoy_cluster_upstream_cx_active|envoy_cluster_upstream_cx_total|envoy_cluster_upstream_cx_connect_fail|envoy_cluster_upstream_cx_connect_ms|envoy_cluster_upstream_rq_active|envoy_cluster_upstream_rq_total|envoy_cluster_upstream_rq_timeout|envoy_cluster_upstream_rq_pending_active|envoy_cluster_upstream_rq_pending_overflow|envoy_cluster_upstream_rq_time|envoy_cluster_membership_total|envoy_cluster_membership_degraded|envoy_cluster_membership_excluded|envoy_listener_downstream_cx_active|envoy_listener_downstream_cx_total|envoy_listener_downstream_cx_transport_socket_connect_timeout|envoy_listener_downstream_cx_overflow|envoy_listener_downstream_cx_overload_reject|envoy_listener_downstream_global_cx_overflow)'
26+
# status:
27+
# metrics:
28+
# - status: successful
29+
# strict: envoy_cluster_upstream_cx_active
30+
# message: istio prometheus receiver is working!
31+
# statements:
32+
# - status: failed
33+
# regexp: "connection refused"
34+
# message: The container is not serving http connections.
35+
# - status: failed
36+
# regexp: "dial tcp: lookup"
37+
# message: Unable to resolve istio prometheus tcp endpoint
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#####################################################################################
2+
# Do not edit manually! #
3+
# All changes must be made to associated .tmpl file before running 'make bundle.d'. #
4+
#####################################################################################
5+
prometheus/istio:
6+
enabled: true
7+
rule:
8+
k8s_observer: type == "pod.container" and container_image matches "istio"
9+
config:
10+
default:
11+
config:
12+
scrape_configs:
13+
- job_name: 'envoy'
14+
metrics_path: /stats/prometheus
15+
scrape_interval: 10s
16+
static_configs:
17+
- targets: ['`endpoint`']
18+
metric_relabel_configs:
19+
- source_labels: [__name__]
20+
action: keep
21+
regex: '(envoy_cluster_upstream_cx_active|envoy_cluster_upstream_cx_total|envoy_cluster_upstream_cx_connect_fail|envoy_cluster_upstream_cx_connect_ms|envoy_cluster_upstream_rq_active|envoy_cluster_upstream_rq_total|envoy_cluster_upstream_rq_timeout|envoy_cluster_upstream_rq_pending_active|envoy_cluster_upstream_rq_pending_overflow|envoy_cluster_upstream_rq_time|envoy_cluster_membership_total|envoy_cluster_membership_degraded|envoy_cluster_membership_excluded|envoy_listener_downstream_cx_active|envoy_listener_downstream_cx_total|envoy_listener_downstream_cx_transport_socket_connect_timeout|envoy_listener_downstream_cx_overflow|envoy_listener_downstream_cx_overload_reject|envoy_listener_downstream_global_cx_overflow)'
22+
status:
23+
metrics:
24+
- status: successful
25+
strict: envoy_cluster_upstream_cx_active
26+
message: istio prometheus receiver is working!
27+
statements:
28+
- status: failed
29+
regexp: "connection refused"
30+
message: The container is not serving http connections.
31+
- status: failed
32+
regexp: "dial tcp: lookup"
33+
message: Unable to resolve istio prometheus tcp endpoint
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{ receiver "prometheus/istio" }}:
2+
enabled: true
3+
rule:
4+
k8s_observer: type == "pod.container" and container_image matches "istio"
5+
config:
6+
default:
7+
config:
8+
scrape_configs:
9+
- job_name: 'envoy'
10+
metrics_path: /stats/prometheus
11+
scrape_interval: 10s
12+
static_configs:
13+
- targets: ['`endpoint`']
14+
metric_relabel_configs:
15+
- source_labels: [__name__]
16+
action: keep
17+
regex: '(envoy_cluster_upstream_cx_active|envoy_cluster_upstream_cx_total|envoy_cluster_upstream_cx_connect_fail|envoy_cluster_upstream_cx_connect_ms|envoy_cluster_upstream_rq_active|envoy_cluster_upstream_rq_total|envoy_cluster_upstream_rq_timeout|envoy_cluster_upstream_rq_pending_active|envoy_cluster_upstream_rq_pending_overflow|envoy_cluster_upstream_rq_time|envoy_cluster_membership_total|envoy_cluster_membership_degraded|envoy_cluster_membership_excluded|envoy_listener_downstream_cx_active|envoy_listener_downstream_cx_total|envoy_listener_downstream_cx_transport_socket_connect_timeout|envoy_listener_downstream_cx_overflow|envoy_listener_downstream_cx_overload_reject|envoy_listener_downstream_global_cx_overflow)'
18+
status:
19+
metrics:
20+
- status: successful
21+
strict: envoy_cluster_upstream_cx_active
22+
message: istio prometheus receiver is working!
23+
statements:
24+
- status: failed
25+
regexp: "connection refused"
26+
message: The container is not serving http connections.
27+
- status: failed
28+
regexp: "dial tcp: lookup"
29+
message: Unable to resolve istio prometheus tcp endpoint

internal/confmapprovider/discovery/bundle/bundle_gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/apache.discovery.yaml.tmpl
2828
//go:generate discoverybundler --render --template bundle.d/receivers/envoy.discovery.yaml.tmpl
2929
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/envoy.discovery.yaml.tmpl
30+
//go:generate discoverybundler --render --template bundle.d/receivers/istio.discovery.yaml.tmpl
31+
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/istio.discovery.yaml.tmpl
3032
//go:generate discoverybundler --render --template bundle.d/receivers/jmx-cassandra.discovery.yaml.tmpl
3133
//go:generate discoverybundler --render --commented --dir ../../../../cmd/otelcol/config/collector/config.d.linux/receivers -t bundle.d/receivers/jmx-cassandra.discovery.yaml.tmpl
3234
//go:generate discoverybundler --render --template bundle.d/receivers/kafkametrics.discovery.yaml.tmpl

internal/confmapprovider/discovery/bundle/bundledfs_other_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestBundleDir(t *testing.T) {
2929
require.Equal(t, []string{
3030
"bundle.d/receivers/apache.discovery.yaml",
3131
"bundle.d/receivers/envoy.discovery.yaml",
32+
"bundle.d/receivers/istio.discovery.yaml",
3233
"bundle.d/receivers/jmx-cassandra.discovery.yaml",
3334
"bundle.d/receivers/kafkametrics.discovery.yaml",
3435
"bundle.d/receivers/mongodb.discovery.yaml",

internal/confmapprovider/discovery/bundle/bundledfs_others.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
2828
//go:embed bundle.d/receivers/apache.discovery.yaml
2929
//go:embed bundle.d/receivers/envoy.discovery.yaml
30+
//go:embed bundle.d/receivers/istio.discovery.yaml
3031
//go:embed bundle.d/receivers/jmx-cassandra.discovery.yaml
3132
//go:embed bundle.d/receivers/kafkametrics.discovery.yaml
3233
//go:embed bundle.d/receivers/mongodb.discovery.yaml

internal/confmapprovider/discovery/bundle/bundledfs_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
//go:embed bundle.d/extensions/k8s-observer.discovery.yaml
2828
//go:embed bundle.d/receivers/apache.discovery.yaml
2929
//go:embed bundle.d/receivers/envoy.discovery.yaml
30+
//go:embed bundle.d/receivers/istio.discovery.yaml
3031
//go:embed bundle.d/receivers/jmx-cassandra.discovery.yaml
3132
//go:embed bundle.d/receivers/kafkametrics.discovery.yaml
3233
//go:embed bundle.d/receivers/mongodb.discovery.yaml

internal/confmapprovider/discovery/bundle/bundledfs_windows_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestBundleDir(t *testing.T) {
2929
require.Equal(t, []string{
3030
"bundle.d/receivers/apache.discovery.yaml",
3131
"bundle.d/receivers/envoy.discovery.yaml",
32+
"bundle.d/receivers/istio.discovery.yaml",
3233
"bundle.d/receivers/jmx-cassandra.discovery.yaml",
3334
"bundle.d/receivers/kafkametrics.discovery.yaml",
3435
"bundle.d/receivers/mongodb.discovery.yaml",

internal/confmapprovider/discovery/bundle/components.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
receivers = []string{
3434
"apache",
3535
"envoy",
36+
"istio",
3637
"jmx-cassandra",
3738
"kafkametrics",
3839
"mongodb",
@@ -68,6 +69,7 @@ var (
6869
windows := map[string]struct{}{
6970
"apache": {},
7071
"envoy": {},
72+
"istio": {},
7173
"jmx-cassandra": {},
7274
"kafkametrics": {},
7375
"mongodb": {},

internal/receiver/discoveryreceiver/endpoint_tracker_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ var (
509509
KubeletEndpointPort: 1,
510510
},
511511
}
512+
513+
podContainerEndpoint = observer.Endpoint{
514+
ID: observer.EndpointID("pod.container.id"),
515+
Target: "pod.container.target",
516+
Details: &observer.PodContainer{
517+
Name: "k8s.node.name",
518+
Image: "redis:123",
519+
ContainerID: "123",
520+
Pod: observer.Pod{
521+
Name: "redis",
522+
},
523+
},
524+
}
512525
)
513526

514527
func expectedPLogs() plog.Logs {

internal/receiver/discoveryreceiver/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (r Rule) MarshalText() (text []byte, err error) {
5252

5353
// ruleRe is used to verify the rule starts type check.
5454
var ruleRe = regexp.MustCompile(
55-
fmt.Sprintf(`^type\s*==\s*(%q|%q|%q|%q|%q|%q)`, observer.PodType, observer.K8sServiceType, observer.PortType, observer.HostPortType, observer.ContainerType, observer.K8sNodeType),
55+
fmt.Sprintf(`^type\s*==\s*(%q|%q|%q|%q|%q|%q|%q)`, observer.PodType, observer.K8sServiceType, observer.PortType, observer.HostPortType, observer.ContainerType, observer.K8sNodeType, observer.PodContainerType),
5656
)
5757

5858
// newRule creates a new rule instance.

internal/receiver/discoveryreceiver/rule_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ func TestRuleEval(t *testing.T) {
7373
want: true,
7474
wantErr: false,
7575
},
76+
{
77+
name: "basic pod.container",
78+
args: args{podContainerEndpoint, `type == "pod.container" && container_image matches "redis"`},
79+
want: true,
80+
wantErr: false,
81+
},
7682
{
7783
name: "relocated type builtin",
7884
args: args{k8sNodeEndpoint, `type == "k8s.node" && typeOf("some string") == "string"`},

k8s/envoy/envoy.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
kubectl apply -f $SCRIPT_DIR/envoy.yaml

k8s/istio/istio.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# These steps install istio, with a demo profile, set up the default namespace to inject sidecars, CRDs, and the sample application under test.
4+
# See https://istio.io/latest/docs/setup/getting-started/#bookinfo for more info.
5+
6+
curl -L https://istio.io/downloadIstio | sh -
7+
wget https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/demo-profile-no-gateways.yaml
8+
$( find . -name istio-*)/bin/istioctl install -f demo-profile-no-gateways.yaml -y
9+
kubectl label namespace default istio-injection=enabled
10+
kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \
11+
{ kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.2.0" | kubectl apply -f -; }
12+
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.24/samples/bookinfo/platform/kube/bookinfo.yaml

0 commit comments

Comments
 (0)