Skip to content

Commit

Permalink
Minor changes in instance logging thanks to PR feedback.
Browse files Browse the repository at this point in the history
Also removed the empty MetadataMigration file that was a result of the last merge (the file was moved)

Signed-off-by: Greg Schohn <[email protected]>
  • Loading branch information
gregschohn committed Sep 10, 2024
1 parent 8847c03 commit fd9b306
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,6 @@ public void testDocumentMigration(
}
}

// @Test
// public void testDocumentMigrationForBigMonolithicShardWorks() throws Exception {
// testDocumentMigration(1,
// SearchClusterContainer.OS_V2_14_0.getImageName(),
// SearchClusterContainer.OS_V2_14_0,
// GENERATOR_BASE_IMAGE,
// new String[]{"tail", "-f", "/dev/null"});
// }

private void verifyWorkMetrics(DocumentMigrationTestContext rootContext, int numWorkers, int numRuns) {
var workMetrics = rootContext.inMemoryInstrumentationBundle.getFinishedMetrics();
var migrationMetrics = rootContext.inMemoryInstrumentationBundle.getFinishedMetrics();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RootOtelContext implements IRootOtelContext {
public static OpenTelemetry initializeOpenTelemetryForCollector(
@NonNull String collectorEndpoint,
@NonNull String serviceName,
String nodeName
@NonNull String nodeName
) {
final var spanProcessor = BatchSpanProcessor.builder(
OtlpGrpcSpanExporter.builder().setEndpoint(collectorEndpoint).setTimeout(2, TimeUnit.SECONDS).build()
Expand Down Expand Up @@ -89,8 +89,8 @@ public static OpenTelemetry initializeNoopOpenTelemetry() {
*/
public static OpenTelemetry initializeOpenTelemetryWithCollectorOrAsNoop(
String collectorEndpoint,
String serviceName,
String instanceName
@NonNull String serviceName,
@NonNull String instanceName
) {
return Optional.ofNullable(collectorEndpoint)
.map(endpoint -> initializeOpenTelemetryForCollector(endpoint, serviceName, instanceName))
Expand Down Expand Up @@ -123,12 +123,15 @@ public CommonMetricInstruments getMetrics() {
return null;
}

public RootOtelContext(String scopeName, IContextTracker contextTracker, String instanceName) {
public RootOtelContext(@NonNull String scopeName,
IContextTracker contextTracker,
@NonNull String serviceName,
@NonNull String instanceName) {
this(scopeName, contextTracker,
initializeOpenTelemetryWithCollectorOrAsNoop(null, null, instanceName));
initializeOpenTelemetryWithCollectorOrAsNoop(null, serviceName, instanceName));
}

public RootOtelContext(String scopeName, IContextTracker contextTracker, @NonNull OpenTelemetry sdk) {
public RootOtelContext(String scopeName, IContextTracker contextTracker, @NonNull OpenTelemetry sdk) {
openTelemetryImpl = sdk;
this.scopeName = scopeName;
this.contextTracker = contextTracker;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
package org.opensearch.migrations.utils;

import java.util.Optional;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ProcessHelpers {
private static final String DEFAULT_NODE_ID = UUID.randomUUID().toString();
private static final String DEFAULT_NODE_ID = "generated_" + UUID.randomUUID().toString();

public static String getNodeInstanceName() {
String id = null;
try {
id = System.getenv("ECS_TASK_ID"); // for ECS deployments
if (id != null) {
return id;
}
id = System.getenv("HOSTNAME"); // for any kubernetes deployed pod
if (id != null) {
return id;
}
// add additional fallbacks here
id = DEFAULT_NODE_ID;
return id;
} finally {
if (id != null) {
String finalId = id;
log.atInfo().setMessage(() -> "getNodeInstanceName()=" + finalId).log();
}
}
var nodeId = Optional.of("ECS_TASK_ID").map(System::getenv)
.or(() -> Optional.of("HOSTNAME").map(System::getenv))
.orElse(DEFAULT_NODE_ID);
log.atInfo().setMessage(() -> "getNodeInstanceName()=" + nodeId).log();
return nodeId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AttributesBuilder fillAttributesForSpansBelow(AttributesBuilder builder)

@Test
public void getPopulatedAttributesAreOverrideCorrectly() {
var rootCtx = new RootOtelContext("test", IContextTracker.DO_NOTHING_TRACKER, "unit_test");
var rootCtx = new RootOtelContext("test", IContextTracker.DO_NOTHING_TRACKER, "unitTestSvc", "testNode");
var aCtx = new AContext(rootCtx);
var bCtx = new BContext(rootCtx, aCtx);

Expand Down

0 comments on commit fd9b306

Please sign in to comment.