github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/pkg/promutil/util_inner.go (about) 1 // Copyright 2022 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package promutil 15 16 import ( 17 "net/http" 18 19 frameModel "github.com/pingcap/tiflow/engine/framework/model" 20 engineModel "github.com/pingcap/tiflow/engine/model" 21 "github.com/pingcap/tiflow/engine/pkg/tenant" 22 "github.com/prometheus/client_golang/prometheus" 23 "github.com/prometheus/client_golang/prometheus/promhttp" 24 ) 25 26 // [NOTICE]: SHOULD NOT use following functions. USE functions in 'util.go' INSTEAD. 27 // They are just for easy scenarios testing. 28 29 // HTTPHandlerForMetricImpl return http.Handler for prometheus metric 30 func HTTPHandlerForMetricImpl(gather prometheus.Gatherer) http.Handler { 31 return promhttp.HandlerFor( 32 gather, 33 promhttp.HandlerOpts{}, 34 ) 35 } 36 37 // NewFactory4MasterImpl return a Factory for jobmaster 38 func NewFactory4MasterImpl(reg *Registry, info tenant.ProjectInfo, prefix string, jobID engineModel.JobID) Factory { 39 return NewAutoRegisterFactory( 40 NewWrappingFactory( 41 NewPromFactory(), 42 prefix, 43 prometheus.Labels{ 44 constLabelTenantKey: info.TenantID(), 45 constLabelProjectKey: info.ProjectID(), 46 constLabelJobKey: jobID, 47 }, 48 ), 49 reg, 50 jobID, 51 ) 52 } 53 54 // NewFactory4WorkerImpl return a Factory for worker 55 func NewFactory4WorkerImpl(reg *Registry, info tenant.ProjectInfo, prefix string, jobID engineModel.JobID, 56 workerID frameModel.WorkerID, 57 ) Factory { 58 return NewAutoRegisterFactory( 59 NewWrappingFactory( 60 NewPromFactory(), 61 prefix, 62 prometheus.Labels{ 63 constLabelTenantKey: info.TenantID(), 64 constLabelProjectKey: info.ProjectID(), 65 constLabelJobKey: jobID, 66 constLabelWorkerKey: workerID, 67 }, 68 ), 69 reg, 70 workerID, 71 ) 72 } 73 74 // NewFactory4FrameworkImpl return a Factory for dataflow framework 75 func NewFactory4FrameworkImpl(reg *Registry) Factory { 76 return NewAutoRegisterFactory( 77 NewWrappingFactory( 78 NewPromFactory(), 79 frameworkMetricPrefix, 80 prometheus.Labels{ 81 constLabelFrameworkKey: "true", 82 }, 83 ), 84 reg, 85 frameworkID, 86 ) 87 } 88 89 // NewFactory4TestImpl return a Factory for test 90 func NewFactory4TestImpl(reg *Registry, testID string) Factory { 91 return NewAutoRegisterFactory( 92 NewWrappingFactory( 93 NewPromFactory(), 94 frameworkMetricPrefix, 95 prometheus.Labels{ 96 constLableTestKey: testID, 97 }, 98 ), 99 reg, 100 testID, 101 ) 102 }