github.com/kubevela/workflow@v0.6.0/pkg/monitor/metrics/workflow.go (about)

     1  /*
     2  Copyright 2022 The KubeVela Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package metrics
    18  
    19  import (
    20  	"github.com/prometheus/client_golang/prometheus"
    21  	"k8s.io/klog/v2"
    22  	"sigs.k8s.io/controller-runtime/pkg/metrics"
    23  
    24  	velametrics "github.com/kubevela/pkg/monitor/metrics"
    25  )
    26  
    27  var (
    28  	// WorkflowRunReconcileTimeHistogram report the reconciling time cost of workflow run controller with state transition recorded
    29  	WorkflowRunReconcileTimeHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    30  		Name:        "workflowrun_reconcile_time_seconds",
    31  		Help:        "workflow run reconcile duration distributions.",
    32  		Buckets:     velametrics.FineGrainedBuckets,
    33  		ConstLabels: prometheus.Labels{},
    34  	}, []string{"begin_phase", "end_phase"})
    35  
    36  	// GenerateTaskRunnersDurationHistogram report the generate task runners execution duration.
    37  	GenerateTaskRunnersDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    38  		Name:        "generate_task_runners_time_seconds",
    39  		Help:        "generate task runners duration distributions.",
    40  		Buckets:     velametrics.FineGrainedBuckets,
    41  		ConstLabels: prometheus.Labels{},
    42  	}, []string{"controller"})
    43  
    44  	// WorkflowRunPhaseCounter report the number of workflow run phase
    45  	WorkflowRunPhaseCounter = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    46  		Name: "workflowrun_phase_number",
    47  		Help: "workflow run phase number",
    48  	}, []string{"phase"})
    49  
    50  	// WorkflowRunFinishedTimeHistogram report the time for finished workflow run
    51  	WorkflowRunFinishedTimeHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    52  		Name:        "workflowrun_finished_time_seconds",
    53  		Help:        "workflow run finished time distributions.",
    54  		Buckets:     velametrics.FineGrainedBuckets,
    55  		ConstLabels: prometheus.Labels{},
    56  	}, []string{"phase"})
    57  
    58  	// WorkflowRunInitializedCounter report the workflow run initialize execute number.
    59  	WorkflowRunInitializedCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    60  		Name: "workflowrun_initialized_num",
    61  		Help: "workflow run initialize times",
    62  	}, []string{})
    63  
    64  	// WorkflowRunStepPhaseGauge report the number of workflow run step state
    65  	WorkflowRunStepPhaseGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
    66  		Name: "workflowrun_step_phase_number",
    67  		Help: "workflow step phase number",
    68  	}, []string{"step_type", "phase"})
    69  
    70  	// WorkflowRunStepDurationHistogram report the step execution duration.
    71  	WorkflowRunStepDurationHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
    72  		Name:        "workflowrun_step_duration_ms",
    73  		Help:        "workflow run step latency distributions.",
    74  		Buckets:     velametrics.FineGrainedBuckets,
    75  		ConstLabels: prometheus.Labels{},
    76  	}, []string{"controller", "step_type"})
    77  )
    78  
    79  var collectorGroup = []prometheus.Collector{
    80  	GenerateTaskRunnersDurationHistogram,
    81  	WorkflowRunStepDurationHistogram,
    82  	WorkflowRunReconcileTimeHistogram,
    83  	WorkflowRunFinishedTimeHistogram,
    84  	WorkflowRunInitializedCounter,
    85  	WorkflowRunPhaseCounter,
    86  	WorkflowRunStepPhaseGauge,
    87  }
    88  
    89  func init() {
    90  	for _, collector := range collectorGroup {
    91  		if err := metrics.Registry.Register(collector); err != nil {
    92  			klog.Error(err)
    93  		}
    94  	}
    95  }