Skip to content

Commit

Permalink
update metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren committed Sep 24, 2024
1 parent cb97e50 commit fce6513
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 205 deletions.
19 changes: 13 additions & 6 deletions api/v1alpha1/release_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/konflux-ci/operator-toolkit/conditions"

"github.com/konflux-ci/release-service/metadata"
"github.com/konflux-ci/release-service/metrics"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -249,11 +250,12 @@ func (r *Release) MarkManagedPipelineProcessed() {
r.Status.ManagedProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleaseManagedPipelineProcessing(
go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.ManagedProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

Expand All @@ -266,11 +268,12 @@ func (r *Release) MarkTenantPipelineProcessed() {
r.Status.TenantProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetCondition(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionTrue, SucceededReason)

go metrics.RegisterCompletedReleaseTenantPipelineProcessing(
go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.TenantProcessing.CompletionTime,
SucceededReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

Expand All @@ -286,11 +289,12 @@ func (r *Release) MarkManagedPipelineProcessing() {

conditions.SetCondition(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionFalse, ProgressingReason)

go metrics.RegisterNewReleaseManagedPipelineProcessing(
go metrics.RegisterNewReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

Expand All @@ -306,11 +310,12 @@ func (r *Release) MarkTenantPipelineProcessing() {

conditions.SetCondition(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionFalse, ProgressingReason)

go metrics.RegisterNewReleaseTenantPipelineProcessing(
go metrics.RegisterNewReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.StartTime,
ProgressingReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

Expand All @@ -323,11 +328,12 @@ func (r *Release) MarkManagedPipelineProcessingFailed(message string) {
r.Status.ManagedProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetConditionWithMessage(&r.Status.Conditions, managedProcessedConditionType, metav1.ConditionFalse, FailedReason, message)

go metrics.RegisterCompletedReleaseManagedPipelineProcessing(
go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.ManagedProcessing.StartTime,
r.Status.ManagedProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.ManagedPipelineType,
)
}

Expand All @@ -340,11 +346,12 @@ func (r *Release) MarkTenantPipelineProcessingFailed(message string) {
r.Status.TenantProcessing.CompletionTime = &metav1.Time{Time: time.Now()}
conditions.SetConditionWithMessage(&r.Status.Conditions, tenantProcessedConditionType, metav1.ConditionFalse, FailedReason, message)

go metrics.RegisterCompletedReleaseTenantPipelineProcessing(
go metrics.RegisterCompletedReleasePipelineProcessing(
r.Status.TenantProcessing.StartTime,
r.Status.TenantProcessing.CompletionTime,
FailedReason.String(),
r.Status.Target,
metadata.TenantPipelineType,
)
}

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 25 additions & 80 deletions metrics/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,10 @@ var (
[]string{},
)

ReleaseConcurrentManagedPipelineProcessingsTotal = prometheus.NewGaugeVec(
ReleaseConcurrentProcessingsTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "release_concurrent_managed_pipeline_processings_total",
Help: "Total number of concurrent release managed pipeline processing attempts",
},
[]string{},
)

ReleaseConcurrentTenantPipelineProcessingsTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "release_concurrent_tenant_pipeline_processings_total",
Help: "Total number of concurrent release tenant pipeline processing attempts",
Name: "release_concurrent_processings_total",
Help: "Total number of concurrent release processing attempts",
},
[]string{},
)
Expand All @@ -62,6 +54,7 @@ var (
releasePreProcessingDurationSecondsLabels = []string{
"reason",
"target",
"type",
}
releasePreProcessingDurationSecondsOpts = prometheus.HistogramOpts{
Name: "release_pre_processing_duration_seconds",
Expand Down Expand Up @@ -115,27 +108,18 @@ var (
Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600},
}

ReleaseManagedPipelineProcessingDurationSeconds = prometheus.NewHistogramVec(
releaseManagedPipelineProcessingDurationSecondsOpts,
ReleaseProcessingDurationSeconds = prometheus.NewHistogramVec(
releaseProcessingDurationSecondsOpts,
releaseProcessingDurationSecondsLabels,
)
releaseProcessingDurationSecondsLabels = []string{
"reason",
"target",
"type",
}
releaseManagedPipelineProcessingDurationSecondsOpts = prometheus.HistogramOpts{
Name: "release_managed_pipeline_processing_duration_seconds",
Help: "How long in seconds a Release Managed Pipeline processing takes to complete",
Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600},
}

ReleaseTenantPipelineProcessingDurationSeconds = prometheus.NewHistogramVec(
releaseTenantPipelineProcessingDurationSecondsOpts,
releaseProcessingDurationSecondsLabels,
)
releaseTenantPipelineProcessingDurationSecondsOpts = prometheus.HistogramOpts{
Name: "release_tenant_pipeline_processing_duration_seconds",
Help: "How long in seconds a Release Tenant Pipeline processing takes to complete",
releaseProcessingDurationSecondsOpts = prometheus.HistogramOpts{
Name: "release_processing_duration_seconds",
Help: "How long in seconds a Release processing takes to complete",
Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600},
}

Expand Down Expand Up @@ -199,40 +183,22 @@ func RegisterCompletedReleasePostActionsExecuted(startTime, completionTime *meta
ReleaseConcurrentPostActionsExecutionsTotal.WithLabelValues().Dec()
}

// RegisterCompletedReleaseManagedPipelineProcessing registers a Release processing as complete, adding a
// new observation for the Release Managed Pipeline processing duration and decreasing the number of
// concurrent processings. If either the startTime or the completionTime parameters are nil, no action
// will be taken.
func RegisterCompletedReleaseManagedPipelineProcessing(startTime, completionTime *metav1.Time, reason, target string) {
if startTime == nil || completionTime == nil {
return
}

ReleaseManagedPipelineProcessingDurationSeconds.
With(prometheus.Labels{
"reason": reason,
"target": target,
}).
Observe(completionTime.Sub(startTime.Time).Seconds())
ReleaseConcurrentManagedPipelineProcessingsTotal.WithLabelValues().Dec()
}

// RegisterCompletedReleaseTenantPipelineProcessing registers a Release processing as complete, adding a
// new observation for the Release Tenant Pipeline processing duration and decreasing the number of
// concurrent processings. If either the startTime or the completionTime parameters are nil, no action
// will be taken.
func RegisterCompletedReleaseTenantPipelineProcessing(startTime, completionTime *metav1.Time, reason, target string) {
// RegisterCompletedReleasePipelineProcessing registers a Release pipeline processing as complete, adding a
// new observation for the Release processing duration with the specific type and decreasing the number of
// concurent processings. If either the startTime or the completionTime parameters are nil, no action will be taken.
func RegisterCompletedReleasePipelineProcessing(startTime, completionTime *metav1.Time, reason, target, pipelineType string) {
if startTime == nil || completionTime == nil {
return
}

ReleaseTenantPipelineProcessingDurationSeconds.
ReleaseProcessingDurationSeconds.
With(prometheus.Labels{
"reason": reason,
"target": target,
"type": pipelineType,
}).
Observe(completionTime.Sub(startTime.Time).Seconds())
ReleaseConcurrentTenantPipelineProcessingsTotal.WithLabelValues().Dec()
ReleaseConcurrentProcessingsTotal.WithLabelValues().Dec()
}

// RegisterValidatedRelease registers a Release as validated, adding a new observation for the
Expand All @@ -256,30 +222,10 @@ func RegisterNewRelease() {
ReleaseConcurrentTotal.WithLabelValues().Inc()
}

// RegisterNewReleaseManagedPipelineProcessing registers a new Release Managed Pipeline processing,
// adding a new observation for the Release start managed pipeline processing duration and increasing
// the number of concurrent processings. If either the startTime or the processingStartTime are nil, no
// action will be taken.
func RegisterNewReleaseManagedPipelineProcessing(startTime, processingStartTime *metav1.Time, reason, target string) {
if startTime == nil || processingStartTime == nil {
return
}

ReleasePreProcessingDurationSeconds.
With(prometheus.Labels{
"reason": reason,
"target": target,
}).
Observe(processingStartTime.Sub(startTime.Time).Seconds())

ReleaseConcurrentManagedPipelineProcessingsTotal.WithLabelValues().Inc()
}

// RegisterNewReleaseTenantPipelineProcessing registers a new Release Tenant Pipeline processing,
// adding a new observation for the Release start tenant pipeline processing duration and increasing
// the number of concurrent processings. If either the startTime or the processingStartTime are nil, no
// action will be taken.
func RegisterNewReleaseTenantPipelineProcessing(startTime, processingStartTime *metav1.Time, reason, target string) {
// RegisterNewReleaseManagedPipelineProcessing registers a new Release Pipeline processing, adding a
// new observation for the Release start pipeline processing duration and increasing the number of
// concurrent processings. If either the startTime or the processingStartTime are nil, no action will be taken.
func RegisterNewReleasePipelineProcessing(startTime, processingStartTime *metav1.Time, reason, target, pipelineType string) {
if startTime == nil || processingStartTime == nil {
return
}
Expand All @@ -288,10 +234,11 @@ func RegisterNewReleaseTenantPipelineProcessing(startTime, processingStartTime *
With(prometheus.Labels{
"reason": reason,
"target": target,
"type": pipelineType,
}).
Observe(processingStartTime.Sub(startTime.Time).Seconds())

ReleaseConcurrentTenantPipelineProcessingsTotal.WithLabelValues().Inc()
ReleaseConcurrentProcessingsTotal.WithLabelValues().Inc()
}

// RegisterNewReleasePostActionsExecution register a new Release post-actions execution, increasing the number of
Expand All @@ -303,15 +250,13 @@ func RegisterNewReleasePostActionsExecution() {
func init() {
metrics.Registry.MustRegister(
ReleaseConcurrentTotal,
ReleaseConcurrentManagedPipelineProcessingsTotal,
ReleaseConcurrentTenantPipelineProcessingsTotal,
ReleaseConcurrentProcessingsTotal,
ReleaseConcurrentPostActionsExecutionsTotal,
ReleasePreProcessingDurationSeconds,
ReleaseValidationDurationSeconds,
ReleaseDurationSeconds,
ReleasePostActionsExecutionDurationSeconds,
ReleaseManagedPipelineProcessingDurationSeconds,
ReleaseTenantPipelineProcessingDurationSeconds,
ReleaseProcessingDurationSeconds,
ReleaseTotal,
)
}
Loading

0 comments on commit fce6513

Please sign in to comment.