Skip to content

Commit 401c642

Browse files
committed
[scraper/zookeeper] fix float parsing for zk_avg_latency on ZK 3.7+
1 parent 048e4ea commit 401c642

5 files changed

Lines changed: 200 additions & 6 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
change_type: bug_fix
2+
component: scraper/zookeeper
3+
note: Fix zk_avg_latency metric being silently dropped on Zookeeper 3.7+ where the value is reported as a float.
4+
issues: [47320]
5+
subtext: ""
6+
change_logs: [user]

scraper/zookeeperscraper/scraper.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,16 @@ func (z *zookeeperMetricsScraper) processMntr(response []string) {
148148
}
149149
int64Val, err := strconv.ParseInt(metricValue, 10, 64)
150150
if err != nil {
151-
z.logger.Debug(
152-
"non-integer value from "+mntrCommand,
153-
zap.String("value", metricValue),
154-
)
155-
continue
151+
// zk_avg_latency changed to float in ZK 3.7+; truncate to int64.
152+
floatVal, floatErr := strconv.ParseFloat(metricValue, 64)
153+
if floatErr != nil {
154+
z.logger.Debug(
155+
"non-parseable value from "+mntrCommand,
156+
zap.String("value", metricValue),
157+
)
158+
continue
159+
}
160+
int64Val = int64(floatVal)
156161
}
157162
recordDataPoints(now, int64Val)
158163
}

scraper/zookeeperscraper/scraper_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) {
8585
},
8686
expectedNumResourceMetrics: 1,
8787
},
88+
{
89+
name: "Test correctness with v3.7.2",
90+
mockedZKCmdToOutputFilename: map[string]string{
91+
"mntr": "mntr-3.7.2",
92+
"ruok": "ruok-valid",
93+
},
94+
expectedMetricsFilename: "correctness-v3.7.2",
95+
expectedResourceAttributes: map[string]string{
96+
"server.state": "standalone",
97+
"zk.version": "3.7.2-a055d78707164783287056086786315873919992",
98+
},
99+
expectedLogs: []logMsg{
100+
{
101+
msg: "metric computation failed",
102+
level: zapcore.DebugLevel,
103+
},
104+
},
105+
expectedNumResourceMetrics: 1,
106+
},
88107
{
89108
name: "Arbitrary connection error",
90109
mockZKConnectionErr: true,
@@ -122,7 +141,7 @@ func TestZookeeperMetricsScraperScrape(t *testing.T) {
122141
},
123142
expectedLogs: []logMsg{
124143
{
125-
msg: "non-integer value from mntr",
144+
msg: "non-parseable value from mntr",
126145
level: zapcore.DebugLevel,
127146
},
128147
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
zk_version 3.7.2-a055d78707164783287056086786315873919992, built on 09/08/2023 09:00 GMT
2+
zk_avg_latency 0.0989
3+
zk_max_latency 47
4+
zk_min_latency 0
5+
zk_packets_received 156
6+
zk_packets_sent 155
7+
zk_num_alive_connections 3
8+
zk_outstanding_requests 0
9+
zk_server_state standalone
10+
zk_znode_count 5
11+
zk_watch_count 1
12+
zk_ephemerals_count 0
13+
zk_approximate_data_size 44
14+
zk_open_file_descriptor_count 68
15+
zk_max_file_descriptor_count 1048576
16+
zk_fsync_threshold_exceed_count 0
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
resourceMetrics:
2+
- resource:
3+
attributes:
4+
- key: server.state
5+
value:
6+
stringValue: standalone
7+
- key: zk.version
8+
value:
9+
stringValue: 3.7.2-a055d78707164783287056086786315873919992
10+
scopeMetrics:
11+
- metrics:
12+
- description: Number of active clients connected to a ZooKeeper server.
13+
name: zookeeper.connection.active
14+
sum:
15+
aggregationTemporality: 2
16+
dataPoints:
17+
- asInt: "3"
18+
startTimeUnixNano: "1000000"
19+
timeUnixNano: "2000000"
20+
unit: '{connections}'
21+
- description: Number of ephemeral nodes that a ZooKeeper server has in its data tree.
22+
name: zookeeper.data_tree.ephemeral_node.count
23+
sum:
24+
aggregationTemporality: 2
25+
dataPoints:
26+
- asInt: "0"
27+
startTimeUnixNano: "1000000"
28+
timeUnixNano: "2000000"
29+
unit: '{nodes}'
30+
- description: Size of data in bytes that a ZooKeeper server has in its data tree.
31+
name: zookeeper.data_tree.size
32+
sum:
33+
aggregationTemporality: 2
34+
dataPoints:
35+
- asInt: "44"
36+
startTimeUnixNano: "1000000"
37+
timeUnixNano: "2000000"
38+
unit: By
39+
- description: Maximum number of file descriptors that a ZooKeeper server can open.
40+
gauge:
41+
dataPoints:
42+
- asInt: "1048576"
43+
startTimeUnixNano: "1000000"
44+
timeUnixNano: "2000000"
45+
name: zookeeper.file_descriptor.limit
46+
unit: '{file_descriptors}'
47+
- description: Number of file descriptors that a ZooKeeper server has open.
48+
name: zookeeper.file_descriptor.open
49+
sum:
50+
aggregationTemporality: 2
51+
dataPoints:
52+
- asInt: "68"
53+
startTimeUnixNano: "1000000"
54+
timeUnixNano: "2000000"
55+
unit: '{file_descriptors}'
56+
- description: Number of times fsync duration has exceeded warning threshold.
57+
name: zookeeper.fsync.exceeded_threshold.count
58+
sum:
59+
aggregationTemporality: 2
60+
dataPoints:
61+
- asInt: "0"
62+
startTimeUnixNano: "1000000"
63+
timeUnixNano: "2000000"
64+
isMonotonic: true
65+
unit: '{events}'
66+
- description: Average time in milliseconds for requests to be processed.
67+
gauge:
68+
dataPoints:
69+
- asInt: "0"
70+
startTimeUnixNano: "1000000"
71+
timeUnixNano: "2000000"
72+
name: zookeeper.latency.avg
73+
unit: ms
74+
- description: Maximum time in milliseconds for requests to be processed.
75+
gauge:
76+
dataPoints:
77+
- asInt: "47"
78+
startTimeUnixNano: "1000000"
79+
timeUnixNano: "2000000"
80+
name: zookeeper.latency.max
81+
unit: ms
82+
- description: Minimum time in milliseconds for requests to be processed.
83+
gauge:
84+
dataPoints:
85+
- asInt: "0"
86+
startTimeUnixNano: "1000000"
87+
timeUnixNano: "2000000"
88+
name: zookeeper.latency.min
89+
unit: ms
90+
- description: The number of ZooKeeper packets received or sent by a server.
91+
name: zookeeper.packet.count
92+
sum:
93+
aggregationTemporality: 2
94+
dataPoints:
95+
- asInt: "156"
96+
attributes:
97+
- key: direction
98+
value:
99+
stringValue: received
100+
startTimeUnixNano: "1000000"
101+
timeUnixNano: "2000000"
102+
- asInt: "155"
103+
attributes:
104+
- key: direction
105+
value:
106+
stringValue: sent
107+
startTimeUnixNano: "1000000"
108+
timeUnixNano: "2000000"
109+
isMonotonic: true
110+
unit: '{packets}'
111+
- description: Number of currently executing requests.
112+
name: zookeeper.request.active
113+
sum:
114+
aggregationTemporality: 2
115+
dataPoints:
116+
- asInt: "0"
117+
startTimeUnixNano: "1000000"
118+
timeUnixNano: "2000000"
119+
unit: '{requests}'
120+
- description: Response from zookeeper ruok command
121+
gauge:
122+
dataPoints:
123+
- asInt: "1"
124+
startTimeUnixNano: "1000000"
125+
timeUnixNano: "2000000"
126+
name: zookeeper.ruok
127+
unit: "1"
128+
- description: Number of watches placed on Z-Nodes on a ZooKeeper server.
129+
name: zookeeper.watch.count
130+
sum:
131+
aggregationTemporality: 2
132+
dataPoints:
133+
- asInt: "1"
134+
startTimeUnixNano: "1000000"
135+
timeUnixNano: "2000000"
136+
unit: '{watches}'
137+
- description: Number of z-nodes that a ZooKeeper server has in its data tree.
138+
name: zookeeper.znode.count
139+
sum:
140+
aggregationTemporality: 2
141+
dataPoints:
142+
- asInt: "5"
143+
startTimeUnixNano: "1000000"
144+
timeUnixNano: "2000000"
145+
unit: '{znodes}'
146+
scope:
147+
name: github.com/open-telemetry/opentelemetry-collector-contrib/scraper/zookeeperscraper
148+
version: latest

0 commit comments

Comments
 (0)