Skip to content

Commit

Permalink
Jfr streaming version (#721)
Browse files Browse the repository at this point in the history
Resolves #707. Builds on #716. 

Turns out this wasn't a good first issue because there was some gradle
buildSrc work needed to add a file with the version that the source code
could read. Lifted the source for this from
[opentelemetry-java](https://github.com/open-telemetry/opentelemetry-java/blob/main/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts#L144-L165).

---------

Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
jack-berg and trask authored Feb 2, 2023
1 parent e1e718c commit 6453d87
Show file tree
Hide file tree
Showing 70 changed files with 137 additions and 60 deletions.
1 change: 1 addition & 0 deletions aws-resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
}

description = "OpenTelemetry AWS Resources Support"
otelJava.moduleName.set("io.opentelemetry.contrib.aws.resource")

dependencies {
api("io.opentelemetry:opentelemetry-api")
Expand Down
1 change: 1 addition & 0 deletions aws-xray-propagator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
}

description = "OpenTelemetry AWS X-Ray Propagator"
otelJava.moduleName.set("io.opentelemetry.contrib.awsxray.propagator")

dependencies {
api("io.opentelemetry:opentelemetry-api")
Expand Down
1 change: 1 addition & 0 deletions aws-xray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "OpenTelemetry AWS X-Ray Support"
otelJava.moduleName.set("io.opentelemetry.contrib.awsxray")

dependencies {
api("io.opentelemetry:opentelemetry-api")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.gradle

import org.gradle.api.provider.Property

abstract class OtelJavaExtension {
abstract val moduleName: Property<String>
}
26 changes: 26 additions & 0 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io.opentelemetry.gradle.OtelJavaExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
Expand All @@ -8,6 +9,8 @@ plugins {
id("otel.spotless-conventions")
}

val otelJava = extensions.create<OtelJavaExtension>("otelJava")

group = "io.opentelemetry.contrib"

base.archivesName.set("opentelemetry-${project.name}")
Expand Down Expand Up @@ -86,6 +89,29 @@ tasks {
}
}

// Add version information to published artifacts.
plugins.withId("otel.publish-conventions") {
tasks {
register("generateVersionResource") {
val moduleName = otelJava.moduleName
val propertiesDir = moduleName.map { File(buildDir, "generated/properties/${it.replace('.', '/')}") }

inputs.property("project.version", project.version.toString())
outputs.dir(propertiesDir)

doLast {
File(propertiesDir.get(), "version.properties").writeText("contrib.version=${project.version}")
}
}
}

sourceSets {
main {
output.dir("$buildDir/generated/properties", "builtBy" to "generateVersionResource")
}
}
}

val dependencyManagement by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
Expand Down
1 change: 1 addition & 0 deletions consistent-sampling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "Sampler and exporter implementations for consistent sampling"
otelJava.moduleName.set("io.opentelemetry.contrib.sampler.consistent")

dependencies {
api("io.opentelemetry:opentelemetry-sdk-trace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import javax.annotation.concurrent.Immutable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import javax.annotation.concurrent.Immutable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import javax.annotation.concurrent.Immutable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static io.opentelemetry.api.internal.Utils.checkArgument;
import static java.util.Objects.requireNonNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import java.util.ArrayList;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

/**
* A function for generating r-values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

final class RValueGenerators {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static java.util.Objects.requireNonNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static io.opentelemetry.contrib.samplers.ConsistentReservoirSamplingSpanProcessor.DEFAULT_EXPORT_TIMEOUT_NANOS;
import static io.opentelemetry.contrib.util.TestUtil.verifyObservedPvaluesUsingGtest;
import static io.opentelemetry.contrib.sampler.consistent.ConsistentReservoirSamplingSpanProcessor.DEFAULT_EXPORT_TIMEOUT_NANOS;
import static io.opentelemetry.contrib.sampler.consistent.TestUtil.verifyObservedPvaluesUsingGtest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static io.opentelemetry.contrib.samplers.OtelTraceState.getInvalidP;
import static io.opentelemetry.contrib.samplers.OtelTraceState.getInvalidR;
import static io.opentelemetry.contrib.sampler.consistent.OtelTraceState.getInvalidP;
import static io.opentelemetry.contrib.sampler.consistent.OtelTraceState.getInvalidR;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.samplers;
package io.opentelemetry.contrib.sampler.consistent;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.util;
package io.opentelemetry.contrib.sampler.consistent;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
1 change: 1 addition & 0 deletions jfr-events/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "OpenTelemetry JFR Events"
otelJava.moduleName.set("io.opentelemetry.contrib.jfrevent")

dependencies {
implementation("io.opentelemetry:opentelemetry-sdk")
Expand Down
3 changes: 3 additions & 0 deletions jfr-streaming/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ plugins {
id("otel.publish-conventions")
}

description = "OpenTelemetry JFR Streaming"
otelJava.moduleName.set("io.opentelemetry.contrib.jfr.streaming")

// Disable publishing test fixtures
val javaComponent = components["java"] as AdhocComponentWithVariants
javaComponent.withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.function.Predicate;

final class HandlerRegistry {
private static final String SCOPE_NAME = "io.opentelemetry.contrib.jfr";
// TODO(jack-berg): read from version.properties
private static final String SCOPE_VERSION = "1.22.0-SNAPSHOT";
private static final String SCOPE_NAME = "io.opentelemetry.contrib.jfr.streaming";
private static final String SCOPE_VERSION = readVersion();

private HandlerRegistry() {}

Expand Down Expand Up @@ -113,4 +113,15 @@ static List<RecordedEventHandler> getHandlers(

return handlers;
}

private static String readVersion() {
Properties properties = new Properties();
try {
properties.load(HandlerRegistry.class.getResourceAsStream("version.properties"));
} catch (Exception e) {
// we left the attribute empty
return "unknown";
}
return properties.getProperty("contrib.version", "unknown");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

package io.opentelemetry.contrib.jfr.streaming;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;

import io.github.netmikey.logunit.api.LogCapturer;
import io.opentelemetry.sdk.OpenTelemetrySdk;
Expand Down Expand Up @@ -45,7 +44,16 @@ void create_Default() {
assertThat(logs.getEvents()).hasSize(1);
logs.assertContains("Starting JfrTelemetry");

await().untilAsserted(() -> assertThat(reader.collectAllMetrics()).isNotEmpty());
assertThat(reader.collectAllMetrics())
.isNotEmpty()
.allSatisfy(
metric -> {
assertThat(metric.getInstrumentationScopeInfo().getName())
.isEqualTo("io.opentelemetry.contrib.jfr.streaming");
assertThat(metric.getInstrumentationScopeInfo().getVersion())
.matches("1\\..*-alpha.*");
});
;
}
}

Expand Down
1 change: 1 addition & 0 deletions jmx-metrics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
}

description = "JMX metrics gathering Groovy script runner"
otelJava.moduleName.set("io.opentelemetry.contrib.jmxmetrics")

application.mainClass.set("io.opentelemetry.contrib.jmxmetrics.JmxMetrics")

Expand Down
1 change: 1 addition & 0 deletions maven-extension/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
// equivalent to the Maven plugin `plexus-component-metadata:generate-metadata`

description = "Maven extension to observe Maven builds with distributed traces using OpenTelemetry SDK"
otelJava.moduleName.set("io.opentelemetry.maven")

dependencies {
implementation("org.codehaus.plexus:plexus-component-annotations:2.1.1")
Expand Down
1 change: 1 addition & 0 deletions micrometer-meter-provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "OpenTelemetry Micrometer MeterProvider"
otelJava.moduleName.set("io.opentelemetry.contrib.metrics.micrometer")

dependencies {
api("io.opentelemetry:opentelemetry-api")
Expand Down
1 change: 1 addition & 0 deletions noop-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "OpenTelemetry Noop API"
otelJava.moduleName.set("io.opentelemetry.contrib.noopapi")

dependencies {
api("io.opentelemetry:opentelemetry-api")
Expand Down
1 change: 1 addition & 0 deletions prometheus-client-bridge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

description = "Prometheus client bridge"
otelJava.moduleName.set("io.opentelemetry.contrib.metrics.prometheus.clientbridge")

dependencies {
api("io.opentelemetry:opentelemetry-sdk-metrics")
Expand Down
Loading

0 comments on commit 6453d87

Please sign in to comment.