Skip to content

Commit

Permalink
chore: added e2e tests for extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Ankit152 <[email protected]>
  • Loading branch information
Ankit152 committed Nov 21, 2024
1 parent a2fd9b4 commit effe1d9
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .chloggen/service-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: support for creating a service for extensions when ports are specified.

# One or more tracking issues related to the change
issues: [3460]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
6 changes: 5 additions & 1 deletion apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ func (c *Config) GetExtensionPorts(logger logr.Logger) ([]corev1.ServicePort, er
return c.getPortsForComponentKinds(logger, KindExtension)
}

func (c *Config) GetAllPorts(logger logr.Logger) ([]corev1.ServicePort, error) {
func (c *Config) GetReceiverAndExporterPorts(logger logr.Logger) ([]corev1.ServicePort, error) {
return c.getPortsForComponentKinds(logger, KindReceiver, KindExporter)
}

func (c *Config) GetAllPorts(logger logr.Logger) ([]corev1.ServicePort, error) {
return c.getPortsForComponentKinds(logger, KindReceiver, KindExporter, KindExtension)
}

func (c *Config) GetEnvironmentVariables(logger logr.Logger) ([]corev1.EnvVar, error) {
return c.getEnvironmentVariablesForComponentKinds(logger, KindReceiver)
}
Expand Down
6 changes: 2 additions & 4 deletions internal/manifests/collector/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
const (
headlessLabel = "operator.opentelemetry.io/collector-headless-service"
monitoringLabel = "operator.opentelemetry.io/collector-monitoring-service"
extensionService = "operator.opentelemetry.io/collector-extension-service"
serviceTypeLabel = "operator.opentelemetry.io/collector-service-type"
valueExists = "Exists"
)
Expand Down Expand Up @@ -111,9 +110,8 @@ func MonitoringService(params manifests.Params) (*corev1.Service, error) {
}

func ExtensionService(params manifests.Params) (*corev1.Service, error) {
name := naming.Service(params.OtelCol.Name)
name := naming.ExtensionService(params.OtelCol.Name)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{})
labels[extensionService] = valueExists
labels[serviceTypeLabel] = ExtensionServiceType.String()

annotations, err := manifestutils.Annotations(params.OtelCol, params.Config.AnnotationsFilter())
Expand Down Expand Up @@ -154,7 +152,7 @@ func Service(params manifests.Params) (*corev1.Service, error) {
return nil, err
}

ports, err := params.OtelCol.Spec.Config.GetAllPorts(params.Log)
ports, err := params.OtelCol.Spec.Config.GetReceiverAndExporterPorts(params.Log)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions internal/naming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func MonitoringService(otelcol string) string {
return DNSName(Truncate("%s-monitoring", 63, Service(otelcol)))
}

// ExtensionService builds the name for the extension service based on the instance.
func ExtensionService(otelcol string) string {
return DNSName(Truncate("%s-extension", 63, Service(otelcol)))
}

// Service builds the service name based on the instance.
func Service(otelcol string) string {
return DNSName(Truncate("%s-collector", 63, otelcol))
Expand Down
148 changes: 148 additions & 0 deletions tests/e2e/extension/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
apiVersion: v1
items:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: jaeger-inmemory-collector
spec:
template:
spec:
containers:
- ports:
- containerPort: 16686
name: jaeger
protocol: TCP
- containerPort: 8888
name: metrics
protocol: TCP
- containerPort: 4317
name: otlp-grpc
protocol: TCP
- containerPort: 4318
name: otlp-http
protocol: TCP
kind: List
metadata:
resourceVersion: ""
---
apiVersion: v1
kind: Service
metadata:
name: jaeger-inmemory-collector
spec:
ports:
- name: jaeger
port: 16686
protocol: TCP
targetPort: 16686
- appProtocol: grpc
name: otlp-grpc
port: 4317
protocol: TCP
targetPort: 4317
- appProtocol: http
name: otlp-http
port: 4318
protocol: TCP
targetPort: 4318
---
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.openshift.io/serving-cert-secret-name: jaeger-inmemory-collector-headless-tls
labels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/name: jaeger-inmemory-collector
app.kubernetes.io/part-of: opentelemetry
app.kubernetes.io/version: latest
operator.opentelemetry.io/collector-headless-service: Exists
operator.opentelemetry.io/collector-service-type: headless
name: jaeger-inmemory-collector-headless
ownerReferences:
- apiVersion: opentelemetry.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: OpenTelemetryCollector
name: jaeger-inmemory
spec:
clusterIP: None
clusterIPs:
- None
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: jaeger
port: 16686
protocol: TCP
targetPort: 16686
- appProtocol: grpc
name: otlp-grpc
port: 4317
protocol: TCP
targetPort: 4317
- appProtocol: http
name: otlp-http
port: 4318
protocol: TCP
targetPort: 4318
selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/name: jaeger-inmemory-collector-monitoring
app.kubernetes.io/part-of: opentelemetry
app.kubernetes.io/version: latest
operator.opentelemetry.io/collector-monitoring-service: Exists
operator.opentelemetry.io/collector-service-type: monitoring
name: jaeger-inmemory-collector-monitoring
spec:
ports:
- name: monitoring
port: 8888
protocol: TCP
targetPort: 8888
selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: v1
kind: Service
metadata:
name: "jaeger-inmemory-collector-extension"
labels:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
app.kubernetes.io/version: latest
operator.opentelemetry.io/collector-service-type: extension
spec:
selector:
app.kubernetes.io/component: opentelemetry-collector
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/part-of: opentelemetry
ports:
- name: "jaeger-query"
port: 16686
targetPort: 16686
status:
loadBalancer: {}
30 changes: 30 additions & 0 deletions tests/e2e/extension/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: jaeger-inmemory
spec:
image: jaegertracing/jaeger-snapshot:latest
config:
service:
extensions: [jaeger_storage, jaeger_query]
pipelines:
traces:
receivers: [otlp]
exporters: [jaeger_storage_exporter]
extensions:
jaeger_query:
storage:
traces: memstore
jaeger_storage:
backends:
memstore:
memory:
max_traces: 100000
receivers:
otlp:
protocols:
grpc:
http:
exporters:
jaeger_storage_exporter:
trace_storage: memstore
14 changes: 14 additions & 0 deletions tests/e2e/extension/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: extension-test
spec:
steps:
- name: step-00
try:
- apply:
file: 00-install.yaml
- assert:
file: 00-assert.yaml

0 comments on commit effe1d9

Please sign in to comment.