Yicong-Huang commented on code in PR #5375:
URL: https://github.com/apache/texera/pull/5375#discussion_r4366130575
##########
amber/src/main/scala/org/apache/texera/web/ComputingUnitMaster.scala:
##########
@@ -138,6 +138,7 @@ class ComputingUnitMaster extends
io.dropwizard.Application[Configuration] with
}
override def run(configuration: Configuration, environment: Environment):
Unit = {
+ org.apache.texera.observability.OtelInit.init("computing-unit-master")
Review Comment:
**Must fix:**
In Kubernetes this call can never enable the SDK. CU pods get their env only
from `computingUnitEnvironmentVariables` in
`ComputingUnitManagingResource.scala` (lines 389-404), and its required and
optional name lists (lines 338-351) forward no `OTEL_*` var. So
`OTEL_SDK_DISABLED: "false"` in `values.yaml` turns on every static service
while each CU stays on the HOCON default `true`, which is the JVM the
per-process `service.instance.id` work targets. Add the five
`EnvironmentalVariable.ENV_OTEL_*` / `ENV_TEXERA_OTEL_ALLOWED_HOSTS` names to
`optionalComputingUnitEnvNames`, which forwards them only when set.
##########
access-control-service/LICENSE-binary:
##########
@@ -242,6 +242,9 @@ Scala/Java jars:
-
com.google.guava.listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
- com.google.j2objc.j2objc-annotations-2.8.jar
- com.helger.profiler-1.1.1.jar
+ - com.squareup.okhttp3.okhttp-4.12.0.jar
Review Comment:
**Advisory:**
Anchored here because the PR description is not part of the diff. Its
heading reads "Any related issues, documentation, or discussions?" but the
template's is "Any related issues, documentation, discussions?", so template
tooling reports that section missing. The content is fine; dropping the extra
"or" is enough.
##########
common/observability/src/test/scala/org/apache/texera/observability/OtelInitSpec.scala:
##########
@@ -0,0 +1,310 @@
+/*
+ * 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.texera.observability
+
+import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter
+import org.scalatest.BeforeAndAfterEach
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import scala.jdk.CollectionConverters._
+
+class OtelInitSpec extends AnyFlatSpec with Matchers with BeforeAndAfterEach {
+
+ override def beforeEach(): Unit = {
+ OtelInit.resetForTest()
+ }
+
+ override def afterEach(): Unit = {
+ OtelInit.resetForTest()
+ }
+
+ // ----- validateEndpoint: pure function, exhaustive cases -------------
+
+ "validateEndpoint" should "accept loopback OTLP http(s) URLs" in {
+ OtelInit.validateEndpoint("http://localhost:4317",
OtelInit.DefaultAllowedHosts) shouldBe Right(
+ ()
+ )
+ OtelInit.validateEndpoint("http://127.0.0.1:4317",
OtelInit.DefaultAllowedHosts) shouldBe Right(
+ ()
+ )
+ OtelInit.validateEndpoint(
+ "https://localhost:4318",
+ OtelInit.DefaultAllowedHosts
+ ) shouldBe Right(())
+ }
+
+ it should "reject a grpc:// endpoint (the OTLP exporter accepts only
http/https)" in {
+ val result = OtelInit.validateEndpoint("grpc://127.0.0.1:4317",
OtelInit.DefaultAllowedHosts)
+ result.isLeft shouldBe true
+ result.left.toOption.get should include("scheme")
+ }
+
+ it should "reject file:// schemes (path traversal style attack)" in {
+ val result = OtelInit.validateEndpoint("file:///etc/passwd",
OtelInit.DefaultAllowedHosts)
+ result.isLeft shouldBe true
+ result.left.toOption.get should include("scheme")
+ }
+
+ it should "reject arbitrary remote hosts not in the allowlist" in {
+ val result = OtelInit.validateEndpoint(
+ "http://attacker.example.com:4317",
+ OtelInit.DefaultAllowedHosts
+ )
+ result.isLeft shouldBe true
+ result.left.toOption.get should include("host")
+ }
+
+ it should "accept hosts added to the allowlist" in {
+ val widened = OtelInit.DefaultAllowedHosts + "collector.internal"
+ OtelInit.validateEndpoint("http://collector.internal:4317", widened)
shouldBe Right(())
+ }
+
+ it should "reject endpoints with no scheme" in {
+ val result = OtelInit.validateEndpoint("localhost:4317",
OtelInit.DefaultAllowedHosts)
+ result.isLeft shouldBe true
+ }
+
+ it should "reject endpoints with no host" in {
+ val result = OtelInit.validateEndpoint("http:///path",
OtelInit.DefaultAllowedHosts)
+ result.isLeft shouldBe true
+ }
+
+ it should "reject completely malformed input" in {
+ val result = OtelInit.validateEndpoint("not a uri at all :: bad",
OtelInit.DefaultAllowedHosts)
+ result.isLeft shouldBe true
+ }
+
+ // ----- buildResource: passthrough with service.name protected ---------
+
+ "buildResource" should "always include the service.name from the argument"
in {
+ val r = OtelInit.buildResource("my-service", "")
+ Option(
+
r.getAttribute(io.opentelemetry.api.common.AttributeKey.stringKey("service.name"))
+ ) shouldBe Some(
+ "my-service"
+ )
+ }
+
+ it should "honor keys from OTEL_RESOURCE_ATTRIBUTES" in {
+ val r = OtelInit.buildResource("svc",
"service.version=1.2.3,deployment.environment=staging")
+ Option(
+
r.getAttribute(io.opentelemetry.api.common.AttributeKey.stringKey("service.version"))
+ ) shouldBe Some(
+ "1.2.3"
+ )
+ Option(
+
r.getAttribute(io.opentelemetry.api.common.AttributeKey.stringKey("deployment.environment"))
+ ) shouldBe Some("staging")
+ }
+
+ it should "pass custom keys through so new resource fields need no code
edit" in {
+ val r = OtelInit.buildResource(
+ "svc",
+ "service.version=1.0,custom.tag=team-a,texera.region.id=us-west"
+ )
+ val attrs: Map[String, String] =
r.getAttributes.asMap.asScala.iterator.map {
+ case (k, v) => k.getKey -> v.toString
+ }.toMap
+
+ attrs("service.version") shouldBe "1.0"
+ attrs("custom.tag") shouldBe "team-a"
+ attrs("texera.region.id") shouldBe "us-west"
+ }
+
+ it should "refuse to let OTEL_RESOURCE_ATTRIBUTES override service.name" in {
+ val r = OtelInit.buildResource("real-svc", "service.name=spoofed")
+ Option(
+
r.getAttribute(io.opentelemetry.api.common.AttributeKey.stringKey("service.name"))
+ ) shouldBe Some(
+ "real-svc"
+ )
+ }
+
+ it should "default a distinct service.instance.id per process so same-named
processes stay apart" in {
+ val key =
io.opentelemetry.api.common.AttributeKey.stringKey("service.instance.id")
+ val id1 = OtelInit.buildResource("computing-unit-master",
"").getAttribute(key)
+ val id2 = OtelInit.buildResource("computing-unit-master",
"").getAttribute(key)
+ id1 should not be null
+ id1 should not be id2
+ }
+
+ it should "let OTEL_RESOURCE_ATTRIBUTES override service.instance.id" in {
+ val r = OtelInit.buildResource("svc", "service.instance.id=cu-7")
+ Option(
+
r.getAttribute(io.opentelemetry.api.common.AttributeKey.stringKey("service.instance.id"))
+ ) shouldBe Some("cu-7")
+ }
+
+ it should "carry the texera.* resource attrs so a CU JVM auto-tags every
emitted record" in {
Review Comment:
**Polish:**
The body only checks that `buildResource` passes custom keys through.
Nothing in the tree sets `texera.computing_unit.id` or the workflow and
execution ids on a CU, and per-run ids cannot be resource attributes of a
long-lived JVM (see the `service.instance.id` thread on `OtelInit.scala`).
Naming it after what it checks avoids implying that mechanism exists.
```suggestion
it should "pass texera.* keys through as resource attributes" in {
```
--
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]