suneet-s commented on code in PR #14443: URL: https://github.com/apache/druid/pull/14443#discussion_r1237840149
########## server/src/main/java/org/apache/druid/server/metrics/ServiceStatusMonitor.java: ########## @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.server.metrics; + +import com.google.common.base.Supplier; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; +import org.apache.druid.java.util.metrics.AbstractMonitor; + +import java.util.Map; + +/** + * Monitor service running status. + * For Overlord/Coordinator, the dimension reported is service leader count. + */ Review Comment: Stale javadoc. ########## docs/configuration/index.md: ########## @@ -399,6 +399,7 @@ Metric monitoring is an essential part of Druid operations. The following monit |`org.apache.druid.server.metrics.TaskCountStatsMonitor`|Reports how many ingestion tasks are currently running/pending/waiting and also the number of successful/failed tasks per emission period.| |`org.apache.druid.server.metrics.TaskSlotCountStatsMonitor`|Reports metrics about task slot usage per emission period.| |`org.apache.druid.server.metrics.WorkerTaskCountStatsMonitor`|Reports how many ingestion tasks are currently running/pending/waiting, the number of successful/failed tasks, and metrics about task slot usage for the reporting worker, per emission period. Only supported by middleManager node types.| +| `org.apache.druid.server.metrics.ServiceStatusMonitor`|Reports service heartbeat. For overlord/coordinator, the number is leader count. Only supported by overlord/coordinator node types.| Review Comment: Stale doc ```suggestion | `org.apache.druid.server.metrics.ServiceStatusMonitor`|Reports a heartbeat for the service. | ``` ########## server/src/test/java/org/apache/druid/server/metrics/ServiceStatusMonitorTest.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.server.metrics; + +import com.google.common.base.Supplier; +import org.apache.druid.java.util.metrics.StubServiceEmitter; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ServiceStatusMonitorTest +{ + + private ServiceStatusMonitor monitor; + private Map<String, Object> heartbeatTags = new HashMap<>(); + private Supplier<Map<String, Object>> heartbeatTagsSupplier = () -> heartbeatTags; + + @Before + public void setUp() throws Exception + { + monitor = new ServiceStatusMonitor(); + monitor.heartbeatTagsSupplier = heartbeatTagsSupplier; + } + + @Test + public void testLeaderCount() + { + heartbeatTags.put("leader", 0); + final StubServiceEmitter emitter = new StubServiceEmitter("service", "host"); + monitor.doMonitor(emitter); + + Assert.assertEquals(1, emitter.getEvents().size()); + Assert.assertEquals(0, emitter.getEvents().get(0).toMap().get("leader")); + Assert.assertEquals("druid/heartbeat", emitter.getEvents().get(0).toMap().get("metric")); + Assert.assertEquals(1, emitter.getEvents().get(0).toMap().get("value")); + + heartbeatTags.put("leader", 1); + emitter.flush(); + monitor.doMonitor(emitter); + Assert.assertEquals(1, emitter.getEvents().size()); + Assert.assertEquals(1, emitter.getEvents().get(0).toMap().get("leader")); + Assert.assertEquals("druid/heartbeat", emitter.getEvents().get(0).toMap().get("metric")); + Assert.assertEquals(1, emitter.getEvents().get(0).toMap().get("value")); Review Comment: I don't think this part of the test is needed. Instead, can you please add a test for adding more than 1 dimension to the metric. ```suggestion ``` And another test for no dimensions in the `heartbeatTagsSupplier` ########## server/src/test/java/org/apache/druid/server/metrics/ServiceStatusMonitorTest.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.server.metrics; + +import com.google.common.base.Supplier; +import org.apache.druid.java.util.metrics.StubServiceEmitter; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ServiceStatusMonitorTest +{ + + private ServiceStatusMonitor monitor; + private Map<String, Object> heartbeatTags = new HashMap<>(); + private Supplier<Map<String, Object>> heartbeatTagsSupplier = () -> heartbeatTags; + + @Before + public void setUp() throws Exception + { + monitor = new ServiceStatusMonitor(); Review Comment: You will likely want to initialize `heartbeatTags` in here so that each test in this class uses a clean map. ########## docs/operations/metrics.md: ########## @@ -326,6 +326,12 @@ If `emitBalancingStats` is set to `true` in the Coordinator [dynamic configurati ## General Health +### Service Health + +|Metric|Description|Dimensions|Normal Value| +|------|-----------|----------|------------| +|`druid/heartbeat`| Report service health. For Overlord/Coordinator, the dimension is leader count. `ServiceStatusMonitor` must be enabled. |`heartbeatType`|1| Review Comment: Stale doc. ```suggestion |`druid/heartbeat`| Metric indicating the service is up. `ServiceStatusMonitor` must be enabled. |`leader` on the Overlord and Coordinator.|1| ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
