Skip to content

Commit

Permalink
Make sure OTLP exporter can report data to OTLP ingress/route without…
Browse files Browse the repository at this point in the history
… additional configuration (open-telemetry#1981)

* Make sure OTLP export can report data to OTLP ingress/route without additional configuration.

Signed-off-by: Pavol Loffay <[email protected]>

* Trim CRD description size

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

* Fix

Signed-off-by: Pavol Loffay <[email protected]>

---------

Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay authored Aug 16, 2023
1 parent d8ffd1e commit 6ffb075
Show file tree
Hide file tree
Showing 30 changed files with 1,718 additions and 3,921 deletions.
21 changes: 21 additions & 0 deletions .chloggen/1967-ingress-path.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make sure OTLP export can report data to OTLP ingress/route without additional configuration

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

# (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: |
The ingress can be configured to create a single host with multiple paths or
multiple hosts with subdomains (one per receiver port).
The path from OpenShift route was removed.
The port names are truncate to 15 characters. Users with custom receivers
which create ports with longer name might need to update their configuration.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true"
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true,maxDescLen=200"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -484,4 +484,4 @@ catalog-build: opm bundle-build bundle-push ## Build a catalog image.
# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
docker push $(CATALOG_IMG)
docker push $(CATALOG_IMG)
15 changes: 15 additions & 0 deletions apis/v1alpha1/ingress_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ const (
// and re-encrypt using a new certificate.
TLSRouteTerminationTypeReencrypt TLSRouteTerminationType = "reencrypt"
)

// IngressRuleType defines how the collector receivers will be exposed in the Ingress.
//
// +kubebuilder:validation:Enum=path;subdomain
type IngressRuleType string

const (
// IngressRuleTypePath configures Ingress to use single host with multiple paths.
// This configuration might require additional ingress setting to rewrite paths.
IngressRuleTypePath IngressRuleType = "path"

// IngressRuleTypeSubdomain configures Ingress to use multiple hosts - one for each exposed
// receiver port. The port name is used as a subdomain for the host defined in the Ingress e.g. otlp-http.example.com.
IngressRuleTypeSubdomain IngressRuleType = "subdomain"
)
8 changes: 7 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ const (
// SEE: OpenTelemetryCollector.spec.ports[index].
type Ingress struct {
// Type default value is: ""
// Supported types are: ingress
// Supported types are: ingress, route
Type IngressType `json:"type,omitempty"`

// RuleType defines how Ingress exposes collector receivers.
// IngressRuleTypePath ("path") exposes each receiver port on a unique path on single domain defined in Hostname.
// IngressRuleTypeSubdomain ("subdomain") exposes each receiver port on a unique subdomain of Hostname.
// Default is IngressRuleTypePath ("path").
RuleType IngressRuleType `json:"ruleType,omitempty"`

// Hostname by which the ingress proxy can be reached.
// +optional
Hostname string `json:"hostname,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (r *OpenTelemetryCollector) Default() {
if r.Spec.Ingress.Type == IngressTypeRoute && r.Spec.Ingress.Route.Termination == "" {
r.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
}
if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Ingress.RuleType == "" {
r.Spec.Ingress.RuleType = IngressRuleTypePath
}
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-opentelemetrycollector,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1alpha1,name=vopentelemetrycollectorcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
Expand Down Expand Up @@ -248,6 +251,9 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
ModeDeployment, ModeDaemonSet, ModeStatefulSet,
)
}
if r.Spec.Ingress.RuleType == IngressRuleTypeSubdomain && (r.Spec.Ingress.Hostname == "" || r.Spec.Ingress.Hostname == "*") {
return fmt.Errorf("a valid Ingress hostname has to be defined for subdomain ruleType")
}

if r.Spec.LivenessProbe != nil {
if r.Spec.LivenessProbe.InitialDelaySeconds != nil && *r.Spec.LivenessProbe.InitialDelaySeconds < 0 {
Expand Down
11 changes: 11 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ func TestOTELColValidatingWebhook(t *testing.T) {
},
expectedErr: "the OpenTelemetry Collector mode is set to sidecar, which does not support the attribute 'AdditionalContainers'",
},
{
name: "missing ingress hostname for subdomain ruleType",
otelcol: OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
Ingress: Ingress{
RuleType: IngressRuleTypeSubdomain,
},
},
},
expectedErr: "a valid Ingress hostname has to be defined for subdomain ruleType",
},
}

for _, test := range tests {
Expand Down
Loading

0 comments on commit 6ffb075

Please sign in to comment.