diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/DynamicGrpcClient.java b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/DynamicGrpcClient.java index 1b05a0bb545f4..02cc6ae7ff0bc 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/DynamicGrpcClient.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/DynamicGrpcClient.java @@ -7,16 +7,16 @@ */ package org.elasticsearch.gradle.testclusters; -import com.google.protobuf.Any; -import com.google.protobuf.StringValue; import io.grpc.CallOptions; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.MethodDescriptor; -import io.grpc.stub.ClientCalls; -import io.grpc.stub.StreamObserver; import io.grpc.protobuf.ProtoUtils; +import io.grpc.stub.ClientCalls; + +import com.google.protobuf.Any; +import com.google.protobuf.StringValue; public class DynamicGrpcClient { private final ManagedChannel channel; @@ -54,9 +54,9 @@ public void shutdown() { public static void main(String[] args) { DynamicGrpcClient client = new DynamicGrpcClient("localhost", 9999); -// client. -// String response = client.sendMessage("Hello, dynamic message!"); -// System.out.println("Response: " + response); -// client.shutdown(); + // client. + // String response = client.sendMessage("Hello, dynamic message!"); + // System.out.println("Response: " + response); + // client.shutdown(); } } diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/MockGrpcApmServer.java b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/MockGrpcApmServer.java index abb5462dfad70..978edba1eb467 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/MockGrpcApmServer.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/MockGrpcApmServer.java @@ -8,25 +8,9 @@ package org.elasticsearch.gradle.testclusters; -import com.google.protobuf.ByteString; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; - -import io.grpc.BindableService; -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.MethodDescriptor; import io.grpc.Server; import io.grpc.ServerBuilder; -import io.grpc.ServerServiceDefinition; -import io.grpc.protobuf.ProtoUtils; -import io.grpc.stub.ServerCalls; import io.grpc.stub.StreamObserver; -import com.google.protobuf.Any; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.StringValue; - import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest; import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse; import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc; @@ -37,11 +21,7 @@ import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetSocketAddress; /** * This is a server which just accepts lines of JSON code and if the JSON @@ -72,11 +52,13 @@ public static void main(String[] args) throws IOException, InterruptedException server.start(); server.blockUntilShutdown(); } + private void blockUntilShutdown() throws InterruptedException { if (server != null) { server.awaitTermination(); } } + private Server server; /** @@ -88,16 +70,11 @@ private void blockUntilShutdown() throws InterruptedException { public synchronized int start() throws IOException { if (server != null) { int port = server.getPort(); - logger.lifecycle("MockApmServer is already running. Reusing on address:port "+ port); + logger.lifecycle("MockApmServer is already running. Reusing on address:port " + port); return port; } - - server = ServerBuilder.forPort(port) - .addService(new TraceServiceImpl()) - .addService(new MetricsServiceImpl()) - .build() - .start(); + server = ServerBuilder.forPort(port).addService(new TraceServiceImpl()).addService(new MetricsServiceImpl()).build().start(); System.out.println("Server started, listening on " + port); Runtime.getRuntime().addShutdownHook(new Thread(() -> { System.err.println("*** shutting down gRPC server since JVM is shutting down"); @@ -125,14 +102,14 @@ static class TraceServiceImpl extends TraceServiceGrpc.TraceServiceImplBase { @Override public void export(ExportTraceServiceRequest request, StreamObserver responseObserver) { super.export(request, responseObserver); - System.out.println("TRACE SERVICE RECEIVED "+request.toString()); + System.out.println("TRACE SERVICE RECEIVED " + request.toString()); } } static class MetricsServiceImpl extends MetricsServiceGrpc.MetricsServiceImplBase { @Override public void export(ExportMetricsServiceRequest request, StreamObserver responseObserver) { - System.out.println("METRICS SERVICE RECEIVED "+request.toString()); + System.out.println("METRICS SERVICE RECEIVED " + request.toString()); } } } diff --git a/distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/APMJvmOptions.java b/distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/APMJvmOptions.java index 4cccf306127fc..832b3f6b4d29b 100644 --- a/distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/APMJvmOptions.java +++ b/distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/APMJvmOptions.java @@ -135,44 +135,44 @@ class APMJvmOptions { */ static List apmJvmOptions(Settings settings, @Nullable SecureSettings secrets, Path logsDir, Path tmpdir) throws UserException, IOException { -// final Path agentJar = findAgentJar(); -// -// if (agentJar == null) { -// return List.of(); -// } -// -// final Map propertiesMap = extractApmSettings(settings); -// -// // Configures a log file to write to. Don't disable writing to a log file, -// // as the agent will then require extra Security Manager permissions when -// // it tries to do something else, and it's just painful. -// propertiesMap.put("log_file", logsDir.resolve("apm-agent.json").toString()); -// -// // No point doing anything if we don't have a destination for the trace data, and it can't be configured dynamically -// if (propertiesMap.containsKey("server_url") == false && propertiesMap.containsKey("server_urls") == false) { -// return List.of(); -// } -// -// if (propertiesMap.containsKey("service_node_name") == false) { -// final String nodeName = settings.get("node.name"); -// if (nodeName != null) { -// propertiesMap.put("service_node_name", nodeName); -// } -// } -// -// if (secrets != null) { -// extractSecureSettings(secrets, propertiesMap); -// } -// final Map dynamicSettings = extractDynamicSettings(propertiesMap); -// -// final Path tmpProperties = writeApmProperties(tmpdir, propertiesMap); + // final Path agentJar = findAgentJar(); + // + // if (agentJar == null) { + // return List.of(); + // } + // + // final Map propertiesMap = extractApmSettings(settings); + // + // // Configures a log file to write to. Don't disable writing to a log file, + // // as the agent will then require extra Security Manager permissions when + // // it tries to do something else, and it's just painful. + // propertiesMap.put("log_file", logsDir.resolve("apm-agent.json").toString()); + // + // // No point doing anything if we don't have a destination for the trace data, and it can't be configured dynamically + // if (propertiesMap.containsKey("server_url") == false && propertiesMap.containsKey("server_urls") == false) { + // return List.of(); + // } + // + // if (propertiesMap.containsKey("service_node_name") == false) { + // final String nodeName = settings.get("node.name"); + // if (nodeName != null) { + // propertiesMap.put("service_node_name", nodeName); + // } + // } + // + // if (secrets != null) { + // extractSecureSettings(secrets, propertiesMap); + // } + // final Map dynamicSettings = extractDynamicSettings(propertiesMap); + // + // final Path tmpProperties = writeApmProperties(tmpdir, propertiesMap); final List options = new ArrayList<>(); // Use an agent argument to specify the config file instead of e.g. `-Delastic.apm.config_file=...` // because then the agent won't try to reload the file, and we can remove it after startup. - // options.add(agentCommandLineOption(agentJar, tmpProperties)); + // options.add(agentCommandLineOption(agentJar, tmpProperties)); -// dynamicSettings.forEach((key, value) -> options.add("-Delastic.apm." + key + "=" + value)); + // dynamicSettings.forEach((key, value) -> options.add("-Delastic.apm." + key + "=" + value)); return options; } diff --git a/libs/telemetry/src/main/java/module-info.java b/libs/telemetry/src/main/java/module-info.java index 09921178e7a94..268f6b87d4bd9 100644 --- a/libs/telemetry/src/main/java/module-info.java +++ b/libs/telemetry/src/main/java/module-info.java @@ -8,6 +8,7 @@ module org.elasticsearch.telemetry { requires org.elasticsearch.base; + exports org.elasticsearch.telemetry; exports org.elasticsearch.telemetry.metric; exports org.elasticsearch.telemetry.tracing; diff --git a/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APM.java b/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APM.java index 21c4de2f8b4cc..342ab566680d0 100644 --- a/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APM.java +++ b/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/APM.java @@ -10,6 +10,14 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,16 +34,6 @@ import org.elasticsearch.telemetry.apm.internal.APMMeterService; import org.elasticsearch.telemetry.apm.internal.APMTelemetryProvider; import org.elasticsearch.telemetry.apm.internal.tracing.APMTracer; - -import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; - import org.elasticsearch.telemetry.apm.jvm.JvmFdMetrics; import java.security.AccessController; @@ -69,20 +67,21 @@ public class APM extends Plugin implements NetworkPlugin, TelemetryPlugin { private final SetOnce telemetryProvider = new SetOnce<>(); private final Settings settings; JvmFdMetrics jvmFdMetrics = new JvmFdMetrics(); + public APM(Settings settings) { this.settings = settings; } @Override public TelemetryProvider getTelemetryProvider(Settings settings) { - Log4jBridgeHandler.install(false,"",true); -//metrics to check https://test-apm-9fc321.kb.us-central1.gcp.cloud.es.io:9243/app/r/s/Zy7QT + Log4jBridgeHandler.install(false, "", true); + // metrics to check https://test-apm-9fc321.kb.us-central1.gcp.cloud.es.io:9243/app/r/s/Zy7QT String ENDPOINT = settings.get("telemetry.agent.server_url"); TimeValue interval = settings.getAsTime("telemetry.agent.metrics_interval", TimeValue.ONE_MINUTE); -// String ENDPOINT = "https://3b4a40972a494625a76de9ef337ef425.apm.us-central1.gcp.cloud.es.io:443"; + // String ENDPOINT = "https://3b4a40972a494625a76de9ef337ef425.apm.us-central1.gcp.cloud.es.io:443"; AccessController.doPrivileged((PrivilegedAction) () -> { - createOtel(ENDPOINT,interval); + createOtel(ENDPOINT, interval); return null; }); @@ -94,36 +93,33 @@ public TelemetryProvider getTelemetryProvider(Settings settings) { private static void createOtel(String ENDPOINT, TimeValue interval) { OtlpGrpcSpanExporter spanExporter = OtlpGrpcSpanExporter.builder() .setEndpoint(ENDPOINT) - // .addHeader("Authorization", "Bearer RXX6gm1WeXlx8qHw3a") + // .addHeader("Authorization", "Bearer RXX6gm1WeXlx8qHw3a") .build(); OtlpGrpcMetricExporter metricExporter = OtlpGrpcMetricExporter.builder() .setEndpoint(ENDPOINT) - // .addHeader("Authorization", "Bearer RXX6gm1WeXlx8qHw3a") + // .addHeader("Authorization", "Bearer RXX6gm1WeXlx8qHw3a") .build(); - Resource resource = Resource.getDefault().merge(Resource.create( - Attributes.of(AttributeKey.stringKey("service.name"), "testing_otel_sdk"))); + Resource resource = Resource.getDefault() + .merge(Resource.create(Attributes.of(AttributeKey.stringKey("service.name"), "testing_otel_sdk"))); + PeriodicMetricReader build = PeriodicMetricReader.builder(metricExporter).setInterval(interval.getSeconds(), TimeUnit.SECONDS).build(); SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder() .setResource(resource) - .registerMetricReader(PeriodicMetricReader.builder(metricExporter).setInterval(interval.getSeconds(), TimeUnit.SECONDS).build()) + .registerMetricReader(build) .build(); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .setResource(resource) .addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build()) .build(); - OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setMeterProvider(sdkMeterProvider) - .buildAndRegisterGlobal(); - + OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).setMeterProvider(sdkMeterProvider).buildAndRegisterGlobal(); } @Override public Collection createComponents(PluginServices services) { - //grpc won't work due to okhttp not being modular (relying on internal package) + // grpc won't work due to okhttp not being modular (relying on internal package) final APMTracer apmTracer = telemetryProvider.get().getTracer(); final APMMeterService apmMeter = telemetryProvider.get().getMeterService(); diff --git a/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/jvm/JvmFdMetrics.java b/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/jvm/JvmFdMetrics.java index fbff930a287e7..7aab471b043f1 100644 --- a/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/jvm/JvmFdMetrics.java +++ b/modules/apm/src/main/java/org/elasticsearch/telemetry/apm/jvm/JvmFdMetrics.java @@ -27,9 +27,10 @@ import java.lang.invoke.MethodType; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; + import javax.annotation.Nullable; -public class JvmFdMetrics /*extends AbstractLifecycleListener */{ +public class JvmFdMetrics /*extends AbstractLifecycleListener */ { // using method handles to avoid direct reference to `com.sun.*` classes which we can't reference directly // as it is not available on all JDKs this is further enforced by the animal sniffer plugin @@ -57,10 +58,9 @@ private static void register(MeterRegistry registry, String name, final Operatin if (methodHandle == NOOP) { return; } - registry.registerLongGauge("es."+name+".total", "","count",()-> { + registry.registerLongGauge("es." + name + ".total", "", "count", () -> { return new LongWithAttributes(getLongWithAttributes(mxBean, methodHandle)); - } - ); + }); } diff --git a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java index 3724ca5507d70..d67b690cc0b6c 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapChecks.java @@ -714,9 +714,9 @@ static class AllPermissionCheck implements BootstrapCheck { @Override public final BootstrapCheckResult check(BootstrapContext context) { -// if (isAllPermissionGranted()) { -// return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security"); -// } + // if (isAllPermissionGranted()) { + // return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security"); + // } return BootstrapCheckResult.success(); } diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Security.java b/server/src/main/java/org/elasticsearch/bootstrap/Security.java index a4388e616d7c1..0bdbb3aab9348 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -106,7 +106,7 @@ final class Security { private Security() {} static void setSecurityManager(@SuppressWarnings("removal") SecurityManager sm) { -// System.setSecurityManager(sm); + // System.setSecurityManager(sm); } /** diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 80333c982f7a1..11eb8760b2dbb 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -430,7 +430,6 @@ public void onTimeout(TimeValue timeout) { injector.getInstance(NodeMetrics.class).start(); injector.getInstance(HealthPeriodicLogger.class).start(); - logger.info("started {}", transportService.getLocalNode()); pluginsService.filterPlugins(ClusterPlugin.class).forEach(ClusterPlugin::onNodeStarted); diff --git a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java index 16a69e72b129a..f74f89ee1ae21 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -102,22 +102,24 @@ public void testWeekBasedDates() { // first week of 2015 starts on Monday 2014-12-29 because 4days belong to 2019 assertThat(DateFormatters.from(dateFormatter.parse("2015")), equalTo(ZonedDateTime.of(2014, 12, 29, 0, 0, 0, 0, ZoneOffset.UTC))); } + public void testUtc() throws ParseException { Date d; Locale locale = Locale.forLanguageTag("sd-Arab"); - //8u391 - 12:39:24 PM BST -// d = new SimpleDateFormat("hh:mm:ss a z", locale).parse("12:39:24 PM BST"); //Unparseable date: "12:39:24 PM BST" -// System.out.println(d); - //11.0.22 - 12:59:58 منجهند، شام GMT+٠١:٠٠ + // 8u391 - 12:39:24 PM BST + // d = new SimpleDateFormat("hh:mm:ss a z", locale).parse("12:39:24 PM BST"); //Unparseable date: "12:39:24 PM BST" + // System.out.println(d); + // 11.0.22 - 12:59:58 منجهند، شام GMT+٠١:٠٠ d = new SimpleDateFormat("hh:mm:ss a z", locale).parse("12:59:58 منجهند، شام GMT+٠١:٠٠"); System.out.println(d); - //17.0.11 - 01:04:51 منجهند، شام GMT+٠١:٠٠ + // 17.0.11 - 01:04:51 منجهند، شام GMT+٠١:٠٠ d = new SimpleDateFormat("hh:mm:ss a z", locale).parse("01:04:51 منجهند، شام GMT+٠١:٠٠"); System.out.println(d); - //22.0.1 - 01:09:33 منجهند، شام BST + // 22.0.1 - 01:09:33 منجهند، شام BST d = new SimpleDateFormat("hh:mm:ss a z", locale).parse("01:09:33 منجهند، شام"); System.out.println(d); } + public void testEpochMillisParser() { DateFormatter formatter = DateFormatters.forPattern("epoch_millis"); {