Skip to content

Commit

Permalink
Merge branch 'main' into feat/3086-allow-configuration-prometheus-cr
Browse files Browse the repository at this point in the history
# Conflicts:
#	bundle/community/manifests/opentelemetry-operator.clusterserviceversion.yaml
#	bundle/openshift/manifests/opentelemetry-operator.clusterserviceversion.yaml
  • Loading branch information
dexter0195 committed Jan 9, 2025
2 parents 636b801 + 51f6888 commit 9ce60cd
Show file tree
Hide file tree
Showing 43 changed files with 304 additions and 174 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix-allocator-metric.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: breaking

# 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: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "change metric `opentelemetry_allocator_targets_remaining` type from counter to gauge"

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

# (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:
16 changes: 16 additions & 0 deletions .chloggen/operator32.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. 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: Add support for Kubernetes `1.32`

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

# (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:
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: Ensure no changes to the CHANGELOG
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-go@v5
id: setup-go
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: Cache tools
uses: actions/cache@v4
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: Cache tools
uses: actions/cache@v4
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# should be compatible with them.
kube-version:
- "1.23"
- "1.31"
- "1.32"
group:
- e2e
- e2e-automatic-rbac
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
uses: actions/setup-go@v5
id: setup-go
with:
go-version: "~1.22.4"
go-version: "~1.23.4"
- name: Cache tools
uses: actions/cache@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: "generate release resources"
run: make release-artifacts IMG_PREFIX="ghcr.io/open-telemetry/opentelemetry-operator" VERSION=${DESIRED_VERSION}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
matrix:
kube-version:
- "1.23"
- "1.31"
- "1.32"

steps:

- name: Set up Go
uses: actions/setup-go@v5
id: setup-go
with:
go-version: "~1.22.4"
go-version: "~1.23.4"

- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
concurrency: 4
concurrency: 3
timeout: 5m
issues-exit-code: 1
tests: true
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ endif

START_KIND_CLUSTER ?= true

KUBE_VERSION ?= 1.31
KUBE_VERSION ?= 1.32
KIND_CONFIG ?= kind-$(KUBE_VERSION).yaml
KIND_CLUSTER_NAME ?= "otel-operator"

Expand Down Expand Up @@ -494,9 +494,9 @@ CHAINSAW ?= $(LOCALBIN)/chainsaw
# renovate: datasource=go depName=sigs.k8s.io/kustomize/kustomize/v5
KUSTOMIZE_VERSION ?= v5.5.0
# renovate: datasource=go depName=sigs.k8s.io/controller-tools/cmd/controller-gen
CONTROLLER_TOOLS_VERSION ?= v0.16.5
CONTROLLER_TOOLS_VERSION ?= v0.17.0
# renovate: datasource=go depName=github.com/golangci/golangci-lint/cmd/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.57.2
GOLANGCI_LINT_VERSION ?= v1.63.4
# renovate: datasource=go depName=sigs.k8s.io/kind
KIND_VERSION ?= v0.26.0
# renovate: datasource=go depName=github.com/kyverno/chainsaw
Expand Down
3 changes: 2 additions & 1 deletion apis/v1beta1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v1beta1
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"reflect"
"regexp"
Expand Down Expand Up @@ -452,7 +453,7 @@ func (s *Service) MetricsEndpoint(logger logr.Logger) (string, int32, error) {
errMsg := fmt.Sprintf("couldn't determine metrics port from configuration: %s",
telemetry.Metrics.Address)
logger.Info(errMsg)
return "", 0, fmt.Errorf(errMsg)
return "", 0, errors.New(errMsg)
}

// The regex below matches on strings that end with a colon followed by 1 or more numbers (representing the port).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-12-28T16:14:39Z"
createdAt: "2024-12-31T13:16:02Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: opentelemetry-operator-system/opentelemetry-operator-serving-cert
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: opentelemetry-operator-system/opentelemetry-operator-serving-cert
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-12-28T16:14:44Z"
createdAt: "2024-12-31T13:16:02Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: opentelemetry-operator-system/opentelemetry-operator-serving-cert
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: opentelemetry-operator-system/opentelemetry-operator-serving-cert
controller-gen.kubebuilder.io/version: v0.16.5
controller-gen.kubebuilder.io/version: v0.17.0
creationTimestamp: null
labels:
app.kubernetes.io/name: opentelemetry-operator
Expand Down
65 changes: 55 additions & 10 deletions cmd/operator-opamp-bridge/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package agent
import (
"bytes"
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -95,10 +96,18 @@ func (agent *Agent) getHealth() *protobufs.ComponentHealth {
LastError: err.Error(),
}
}
statusTime, err := agent.getCurrentTimeUnixNano()
if err != nil {
return &protobufs.ComponentHealth{
Healthy: false,
StartTimeUnixNano: agent.startTime,
LastError: err.Error(),
}
}
return &protobufs.ComponentHealth{
Healthy: true,
StartTimeUnixNano: agent.startTime,
StatusTimeUnixNano: uint64(agent.clock.Now().UnixNano()),
StatusTimeUnixNano: statusTime,
LastError: "",
ComponentHealthMap: healthMap,
}
Expand All @@ -124,9 +133,17 @@ func (agent *Agent) generateCollectorPoolHealth() (map[string]*protobufs.Compone
for _, pod := range podMap {
isPoolHealthy = isPoolHealthy && pod.Healthy
}
podStartTime, err := timeToUnixNanoUnsigned(col.ObjectMeta.GetCreationTimestamp().Time)
if err != nil {
return nil, err
}
statusTime, err := agent.getCurrentTimeUnixNano()
if err != nil {
return nil, err
}
healthMap[key.String()] = &protobufs.ComponentHealth{
StartTimeUnixNano: uint64(col.ObjectMeta.GetCreationTimestamp().UnixNano()),
StatusTimeUnixNano: uint64(agent.clock.Now().UnixNano()),
StartTimeUnixNano: podStartTime,
StatusTimeUnixNano: statusTime,
Status: col.Status.Scale.StatusReplicas,
ComponentHealthMap: podMap,
Healthy: isPoolHealthy,
Expand Down Expand Up @@ -158,6 +175,10 @@ func (agent *Agent) getCollectorSelector(col v1beta1.OpenTelemetryCollector) map
}

func (agent *Agent) generateCollectorHealth(selectorLabels map[string]string, namespace string) (map[string]*protobufs.ComponentHealth, error) {
statusTime, err := agent.getCurrentTimeUnixNano()
if err != nil {
return nil, err
}
pods, err := agent.applier.GetCollectorPods(selectorLabels, namespace)
if err != nil {
return nil, err
Expand All @@ -169,15 +190,18 @@ func (agent *Agent) generateCollectorHealth(selectorLabels map[string]string, na
if item.Status.Phase != "Running" {
healthy = false
}
var startTime int64
var startTime uint64
if item.Status.StartTime != nil {
startTime = item.Status.StartTime.UnixNano()
startTime, err = timeToUnixNanoUnsigned(item.Status.StartTime.Time)
if err != nil {
return nil, err
}
} else {
healthy = false
}
healthMap[key.String()] = &protobufs.ComponentHealth{
StartTimeUnixNano: uint64(startTime),
StatusTimeUnixNano: uint64(agent.clock.Now().UnixNano()),
StartTimeUnixNano: startTime,
StatusTimeUnixNano: statusTime,
Status: string(item.Status.Phase),
Healthy: healthy,
}
Expand All @@ -197,7 +221,7 @@ func (agent *Agent) onConnectFailed(ctx context.Context, err error) {

// onError is called when an agent receives an error response from the server.
func (agent *Agent) onError(ctx context.Context, err *protobufs.ServerErrorResponse) {
agent.logger.Error(fmt.Errorf(err.GetErrorMessage()), "server returned an error response")
agent.logger.Error(errors.New(err.GetErrorMessage()), "server returned an error response")
}

// saveRemoteConfigStatus receives a status from the server when the server sets a remote configuration.
Expand All @@ -207,7 +231,11 @@ func (agent *Agent) saveRemoteConfigStatus(_ context.Context, status *protobufs.

// Start sets up the callbacks for the OpAMP client and begins the client's connection to the server.
func (agent *Agent) Start() error {
agent.startTime = uint64(agent.clock.Now().UnixNano())
startTime, err := agent.getCurrentTimeUnixNano()
if err != nil {
return err
}
agent.startTime = startTime
settings := types.StartSettings{
OpAMPServerURL: agent.config.Endpoint,
Header: agent.config.Headers.ToHTTPHeader(),
Expand All @@ -224,7 +252,7 @@ func (agent *Agent) Start() error {
PackagesStateProvider: nil,
Capabilities: agent.config.GetCapabilities(),
}
err := agent.opampClient.SetAgentDescription(agent.agentDescription)
err = agent.opampClient.SetAgentDescription(agent.agentDescription)
if err != nil {
return err
}
Expand Down Expand Up @@ -429,3 +457,20 @@ func (agent *Agent) onMessage(ctx context.Context, msg *types.MessageData) {
agent.initMeter(msg.OwnMetricsConnSettings)
}
}

// getCurrentTimeUnixNano returns the current time as a uint64, which the protocol expects.
func (agent *Agent) getCurrentTimeUnixNano() (uint64, error) {
// technically this could be negative if the system time is set to before 1970-01-1
// the proto demands this to be a nonnegative number, so in that case, just return 0
return timeToUnixNanoUnsigned(agent.clock.Now())
}

// timeToUnixNanoUnsigned returns the number of nanoseconds elapsed from 1970-01-01 to the given time, but returns an
// error if the value is negative. OpAMP expects these values to be non-negative.
func timeToUnixNanoUnsigned(t time.Time) (uint64, error) {
signedUnixNano := t.UnixNano()
if signedUnixNano < 0 {
return 0, fmt.Errorf("invalid system time, must be after 01-01-1970 due to OpAMP requirements: %v", t)
}
return uint64(signedUnixNano), nil
}
Loading

0 comments on commit 9ce60cd

Please sign in to comment.