Skip to content

Commit 8d2fff3

Browse files
NC_Danil NC_BasinNC_Danil NC_Basin
authored andcommitted
Add metrics usage example in ReadMe
1 parent 89af97f commit 8d2fff3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ for [segmentio/kafka-go](github.com/segmentio/kafka-go) native go client.
1313
* [Blue-Green for segmentio Kafka client](#blue-green-for-segmentio-kafka-client-)
1414
* [Usage examples](#usage-examples)
1515
* [Simple consumer creation and polling](#simple-consumer-creation-and-polling)
16+
* [Metrics](#metrics)
1617
* [Migration to Blue Green 2](#migration-to-blue-green-2)
1718
<!-- TOC -->
1819

@@ -96,5 +97,35 @@ func processMsg(ctx context.Context, consumer *bgKafka.BgConsumer, message bgKaf
9697
}
9798
~~~
9899

100+
### Metrics
101+
102+
Blue-green kafka consumer collects own metrics set.
103+
Metrics are updating on messages poll and offset commit (interaction with message broker).
104+
105+
Values of each metric are split by partitions and contains data only from partitions assigned to this consumer.
106+
107+
Metrics usage example:
108+
109+
```go
110+
// Use Stats() method to receive metrics snapshot.
111+
metrics := consumer.Stats()
112+
113+
// Call GetByPartitions() method for required metric to get map[int]in64, where key is a partition number
114+
lags := metrics.Lag.GetByPartitions()
115+
for partition, lag := range lags {
116+
logger.Info("Lag on partition %d: %d", partition, lag)
117+
}
118+
119+
// Be aware that metric for each partition is updating on poll or commit.
120+
// It means that before that after consumer init metrics may be empty
121+
_, commitOffsetExists := metrics.CommitOffset.GetByPartitions()[0]
122+
if !commitOffsetExists {
123+
logger.Info("No offest has been commited for partition 0 yet")
124+
}
125+
```
126+
127+
You can find full list of supported metrics and its description
128+
in [metrics.go](https://github.com/Netcracker/qubership-core-lib-go-bg-kafka/blob/main/metrics.go#L43)
129+
99130
## Migration to Blue Green 2
100131
See details [here](docs/migration.md)

0 commit comments

Comments
 (0)