Skip to content

Commit

Permalink
chore(operator): bump OTel dependencies to the latest version (#1419)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored May 17, 2023
1 parent e40292c commit a7475c2
Show file tree
Hide file tree
Showing 23 changed files with 466 additions and 1,097 deletions.
19 changes: 9 additions & 10 deletions operator/apis/lifecycle/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"math/rand"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric"
)

const WorkloadAnnotation = "keptn.sh/workload"
Expand Down Expand Up @@ -132,14 +131,14 @@ const PreDeploymentEvaluationCheckType CheckType = "pre-eval"
const PostDeploymentEvaluationCheckType CheckType = "post-eval"

type KeptnMeters struct {
TaskCount syncint64.Counter
TaskDuration syncfloat64.Histogram
DeploymentCount syncint64.Counter
DeploymentDuration syncfloat64.Histogram
AppCount syncint64.Counter
AppDuration syncfloat64.Histogram
EvaluationCount syncint64.Counter
EvaluationDuration syncfloat64.Histogram
TaskCount metric.Int64Counter
TaskDuration metric.Float64Histogram
DeploymentCount metric.Int64Counter
DeploymentDuration metric.Float64Histogram
AppCount metric.Int64Counter
AppDuration metric.Float64Histogram
EvaluationCount metric.Int64Counter
EvaluationDuration metric.Float64Histogram
}

const (
Expand Down
19 changes: 9 additions & 10 deletions operator/apis/lifecycle/v1alpha2/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"math/rand"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric"
)

const WorkloadAnnotation = "keptn.sh/workload"
Expand Down Expand Up @@ -134,14 +133,14 @@ const PreDeploymentEvaluationCheckType CheckType = "pre-eval"
const PostDeploymentEvaluationCheckType CheckType = "post-eval"

type KeptnMeters struct {
TaskCount syncint64.Counter
TaskDuration syncfloat64.Histogram
DeploymentCount syncint64.Counter
DeploymentDuration syncfloat64.Histogram
AppCount syncint64.Counter
AppDuration syncfloat64.Histogram
EvaluationCount syncint64.Counter
EvaluationDuration syncfloat64.Histogram
TaskCount metric.Int64Counter
TaskDuration metric.Float64Histogram
DeploymentCount metric.Int64Counter
DeploymentDuration metric.Float64Histogram
AppCount metric.Int64Counter
AppDuration metric.Float64Histogram
EvaluationCount metric.Int64Counter
EvaluationDuration metric.Float64Histogram
}

const (
Expand Down
19 changes: 9 additions & 10 deletions operator/apis/lifecycle/v1alpha3/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"strconv"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
"go.opentelemetry.io/otel/metric"
)

const WorkloadAnnotation = "keptn.sh/workload"
Expand Down Expand Up @@ -148,14 +147,14 @@ const PreDeploymentEvaluationCheckType CheckType = "pre-eval"
const PostDeploymentEvaluationCheckType CheckType = "post-eval"

type KeptnMeters struct {
TaskCount syncint64.Counter
TaskDuration syncfloat64.Histogram
DeploymentCount syncint64.Counter
DeploymentDuration syncfloat64.Histogram
AppCount syncint64.Counter
AppDuration syncfloat64.Histogram
EvaluationCount syncint64.Counter
EvaluationDuration syncfloat64.Histogram
TaskCount metric.Int64Counter
TaskDuration metric.Float64Histogram
DeploymentCount metric.Int64Counter
DeploymentDuration metric.Float64Histogram
AppCount metric.Int64Counter
AppDuration metric.Float64Histogram
EvaluationCount metric.Int64Counter
EvaluationDuration metric.Float64Histogram
}

const (
Expand Down
15 changes: 7 additions & 8 deletions operator/controllers/common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (

controllererrors "github.com/keptn/lifecycle-toolkit/operator/controllers/errors"
"github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/interfaces"
"go.opentelemetry.io/otel/metric/instrument/asyncfloat64"
"go.opentelemetry.io/otel/metric/instrument/asyncint64"
"go.opentelemetry.io/otel/metric"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func ObserveDeploymentDuration(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge asyncfloat64.Gauge) error {
func ObserveDeploymentDuration(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge metric.Float64ObservableGauge, o metric.Observer) error {
err := client.List(ctx, reconcileObjectList)
if err != nil {
return fmt.Errorf(controllererrors.ErrCannotRetrieveInstancesMsg, err)
Expand All @@ -27,14 +26,14 @@ func ObserveDeploymentDuration(ctx context.Context, client client.Client, reconc
reconcileObject, _ := interfaces.NewMetricsObjectWrapperFromClientObject(ro)
if reconcileObject.IsEndTimeSet() {
duration := reconcileObject.GetEndTime().Sub(reconcileObject.GetStartTime())
gauge.Observe(ctx, duration.Seconds(), reconcileObject.GetDurationMetricsAttributes()...)
o.ObserveFloat64(gauge, duration.Seconds(), metric.WithAttributes(reconcileObject.GetDurationMetricsAttributes()...))
}
}

return nil
}

func ObserveDeploymentInterval(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge asyncfloat64.Gauge) error {
func ObserveDeploymentInterval(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge metric.Float64ObservableGauge, o metric.Observer) error {
err := client.List(ctx, reconcileObjectList)
if err != nil {
return fmt.Errorf(controllererrors.ErrCannotRetrieveInstancesMsg, err)
Expand All @@ -59,7 +58,7 @@ func ObserveDeploymentInterval(ctx context.Context, client client.Client, reconc
}

previousInterval := reconcileObject.GetEndTime().Sub(predecessor.GetEndTime())
gauge.Observe(ctx, previousInterval.Seconds(), reconcileObject.GetDurationMetricsAttributes()...)
o.ObserveFloat64(gauge, previousInterval.Seconds(), metric.WithAttributes(reconcileObject.GetDurationMetricsAttributes()...))
}
}

Expand All @@ -84,7 +83,7 @@ func getPredecessor(successor *interfaces.MetricsObjectWrapper, items []client.O
return predecessor
}

func ObserveActiveInstances(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge asyncint64.Gauge) error {
func ObserveActiveInstances(ctx context.Context, client client.Client, reconcileObjectList client.ObjectList, gauge metric.Int64ObservableGauge, o metric.Observer) error {
err := client.List(ctx, reconcileObjectList)
if err != nil {
return fmt.Errorf(controllererrors.ErrCannotRetrieveInstancesMsg, err)
Expand All @@ -102,7 +101,7 @@ func ObserveActiveInstances(ctx context.Context, client client.Client, reconcile
gaugeValue = int64(1)
}

gauge.Observe(ctx, gaugeValue, activeMetricsObject.GetActiveMetricsAttributes()...)
o.ObserveInt64(gauge, gaugeValue, metric.WithAttributes(activeMetricsObject.GetActiveMetricsAttributes()...))
}

return nil
Expand Down
21 changes: 9 additions & 12 deletions operator/controllers/common/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@ import (
controllererrors "github.com/keptn/lifecycle-toolkit/operator/controllers/errors"
"github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/interfaces"
"github.com/stretchr/testify/require"
noop "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument/asyncfloat64"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestMetrics_ObserveDeploymentDuration(t *testing.T) {

gauge, err := noop.NewNoopMeter().AsyncFloat64().Gauge("mine")
require.Nil(t, err)
gauge := noop.Float64ObservableGauge{}

tests := []struct {
name string
clientObjects client.ObjectList
list client.ObjectList
err error
gauge asyncfloat64.Gauge
gauge metric.Float64ObservableGauge
}{
{
name: "failed to create wrapper",
Expand Down Expand Up @@ -79,7 +77,7 @@ func TestMetrics_ObserveDeploymentDuration(t *testing.T) {
err := lifecyclev1alpha3.AddToScheme(scheme.Scheme)
require.Nil(t, err)
client := fake.NewClientBuilder().WithLists(tt.clientObjects).Build()
err = ObserveDeploymentDuration(context.TODO(), client, tt.list, gauge)
err = ObserveDeploymentDuration(context.TODO(), client, tt.list, gauge, noop.Observer{})
require.ErrorIs(t, err, tt.err)
})

Expand Down Expand Up @@ -153,9 +151,9 @@ func TestMetrics_ObserveActiveInstances(t *testing.T) {
err := lifecyclev1alpha3.AddToScheme(scheme.Scheme)
require.Nil(t, err)
client := fake.NewClientBuilder().WithLists(tt.clientObjects).Build()
gauge, err := noop.NewNoopMeter().AsyncInt64().Gauge("mine")
gauge := noop.Int64ObservableGauge{}
require.Nil(t, err)
err = ObserveActiveInstances(context.TODO(), client, tt.list, gauge)
err = ObserveActiveInstances(context.TODO(), client, tt.list, gauge, noop.Observer{})
require.ErrorIs(t, err, tt.err)

})
Expand Down Expand Up @@ -365,15 +363,14 @@ func TestMetrics_ObserveDeploymentInterval(t *testing.T) {
},
}

gauge, err := noop.NewNoopMeter().AsyncFloat64().Gauge("mine")
require.Nil(t, err)
gauge := noop.Float64ObservableGauge{}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := lifecyclev1alpha3.AddToScheme(scheme.Scheme)
require.Nil(t, err)
fakeClient := fake.NewClientBuilder().WithLists(tt.clientObjects).Build()
err = ObserveDeploymentInterval(context.TODO(), fakeClient, tt.list, gauge)
err = ObserveDeploymentInterval(context.TODO(), fakeClient, tt.list, gauge, noop.Observer{})
require.ErrorIs(t, err, tt.err)
})

Expand Down
Loading

0 comments on commit a7475c2

Please sign in to comment.