github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/metrics/mq/pulsar.go (about)

     1  // Copyright 2023 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 mq
    15  
    16  import (
    17  	"github.com/pingcap/tiflow/cdc/model"
    18  	"github.com/pingcap/tiflow/pkg/sink/codec/common"
    19  	"github.com/prometheus/client_golang/prometheus"
    20  )
    21  
    22  const (
    23  	pulsarPublishedDDLSchemaTableCount      = "published_DDL_schema_table_count"
    24  	pulsarPublishedDMLSchemaTableCount      = "published_DML_schema_table_count"
    25  	pulsarPublishedMessageTypeResolvedCount = "published_message_type_resolved_count"
    26  )
    27  
    28  var (
    29  	// pulsar producer DDL scheme, type: count/success/fail, May there are too many tables
    30  	publishedDDLSchemaTableCountMetric = prometheus.NewCounterVec(
    31  		prometheus.CounterOpts{
    32  			Namespace: "ticdc",
    33  			Subsystem: "pulsar",
    34  			Name:      pulsarPublishedDDLSchemaTableCount,
    35  			Help:      "pulsar published schema count",
    36  		}, []string{"topic", "changefeed", "schema", "type"})
    37  
    38  	// pulsar producer DML scheme, type:count/success/fail , May there are too many tables
    39  	publishedDMLSchemaTableCountMetric = prometheus.NewCounterVec(
    40  		prometheus.CounterOpts{
    41  			Namespace: "ticdc",
    42  			Subsystem: "pulsar",
    43  			Name:      pulsarPublishedDMLSchemaTableCount,
    44  			Help:      "pulsar published schema count ",
    45  		}, []string{"topic", "changefeed", "schema", "type"})
    46  
    47  	// pulsar producer WATER count, type:count/success/fail , May there are too many tables
    48  	pulsarPublishedMessageTypeResolvedCountMetric = prometheus.NewCounterVec(
    49  		prometheus.CounterOpts{
    50  			Namespace: "ticdc",
    51  			Subsystem: "pulsar",
    52  			Name:      pulsarPublishedMessageTypeResolvedCount,
    53  			Help:      "pulsar published message type resolved count ",
    54  		}, []string{"topic", "changefeed", "schema", "type"})
    55  )
    56  
    57  // IncPublishedDDLCount DDL
    58  func IncPublishedDDLCount(topic, changefeed string, message *common.Message) {
    59  	if message.Type == model.MessageTypeDDL {
    60  		publishedDDLSchemaTableCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "count").Inc()
    61  	}
    62  	if message.Type == model.MessageTypeResolved {
    63  		pulsarPublishedMessageTypeResolvedCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "count").Inc()
    64  	}
    65  }
    66  
    67  // IncPublishedDDLSuccess success
    68  func IncPublishedDDLSuccess(topic, changefeed string, message *common.Message) {
    69  	if message.Type == model.MessageTypeDDL {
    70  		publishedDDLSchemaTableCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "success").Inc()
    71  	}
    72  	if message.Type == model.MessageTypeResolved {
    73  		pulsarPublishedMessageTypeResolvedCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "success").Inc()
    74  	}
    75  }
    76  
    77  // IncPublishedDDLFail fail
    78  func IncPublishedDDLFail(topic, changefeed string, message *common.Message) {
    79  	if message.Type == model.MessageTypeDDL {
    80  		publishedDDLSchemaTableCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "fail").Inc()
    81  	}
    82  	if message.Type == model.MessageTypeResolved {
    83  		pulsarPublishedMessageTypeResolvedCountMetric.WithLabelValues(topic, changefeed, message.GetSchema(), "fail").Inc()
    84  	}
    85  }
    86  
    87  // IncPublishedDMLCount count
    88  func IncPublishedDMLCount(topic, changefeed, schema string) {
    89  	publishedDMLSchemaTableCountMetric.WithLabelValues(topic, changefeed, schema, "count").Inc()
    90  }
    91  
    92  // IncPublishedDMLSuccess success
    93  func IncPublishedDMLSuccess(topic, changefeed, schema string) {
    94  	publishedDMLSchemaTableCountMetric.WithLabelValues(topic, changefeed, schema, "success").Inc()
    95  }
    96  
    97  // IncPublishedDMLFail fail
    98  func IncPublishedDMLFail(topic, changefeed, schema string) {
    99  	publishedDMLSchemaTableCountMetric.WithLabelValues(topic, changefeed, schema, "fail").Inc()
   100  }