Skip to content

Commit 37804e0

Browse files
patduinjavsanbel2
andauthored
Added metrics and removed retryHandler (#330)
* Added metrics and removed retryHandler * added namespace to the metric --------- Co-authored-by: Javier Sánchez Beltrán <[email protected]>
1 parent 873ffbe commit 37804e0

File tree

10 files changed

+43
-27
lines changed

10 files changed

+43
-27
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.13.3] - 2024-10-02
2+
### Added
3+
- Metric for monitoring open transports. `<prefix>.open_transports_gauge`
4+
### Changed
5+
- Removed RetryingHMSHandler. Retries are done in the client there should be no need to wrap everything in retry logic again.
6+
17
## [3.13.2] - 2024-07-23
28
### Fix
39
- Add HiveConf cache to `CloseableThriftHiveMetastoreIfaceClientFactory` to prevent threads block. See [#325](https://github.com/ExpediaGroup/waggle-dance/issues/325)

waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/mapping/model/DatabaseMappingImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2023 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/TSetIpAddressProcessorFactory.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2023 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,9 +19,7 @@
1919

2020
import org.apache.hadoop.hive.conf.HiveConf;
2121
import org.apache.hadoop.hive.metastore.IHMSHandler;
22-
import org.apache.hadoop.hive.metastore.RetryingHMSHandler;
2322
import org.apache.hadoop.hive.metastore.TSetIpAddressProcessor;
24-
import org.apache.hadoop.hive.metastore.api.MetaException;
2523
import org.apache.thrift.TProcessor;
2624
import org.apache.thrift.TProcessorFactory;
2725
import org.apache.thrift.transport.TSocket;
@@ -61,24 +59,16 @@ public TProcessor getProcessor(TTransport transport) {
6159

6260
boolean useSASL = hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL);
6361
if (useSASL) {
64-
IHMSHandler tokenHandler = TokenWrappingHMSHandler.newProxyInstance(baseHandler, useSASL);
65-
IHMSHandler handler = newRetryingHMSHandler(ExceptionWrappingHMSHandler.newProxyInstance(tokenHandler), hiveConf,
66-
false);
62+
IHMSHandler handler = TokenWrappingHMSHandler.newProxyInstance(baseHandler, useSASL);
6763
return new TSetIpAddressProcessor<>(handler);
6864
} else {
69-
IHMSHandler handler = newRetryingHMSHandler(ExceptionWrappingHMSHandler.newProxyInstance(baseHandler), hiveConf,
70-
false);
65+
IHMSHandler handler = ExceptionWrappingHMSHandler.newProxyInstance(baseHandler);
7166
transportMonitor.monitor(transport, baseHandler);
7267
return new TSetIpAddressProcessor<>(handler);
7368
}
74-
} catch (MetaException | ReflectiveOperationException | RuntimeException e) {
69+
} catch (ReflectiveOperationException | RuntimeException e) {
7570
throw new RuntimeException("Error creating TProcessor", e);
7671
}
7772
}
7873

79-
private IHMSHandler newRetryingHMSHandler(IHMSHandler baseHandler, HiveConf hiveConf, boolean local)
80-
throws MetaException {
81-
return RetryingHMSHandler.getProxy(hiveConf, baseHandler, local);
82-
}
83-
8474
}

waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/TTransportMonitor.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2019 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,13 +30,17 @@
3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.stereotype.Component;
3232

33+
import io.micrometer.core.instrument.Gauge;
34+
import io.micrometer.core.instrument.MeterRegistry;
35+
3336
import com.google.common.annotations.VisibleForTesting;
3437

3538
import com.hotels.bdp.waggledance.conf.WaggleDanceConfiguration;
3639

3740
@Component
3841
public class TTransportMonitor {
3942

43+
static final String METRIC_NAME_OPEN_TRANSPORTS = "com_hotels_bdp_waggledance_open_transports_gauge";
4044
private static final Logger LOG = LoggerFactory.getLogger(TTransportMonitor.class);
4145

4246
private static class ActionContainer {
@@ -53,13 +57,17 @@ private ActionContainer(TTransport transport, Closeable action) {
5357
private final ConcurrentLinkedQueue<ActionContainer> transports = new ConcurrentLinkedQueue<>();
5458

5559
@Autowired
56-
public TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration) {
57-
this(waggleDanceConfiguration, Executors.newScheduledThreadPool(1));
60+
public TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration, MeterRegistry meterRegistry) {
61+
this(waggleDanceConfiguration, Executors.newScheduledThreadPool(1), meterRegistry);
5862
}
5963

6064
@VisibleForTesting
61-
TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration, ScheduledExecutorService scheduler) {
65+
TTransportMonitor(
66+
WaggleDanceConfiguration waggleDanceConfiguration,
67+
ScheduledExecutorService scheduler,
68+
MeterRegistry meterRegistry) {
6269
this.scheduler = scheduler;
70+
Gauge.builder(METRIC_NAME_OPEN_TRANSPORTS, transports, ConcurrentLinkedQueue::size).register(meterRegistry);
6371
Runnable monitor = () -> {
6472
LOG.debug("Releasing disconnected sessions");
6573
Iterator<ActionContainer> iterator = transports.iterator();
@@ -80,6 +88,7 @@ public TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration) {
8088
}
8189
iterator.remove();
8290
}
91+
LOG.info("Number of open transports (#connections clients -> WD ): {}", transports.size());
8392
};
8493
this.scheduler
8594
.scheduleAtFixedRate(monitor, waggleDanceConfiguration.getDisconnectConnectionDelay(),

waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/security/AccessControlHandlerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2019 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/mapping/model/DatabaseMappingImplTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2021 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,6 +83,7 @@
8383
import org.mockito.junit.MockitoJUnitRunner;
8484

8585
import com.google.common.collect.Lists;
86+
8687
import com.hotels.bdp.waggledance.api.WaggleDanceException;
8788

8889
@RunWith(MockitoJUnitRunner.class)

waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/server/TSetIpAddressProcessorFactoryTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2020 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,6 @@ public class TSetIpAddressProcessorFactoryTest {
4848
@Before
4949
public void init() {
5050
when(federatedHMSHandlerFactory.create()).thenReturn(federatedHMSHandler);
51-
when(federatedHMSHandler.getConf()).thenReturn(hiveConf);
5251
factory = new TSetIpAddressProcessorFactory(hiveConf, federatedHMSHandlerFactory, transportMonitor);
5352
}
5453

waggle-dance-core/src/test/java/com/hotels/bdp/waggledance/server/TTransportMonitorTest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2016-2020 Expedia, Inc.
2+
* Copyright (C) 2016-2024 Expedia, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,9 @@
3939
import org.mockito.Mock;
4040
import org.mockito.junit.MockitoJUnitRunner;
4141

42+
import io.micrometer.core.instrument.MeterRegistry;
43+
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
44+
4245
import com.hotels.bdp.waggledance.conf.WaggleDanceConfiguration;
4346

4447
@RunWith(MockitoJUnitRunner.class)
@@ -52,21 +55,25 @@ public class TTransportMonitorTest {
5255
private @Mock TTransport transport;
5356
private @Mock Closeable action;
5457
private @Mock ScheduledExecutorService scheduler;
58+
private MeterRegistry meterRegistry;
5559

5660
private TTransportMonitor monitor;
5761

62+
5863
@Before
5964
public void init() {
65+
meterRegistry = new SimpleMeterRegistry();
6066
when(waggleDanceConfiguration.getDisconnectConnectionDelay()).thenReturn((int) DEFAULT_DELAY);
6167
when(waggleDanceConfiguration.getDisconnectTimeUnit()).thenReturn(MILLISECONDS);
62-
monitor = new TTransportMonitor(waggleDanceConfiguration, scheduler);
68+
monitor = new TTransportMonitor(waggleDanceConfiguration, scheduler, meterRegistry);
6369
verify(scheduler).scheduleAtFixedRate(runnableCaptor.capture(), anyLong(), anyLong(), any(TimeUnit.class));
6470
}
6571

6672
@Test
6773
public void initialization() throws Exception {
6874
assertThat(runnableCaptor.getValue(), is(notNullValue()));
6975
verify(scheduler).scheduleAtFixedRate(runnableCaptor.getValue(), DEFAULT_DELAY, DEFAULT_DELAY, MILLISECONDS);
76+
assertThat(meterRegistry.get(TTransportMonitor.METRIC_NAME_OPEN_TRANSPORTS).gauge().value(), is(0.0));
7077
}
7178

7279
@Test
@@ -76,6 +83,7 @@ public void shouldNotDisconnect() throws Exception {
7683
runnableCaptor.getValue().run();
7784
verify(transport, never()).close();
7885
verify(action, never()).close();
86+
assertThat(meterRegistry.get(TTransportMonitor.METRIC_NAME_OPEN_TRANSPORTS).gauge().value(), is(1.0));
7987
}
8088

8189
@Test
@@ -85,6 +93,7 @@ public void shouldDisconnect() throws Exception {
8593
runnableCaptor.getValue().run();
8694
verify(transport).close();
8795
verify(action).close();
96+
assertThat(meterRegistry.get(TTransportMonitor.METRIC_NAME_OPEN_TRANSPORTS).gauge().value(), is(0.0));
8897
}
8998

9099
@Test
@@ -95,6 +104,7 @@ public void shouldDisconnectWhenTransportThrowsException() throws Exception {
95104
runnableCaptor.getValue().run();
96105
verify(transport).close();
97106
verify(action).close();
107+
assertThat(meterRegistry.get(TTransportMonitor.METRIC_NAME_OPEN_TRANSPORTS).gauge().value(), is(0.0));
98108
}
99109

100110
@Test
@@ -105,6 +115,7 @@ public void shouldDisconnectWhenActionThrowsException() throws Exception {
105115
runnableCaptor.getValue().run();
106116
verify(transport).close();
107117
verify(action).close();
118+
assertThat(meterRegistry.get(TTransportMonitor.METRIC_NAME_OPEN_TRANSPORTS).gauge().value(), is(0.0));
108119
}
109120

110121
}

waggle-dance-integration-tests/src/test/resources/log4j.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
2121
<layout class="org.apache.log4j.PatternLayout">
2222
<!-- WaggleDance Integration Tests (WD_IT) log (through hive dependencies) via log4j (not log4j2.xml which controls the logging of the started WaggleDanceRunner) -->
23-
<param name="ConversionPattern" value="%d{ISO8601} WD_IT %tn %-5p %c:%L - %m%n" />
23+
<param name="ConversionPattern" value="%d{ISO8601} WD_IT %t %-5p %c:%L - %m%n" />
2424
</layout>
2525
</appender>
2626

waggle-dance-integration-tests/src/test/resources/log4j2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Configuration>
1818
<Appenders>
1919
<Console name="STDOUT" target="SYSTEM_OUT">
20-
<PatternLayout pattern="%d{ISO8601} %tn %-5p %c:%L - %m%n"/>
20+
<PatternLayout pattern="%d{ISO8601} %t %-5p %c:%L - %m%n"/>
2121
</Console>
2222
</Appenders>
2323
<Loggers>

0 commit comments

Comments
 (0)