Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Oct 6, 2022
1 parent 2709c0e commit 9f5f602
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
11 changes: 11 additions & 0 deletions operator/api/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"fmt"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument/syncint64"
)
Expand Down Expand Up @@ -57,3 +58,13 @@ type KeptnMeters struct {
DeploymentDuration syncfloat64.Histogram
DeploymentActive syncint64.UpDownCounter
}

const (
ApplicationName attribute.Key = attribute.Key("keptn.app_name")
Workload attribute.Key = attribute.Key("keptn.workload")
Version attribute.Key = attribute.Key("keptn.version")
Namespace attribute.Key = attribute.Key("keptn.namespace")
Status attribute.Key = attribute.Key("keptn.status")
Task attribute.Key = attribute.Key("keptn.task")
TaskType attribute.Key = attribute.Key("keptn.task_type")
)
22 changes: 11 additions & 11 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ func (i *KeptnTask) IsEndTimeSet() bool {

func (i KeptnTask) GetActiveMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.Key("KeptnApp").String(i.Spec.AppName),
attribute.Key("KeptnWorkload").String(i.Spec.Workload),
attribute.Key("KeptnVersion").String(i.Spec.WorkloadVersion),
attribute.Key("TaskName").String(i.Name),
attribute.Key("Type").String(string(i.Spec.Type)),
common.ApplicationName.String(i.Spec.AppName),
common.Workload.String(i.Spec.Workload),
common.Version.String(i.Spec.WorkloadVersion),
common.Task.String(i.Name),
common.TaskType.String(string(i.Spec.Type)),
}
}

func (i KeptnTask) GetMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.Key("KeptnApp").String(i.Spec.AppName),
attribute.Key("KeptnWorkload").String(i.Spec.Workload),
attribute.Key("KeptnVersion").String(i.Spec.WorkloadVersion),
attribute.Key("TaskName").String(i.Name),
attribute.Key("Type").String(string(i.Spec.Type)),
attribute.Key("Status").String(string(i.Status.Status)),
common.ApplicationName.String(i.Spec.AppName),
common.Workload.String(i.Spec.Workload),
common.Version.String(i.Spec.WorkloadVersion),
common.Task.String(i.Name),
common.TaskType.String(string(i.Spec.Type)),
common.Status.String(string(i.Status.Status)),
}
}
18 changes: 9 additions & 9 deletions operator/api/v1alpha1/keptnworkloadinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ func (i *WorkloadTaskStatus) SetEndTime() {

func (i KeptnWorkloadInstance) GetActiveMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.Key("KeptnApp").String(i.Spec.AppName),
attribute.Key("KeptnWorkload").String(i.Spec.WorkloadName),
attribute.Key("KeptnVersion").String(i.Spec.Version),
attribute.Key("Namespace").String(i.Namespace),
common.ApplicationName.String(i.Spec.AppName),
common.Workload.String(i.Spec.WorkloadName),
common.Version.String(i.Spec.Version),
common.Namespace.String(i.Namespace),
}
}

func (i KeptnWorkloadInstance) GetMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
attribute.Key("KeptnApp").String(i.Spec.AppName),
attribute.Key("KeptnWorkload").String(i.Spec.WorkloadName),
attribute.Key("KeptnVersion").String(i.Spec.Version),
attribute.Key("Namespace").String(i.Namespace),
attribute.Key("Status").String(string(i.Status.PostDeploymentStatus)),
common.ApplicationName.String(i.Spec.AppName),
common.Workload.String(i.Spec.WorkloadName),
common.Version.String(i.Spec.Version),
common.Namespace.String(i.Namespace),
common.Status.String(string(i.Status.PostDeploymentStatus)),
}
}
2 changes: 0 additions & 2 deletions operator/controllers/keptntask/job_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (

"github.com/imdario/mergo"
klcv1alpha1 "github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1"
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down
23 changes: 8 additions & 15 deletions operator/controllers/semconv/keptn.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package semconv

import (
klcv1alpha1 "github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1"
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1"
"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

const (
ApplicationName attribute.Key = attribute.Key("keptn.deployment.app_name")
Workload attribute.Key = attribute.Key("keptn.deployment.workload")
Version attribute.Key = attribute.Key("keptn.deployment.version")
)

func AddAttributeFromWorkload(s trace.Span, w klcv1alpha1.KeptnWorkload) {
s.SetAttributes(ApplicationName.String(w.Spec.AppName))
s.SetAttributes(Workload.String(w.Name))
s.SetAttributes(Version.String(w.Spec.Version))
func AddAttributeFromWorkload(s trace.Span, w v1alpha1.KeptnWorkload) {
s.SetAttributes(common.ApplicationName.String(w.Spec.AppName))
s.SetAttributes(common.Workload.String(w.Name))
s.SetAttributes(common.Version.String(w.Spec.Version))
}

func AddAttributeFromAnnotations(s trace.Span, annotations map[string]string) {
s.SetAttributes(ApplicationName.String(annotations[common.AppAnnotation]))
s.SetAttributes(Workload.String(annotations[common.WorkloadAnnotation]))
s.SetAttributes(Version.String(annotations[common.VersionAnnotation]))
s.SetAttributes(common.ApplicationName.String(annotations[common.AppAnnotation]))
s.SetAttributes(common.Workload.String(annotations[common.WorkloadAnnotation]))
s.SetAttributes(common.Version.String(annotations[common.VersionAnnotation]))
}
2 changes: 2 additions & 0 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ func newResource() *resource.Resource {
),
)
return r
}

func serveMetrics(collector prometheus.Collector) {
registry := prometheus.NewRegistry()
err := registry.Register(collector)
Expand Down

0 comments on commit 9f5f602

Please sign in to comment.