Skip to content

Commit 5daddc3

Browse files
Remove linked project connection error metric
The message logged in RemoteConnectionStrategy has proven sufficient for use in constructing the dashboard and implementing an alert. This PR is for removing the metric code to avoid emitting extra unused APM data. Relates: ES-12696
1 parent 8975f24 commit 5daddc3

File tree

3 files changed

+1
-75
lines changed

3 files changed

+1
-75
lines changed

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public final class RemoteClusterService extends RemoteClusterAware
6565
private static final Logger logger = LogManager.getLogger(RemoteClusterService.class);
6666

6767
public static final String REMOTE_CLUSTER_HANDSHAKE_ACTION_NAME = "cluster:internal/remote_cluster/handshake";
68-
public static final String CONNECTION_ATTEMPT_FAILURES_COUNTER_NAME = "es.projects.linked.connections.error.total";
6968

7069
private final boolean isRemoteClusterClient;
7170
private final boolean isSearchNode;
@@ -102,13 +101,6 @@ public boolean isRemoteClusterServerEnabled() {
102101
* the functionality to do it the right way is not yet ready -- replace this code when it's ready.
103102
*/
104103
this.crossProjectEnabled = settings.getAsBoolean("serverless.cross_project.enabled", false);
105-
// Since this counter may never be incremented we need to force an initial observed value of zero via add(0) so the metric will be
106-
// in the mappings of the indices of the APM data stream, otherwise we will encounter 'not found' errors in dashboards and alerts.
107-
// See observability-dev issue #3042.
108-
transportService.getTelemetryProvider()
109-
.getMeterRegistry()
110-
.registerLongUpDownCounter(CONNECTION_ATTEMPT_FAILURES_COUNTER_NAME, "linked project connection attempt failure count", "count")
111-
.add(0);
112104
}
113105

114106
public RemoteClusterCredentialsManager getRemoteClusterCredentialsManager() {

server/src/main/java/org/elasticsearch/transport/RemoteConnectionStrategy.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
2222
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
2323
import org.elasticsearch.core.Nullable;
24-
import org.elasticsearch.telemetry.TelemetryProvider;
25-
import org.elasticsearch.telemetry.metric.LongUpDownCounter;
2624
import org.elasticsearch.threadpool.ThreadPool;
2725

2826
import java.io.Closeable;
@@ -33,7 +31,6 @@
3331
import java.util.ArrayList;
3432
import java.util.Collections;
3533
import java.util.List;
36-
import java.util.Map;
3734
import java.util.Objects;
3835
import java.util.concurrent.ExecutorService;
3936
import java.util.concurrent.atomic.AtomicBoolean;
@@ -79,10 +76,6 @@ enum ConnectionAttempt {
7976
reconnect
8077
}
8178

82-
static final String linkedProjectIdLabel = "es_linked_project_id";
83-
static final String linkedProjectAliasLabel = "es_linked_project_alias";
84-
static final String connectionAtemptLabel = "es_linked_project_attempt";
85-
8679
private final int maxPendingConnectionListeners;
8780

8881
protected final Logger logger = LogManager.getLogger(getClass());
@@ -91,7 +84,6 @@ enum ConnectionAttempt {
9184
private final Object mutex = new Object();
9285
private List<ActionListener<Void>> listeners = new ArrayList<>();
9386
private final AtomicBoolean initialConnectionAttempted = new AtomicBoolean(false);
94-
private final LongUpDownCounter connectionAttemptFailures;
9587

9688
protected final TransportService transportService;
9789
protected final RemoteConnectionManager connectionManager;
@@ -106,17 +98,9 @@ enum ConnectionAttempt {
10698
this.transportService = transportService;
10799
this.connectionManager = connectionManager;
108100
this.maxPendingConnectionListeners = config.maxPendingConnectionListeners();
109-
this.connectionAttemptFailures = lookupConnectionFailureMetric(transportService.getTelemetryProvider());
110101
connectionManager.addListener(this);
111102
}
112103

113-
private LongUpDownCounter lookupConnectionFailureMetric(TelemetryProvider telemetryProvider) {
114-
final var meterRegistry = telemetryProvider == null ? null : telemetryProvider.getMeterRegistry();
115-
return meterRegistry == null
116-
? null
117-
: meterRegistry.getLongUpDownCounter(RemoteClusterService.CONNECTION_ATTEMPT_FAILURES_COUNTER_NAME);
118-
}
119-
120104
static ConnectionProfile buildConnectionProfile(LinkedProjectConfig config, String transportProfile) {
121105
ConnectionProfile.Builder builder = new ConnectionProfile.Builder().setConnectTimeout(config.transportConnectTimeout())
122106
.setHandshakeTimeout(config.transportConnectTimeout())
@@ -242,21 +226,7 @@ private void connectionAttemptCompleted(@Nullable Exception e) {
242226
if (e == null) {
243227
logger.debug(msgSupplier);
244228
} else {
245-
final var isClosed = isClosed();
246-
logger.log(isClosed ? Level.DEBUG : Level.WARN, msgSupplier, e);
247-
if (isClosed == false && connectionAttemptFailures != null) {
248-
connectionAttemptFailures.add(
249-
1,
250-
Map.of(
251-
linkedProjectIdLabel,
252-
linkedProjectId.toString(),
253-
linkedProjectAliasLabel,
254-
clusterAlias,
255-
connectionAtemptLabel,
256-
(isInitialAttempt ? ConnectionAttempt.initial : ConnectionAttempt.reconnect).toString()
257-
)
258-
);
259-
}
229+
logger.log(isClosed() ? Level.DEBUG : Level.WARN, msgSupplier, e);
260230
}
261231
}
262232

server/src/test/java/org/elasticsearch/transport/RemoteConnectionStrategyTests.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.elasticsearch.common.util.concurrent.ThreadContext;
2121
import org.elasticsearch.core.Strings;
2222
import org.elasticsearch.core.TimeValue;
23-
import org.elasticsearch.telemetry.InstrumentType;
24-
import org.elasticsearch.telemetry.RecordingMeterRegistry;
2523
import org.elasticsearch.test.ESTestCase;
2624
import org.elasticsearch.test.EnumSerializationTestUtils;
2725
import org.elasticsearch.test.MockLog;
@@ -32,7 +30,6 @@
3230

3331
import java.util.List;
3432
import java.util.Map;
35-
import java.util.Set;
3633
import java.util.concurrent.CountDownLatch;
3734

3835
import static org.elasticsearch.test.MockLog.assertThatLogger;
@@ -42,7 +39,6 @@
4239
import static org.elasticsearch.transport.RemoteClusterSettings.SniffConnectionStrategySettings.REMOTE_CLUSTER_SEEDS;
4340
import static org.elasticsearch.transport.RemoteClusterSettings.toConfig;
4441
import static org.elasticsearch.transport.RemoteConnectionStrategy.buildConnectionProfile;
45-
import static org.hamcrest.Matchers.equalTo;
4642
import static org.mockito.Mockito.mock;
4743

4844
public class RemoteConnectionStrategyTests extends ESTestCase {
@@ -219,11 +215,6 @@ public void testConnectionAttemptMetricsAndLogging() {
219215
new ClusterConnectionManager(TestProfiles.LIGHT_PROFILE, mock(Transport.class), threadContext)
220216
)
221217
) {
222-
assert transportService.getTelemetryProvider() != null;
223-
final var meterRegistry = transportService.getTelemetryProvider().getMeterRegistry();
224-
assert meterRegistry instanceof RecordingMeterRegistry;
225-
final var metricRecorder = ((RecordingMeterRegistry) meterRegistry).getRecorder();
226-
227218
for (boolean shouldConnectFail : new boolean[] { true, false }) {
228219
for (boolean isInitialConnectAttempt : new boolean[] { true, false }) {
229220
final var strategy = new FakeConnectionStrategy(
@@ -265,34 +256,12 @@ public void testConnectionAttemptMetricsAndLogging() {
265256
expectedLogMessage
266257
)
267258
);
268-
if (shouldConnectFail) {
269-
metricRecorder.collect();
270-
final var counterName = RemoteClusterService.CONNECTION_ATTEMPT_FAILURES_COUNTER_NAME;
271-
final var measurements = metricRecorder.getMeasurements(InstrumentType.LONG_UP_DOWN_COUNTER, counterName);
272-
assertFalse(measurements.isEmpty());
273-
final var measurement = measurements.getLast();
274-
assertThat(measurement.getLong(), equalTo(1L));
275-
final var attributes = measurement.attributes();
276-
final var keySet = Set.of(
277-
RemoteConnectionStrategy.linkedProjectIdLabel,
278-
RemoteConnectionStrategy.linkedProjectAliasLabel,
279-
RemoteConnectionStrategy.connectionAtemptLabel
280-
);
281-
final var expectedAttemptType = isInitialConnectAttempt
282-
? RemoteConnectionStrategy.ConnectionAttempt.initial
283-
: RemoteConnectionStrategy.ConnectionAttempt.reconnect;
284-
assertThat(attributes.keySet(), equalTo(keySet));
285-
assertThat(attributes.get(RemoteConnectionStrategy.linkedProjectIdLabel), equalTo(linkedProjectId.toString()));
286-
assertThat(attributes.get(RemoteConnectionStrategy.linkedProjectAliasLabel), equalTo(alias));
287-
assertThat(attributes.get(RemoteConnectionStrategy.connectionAtemptLabel), equalTo(expectedAttemptType.toString()));
288-
}
289259
}
290260
}
291261

292262
// Now verify connection errors when closing (node shutting down) are logged at debug and not warn.
293263
final var strategy = new FakeConnectionStrategy(originProjectId, linkedProjectId, alias, transportService, connectionManager);
294264
waitForConnect(strategy);
295-
metricRecorder.resetCalls();
296265
strategy.setShouldConnectFail(true);
297266
strategy.setWaitInConnect(true);
298267
final var expectedLogLevel = Level.DEBUG;
@@ -320,11 +289,6 @@ public void testConnectionAttemptMetricsAndLogging() {
320289
expectedLogMessage
321290
)
322291
);
323-
// Expect no metric change if the strategy has been closed.
324-
metricRecorder.collect();
325-
final var counterName = RemoteClusterService.CONNECTION_ATTEMPT_FAILURES_COUNTER_NAME;
326-
final var measurements = metricRecorder.getMeasurements(InstrumentType.LONG_UP_DOWN_COUNTER, counterName);
327-
assertTrue(measurements.isEmpty());
328292
}
329293
}
330294

0 commit comments

Comments
 (0)