mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-04 09:52:30 +08:00
Related to #39095 https://go.dev/doc/modules/version-numbers Update pkg version according to golang dep version convention --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package metricsutil
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/milvus-io/milvus/pkg/v2/metrics"
|
|
"github.com/milvus-io/milvus/pkg/v2/streaming/util/message"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/syncutil"
|
|
)
|
|
|
|
func NewTxnMetrics(pchannel string) *TxnMetrics {
|
|
constLabel := prometheus.Labels{
|
|
metrics.NodeIDLabelName: paramtable.GetStringNodeID(),
|
|
metrics.WALChannelLabelName: pchannel,
|
|
}
|
|
return &TxnMetrics{
|
|
mu: syncutil.ClosableLock{},
|
|
constLabel: constLabel,
|
|
inflightTxnGauge: metrics.WALInflightTxn.With(constLabel),
|
|
txnCounter: metrics.WALFinishTxn.MustCurryWith(constLabel),
|
|
}
|
|
}
|
|
|
|
type TxnMetrics struct {
|
|
mu syncutil.ClosableLock
|
|
constLabel prometheus.Labels
|
|
inflightTxnGauge prometheus.Gauge
|
|
txnCounter *prometheus.CounterVec
|
|
}
|
|
|
|
func (m *TxnMetrics) BeginTxn() {
|
|
if !m.mu.LockIfNotClosed() {
|
|
return
|
|
}
|
|
m.inflightTxnGauge.Inc()
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
func (m *TxnMetrics) Finish(state message.TxnState) {
|
|
if !m.mu.LockIfNotClosed() {
|
|
return
|
|
}
|
|
m.inflightTxnGauge.Dec()
|
|
m.txnCounter.WithLabelValues(state.String()).Inc()
|
|
m.mu.Unlock()
|
|
}
|
|
|
|
func (m *TxnMetrics) Close() {
|
|
m.mu.Close()
|
|
metrics.WALInflightTxn.Delete(m.constLabel)
|
|
metrics.WALFinishTxn.DeletePartialMatch(m.constLabel)
|
|
}
|