From b578483e55dd3fe40d59d692f84b8396f001217e Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 30 Nov 2023 14:14:37 +0530 Subject: [PATCH 01/16] Update opentelemetry version --- ballerina/build.gradle | 327 ++++++++++++++++++ gradle.properties | 42 +-- native/build.gradle | 111 ++++++ .../trace/jaeger/JaegerTracerProvider.java | 116 +++++++ .../trace/jaeger/sampler/RateLimiter.java | 47 +++ .../jaeger/sampler/RateLimitingSampler.java | 83 +++++ native/src/main/java/module-info.java | 15 + 7 files changed, 721 insertions(+), 20 deletions(-) create mode 100644 ballerina/build.gradle create mode 100644 native/build.gradle create mode 100644 native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java create mode 100644 native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java create mode 100644 native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java create mode 100644 native/src/main/java/module-info.java diff --git a/ballerina/build.gradle b/ballerina/build.gradle new file mode 100644 index 0000000..1e0e1c1 --- /dev/null +++ b/ballerina/build.gradle @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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. + */ + +import org.apache.tools.ant.taskdefs.condition.Os + +description = 'Ballerina - Jaeger Extension - Ballerina Module' + +configurations { + nativeJar { + transitive false + } + externalJars { + transitive false + } + distribution { + canBeConsumed true + canBeResolved false + } +} + +dependencies { + nativeJar project(':jaeger-extension-native') + + externalJars "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" + externalJars "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" + externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" + externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" + externalJars "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}" + externalJars "io.opentelemetry:opentelemetry-proto:${openTelemetryProtoVersion}" + externalJars "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryExporterVersion}" + externalJars "io.opentelemetry:opentelemetry-exporter-otlp-common:${openTelemetryExporterVersion}" + externalJars "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" + externalJars "com.google.guava:guava:${guavaVersion}" + externalJars "com.google.guava:failureaccess:${failureAccessVersion}" + externalJars "io.grpc:grpc-api:${grpcVersion}" + externalJars "io.grpc:grpc-context:${grpcVersion}" + externalJars "io.grpc:grpc-core:${grpcVersion}" + externalJars "io.grpc:grpc-stub:${grpcVersion}" + externalJars "io.grpc:grpc-protobuf:${grpcVersion}" + externalJars "io.grpc:grpc-protobuf-lite:${grpcVersion}" + externalJars "io.grpc:grpc-netty-shaded:${grpcVersion}" + externalJars "com.google.protobuf:protobuf-java:${protobufVersion}" + externalJars "io.netty:netty-handler:${nettyVersion}" + externalJars "io.perfmark:perfmark-api:${perfmarkVersion}" +} + +clean { + delete "${project.projectDir}/target" + delete "${project.projectDir}/Ballerina.lock" + delete "${project.projectDir}/ballerina-internal.log" +} + +jar { + manifest { + attributes('Implementation-Title': project.name, 'Implementation-Version': project.version) + } +} + +task unpackJballerinaTools(type: Copy, dependsOn: configurations.jbalTools) { + configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact -> + from zipTree(artifact.getFile()) + into new File("${buildDir}/extracted-distributions", "jballerina-tools-zip") + } +} + +task unpackStdLibs(dependsOn: configurations.ballerinaStdLibs) { + doLast { + configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> + copy { + from project.zipTree(artifact.getFile()) + into new File("${buildDir}/extracted-distributions", artifact.name + "-zip") + } + } + } +} + +task copyExternalJarsToLib(type: Copy) { + into "${project.projectDir}/lib" + from configurations.externalJars +} + +task copyStdlibs(type: Copy) { + dependsOn unpackJballerinaTools + dependsOn unpackStdLibs + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + into "${project.buildDir}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}" + + /* Standard Libraries */ + configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> + def artifactExtractedPath = "${buildDir}/extracted-distributions/" + artifact.name + "-zip" + into("repo/bala") { + from "${artifactExtractedPath}/bala" + } + into("repo/cache") { + from "${artifactExtractedPath}/cache" + } + } +} + +def packageOrg = "ballerinax" +def packageName = "jaeger" +def ballerinaConfigFile = new File("${project.projectDir}/Ballerina.toml") +def ballerinaDependencyFile = new File("$project.projectDir/Dependencies.toml") +def artifactBallerinaDocs = file("${project.projectDir}/build/docs_parent/") +def artifactCacheParent = file("${project.buildDir}/cache_parent/") +def artifactLibParent = file("${project.buildDir}/lib_parent/") +def snapshotVersion = "-SNAPSHOT" +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaCentralAccessToken = System.getenv('BALLERINA_CENTRAL_ACCESS_TOKEN') +def originalConfig = ballerinaConfigFile.text +def originalDependencyConfig = ballerinaDependencyFile.text +def artifactJar = file("$project.projectDir/target/cache/${packageOrg}/${packageName}/${tomlVersion}/java17/") +def platform = "java17" +def distributionBinPath = "${project.buildDir.absolutePath}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}/bin" + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-'); + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +task updateTomlVerions { + doLast { + def stdlibDependentIoVersion = stripBallerinaExtensionVersion(project.stdlibIoVersion) + def openTelemetryVersion = project.openTelemetryVersion + def openTelemetrySDKVersion = project.openTelemetrySDKVersion + def openTelemetryExporterVersion = project.openTelemetryExporterVersion + def openTelemetrySemconvVersion = project.openTelemetrySemconvVersion + def openTelemetryProtoVersion = project.openTelemetryProtoVersion + def guavaVersion = project.guavaVersion + def failureAccessVersion = project.failureAccessVersion + def grpcVersion = project.grpcVersion + def nettyVersion = project.nettyVersion + def protobufVersion = project.protobufVersion + def perfmarkVersion = project.perfmarkVersion + + def newConfig = ballerinaConfigFile.text.replace("@project.version@", project.version) + newConfig = newConfig.replace("@toml.version@", tomlVersion) + newConfig = newConfig.replace("@opentelemetry.version@", openTelemetryVersion) + newConfig = newConfig.replace("@opentelemetrySDK.version@", openTelemetrySDKVersion) + newConfig = newConfig.replace("@opentelemetryExporter.version@", openTelemetryExporterVersion) + newConfig = newConfig.replace("@opentelemetrySemconv.version@", openTelemetrySemconvVersion) + newConfig = newConfig.replace("@opentelemetryProto.version@", openTelemetryProtoVersion) + newConfig = newConfig.replace("@guava.version@", guavaVersion) + newConfig = newConfig.replace("@failureAccess.version@", failureAccessVersion) + newConfig = newConfig.replace("@grpc.version@", grpcVersion) + newConfig = newConfig.replace("@netty.version@", nettyVersion) + newConfig = newConfig.replace("@protobuf.version@", protobufVersion) + newConfig = newConfig.replace("@perfmark.version@", perfmarkVersion) + ballerinaConfigFile.text = newConfig + + def newDependencyConfig = ballerinaDependencyFile.text.replace("@stdlib.io.version@", stdlibDependentIoVersion) + ballerinaDependencyFile.text = newDependencyConfig + } +} + +task revertTomlFile { + doLast { + ballerinaConfigFile.text = originalConfig + ballerinaDependencyFile.text = originalDependencyConfig + } +} + +task ballerinaBuild { + dependsOn copyExternalJarsToLib + dependsOn copyStdlibs + dependsOn updateTomlVerions + dependsOn configurations.nativeJar + dependsOn configurations.externalJars + dependsOn compileJava + dependsOn compileTestJava + dependsOn jar + dependsOn checkstyleMain + dependsOn checkstyleTest + dependsOn spotbugsMain + dependsOn spotbugsTest + dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" + + inputs.dir file(project.projectDir) + finalizedBy(revertTomlFile) + + doLast { + def additionalBuildParams = "" + if (project.hasProperty("debug")) { + additionalBuildParams = "--debug ${project.findProperty("debug")}" + } + + exec { + workingDir project.projectDir + environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat pack --offline ${additionalBuildParams} && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "${distributionBinPath}/bal pack --offline ${additionalBuildParams}" + } + } + // extract bala file to artifact cache directory + file("${project.projectDir}/target/bala").eachFileMatch(~/.*.bala/) { balaFile -> + copy { + from zipTree(balaFile) + into file("$artifactCacheParent/bala/${packageOrg}/${packageName}/${tomlVersion}/${platform}") + } + } + copy { + from file("${project.projectDir}/target/cache") + exclude '**/*-testable.jar' + exclude '**/tests_cache/' + into file("$artifactCacheParent/cache/") + } + + // Doc creation and packing + exec { + workingDir project.projectDir + environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "$distributionBinPath/bal.bat doc && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "$distributionBinPath/bal doc" + } + } + copy { + from file("$project.projectDir/target/apidocs/${packageName}") + into file("$project.buildDir/docs_parent/docs/${packageName}") + } + } + + outputs.dir artifactCacheParent + outputs.dir artifactBallerinaDocs + outputs.dir artifactLibParent +} + +task createArtifactZip(type: Zip) { + destinationDirectory = file("${project.buildDir}/distributions") + from ballerinaBuild +} + +artifacts { + distribution createArtifactZip +} + +task ballerinaPublish { + dependsOn updateTomlVerions + dependsOn ballerinaBuild + dependsOn ":${packageName}-extension-tests:test" + dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" + + finalizedBy(revertTomlFile) + + doLast { + if (project.version.endsWith('-SNAPSHOT')) { + return + } + if (ballerinaCentralAccessToken != null) { + println("Publishing to the ballerina central...") + exec { + workingDir project.projectDir + environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "$distributionBinPath/bal push" + } + } + } else { + throw new InvalidUserDataException("Central Access Token is not present") + } + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifact source: createArtifactZip, extension: 'zip' + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/${System.getenv("packagePublishRepo")}") + credentials { + username = System.getenv("packageUser") + password = System.getenv("packagePAT") + } + } + } +} + +build { + dependsOn ballerinaBuild +} + +publish { + dependsOn ballerinaPublish +} + +task extractBallerinaClassFiles(type: Copy) { + fileTree(artifactJar).forEach { file -> + from zipTree(file).matching { + exclude '**/tests/*' + include '**/*.class' + } + into "${project.rootDir.absolutePath}/build/classes" + } +} diff --git a/gradle.properties b/gradle.properties index 66c51ee..0d85b58 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,17 +13,19 @@ # limitations under the License. group=org.ballerinalang -version=0.4.0-SNAPSHOT -ballerinaLangVersion=2201.8.2 +version=0.5.0-SNAPSHOT +ballerinaLangVersion=2201.9.0-SNAPSHOT org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.workers.max=3 # Native Dependency Versions -jaegerVersion=1.8.1 -openTelemetryVersion=1.0.0 -openTelemetryAlphaVersion=1.0.0-alpha +openTelemetryVersion=1.32.0 +openTelemetryExporterVersion=1.14.0 +openTelemetrySDKVersion=1.32.0 +openTelemetrySemconvVersion=1.21.0-alpha +openTelemetryProtoVersion=1.7.1-alpha guavaVersion=30.1-jre failureAccessVersion=1.0.1 grpcVersion=1.35.0 @@ -36,22 +38,22 @@ observeVersion=1.0.2 observeInternalVersion=1.0.2 # Test Module Dependecy Versions -stdlibHttpVersion=2.2.1 -stdlibIoVersion=1.2.1 +stdlibHttpVersion=2.10.4 +stdlibIoVersion=1.6.0 stdlibRegexVersion=1.2.1 -stdlibOsVersion=1.2.1 -stdlibTimeVersion=2.2.1 -stdlibUrlVersion=2.2.1 -stdlibTaskVersion=2.2.1 -stdlibFileVersion=1.2.1 -stdlibCryptoVersion=2.2.1 -stdlibLogVersion=2.8.1-20230718-085900-36c385c -stdlibMimeVersion=2.2.1 -stdlibCacheVersion=3.2.1 -stdlibAuthVersion=2.2.1 -stdlibJwtVersion=2.2.1 -stdlibOAuth2Version=2.2.1 -stdlibUuidVersion=1.2.1 +stdlibOsVersion=1.8.0 +stdlibTimeVersion=2.4.0 +stdlibUrlVersion=2.4.0 +stdlibTaskVersion=2.5.0 +stdlibFileVersion=1.9.0 +stdlibCryptoVersion=2.5.0 +stdlibLogVersion=2.9.0 +stdlibMimeVersion=2.9.0 +stdlibCacheVersion=3.7.0 +stdlibAuthVersion=2.10.0 +stdlibJwtVersion=2.10.0 +stdlibOAuth2Version=2.10.0 +stdlibUuidVersion=1.7.0 # Test Dependency Versions testngVersion=7.6.1 diff --git a/native/build.gradle b/native/build.gradle new file mode 100644 index 0000000..5783ca0 --- /dev/null +++ b/native/build.gradle @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed 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. + */ + +plugins { + id 'java-library' +} + +description = 'Ballerina - Jaeger Extension - Native Module' + +dependencies { + implementation "org.ballerinalang:ballerina-runtime:${ballerinaLangVersion}" + implementation "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" + implementation "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" + implementation "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetrySDKVersion}" + implementation "io.opentelemetry:opentelemetry-sdk-common:${openTelemetrySDKVersion}" + implementation "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}" + implementation "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryExporterVersion}" + implementation "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" + implementation "io.opentelemetry:opentelemetry-sdk-extension-jaeger-remote-sampler:${openTelemetrySDKVersion}" + + implementation("com.google.guava:guava:${guavaVersion}") { + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("com.google.guava:failureaccess:${failureAccessVersion}") + implementation("io.grpc:grpc-api:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("io.grpc:grpc-core:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("io.grpc:grpc-stub:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("io.grpc:grpc-protobuf:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("io.grpc:grpc-protobuf-lite:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation("io.grpc:grpc-netty-shaded:${grpcVersion}") { + exclude group: 'io.grpc', module: 'grpc-context' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + } + implementation "com.google.protobuf:protobuf-java:${protobufVersion}" + implementation("io.netty:netty-handler:${nettyVersion}") + implementation "io.perfmark:perfmark-api:${perfmarkVersion}" +} + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} + +jar { + manifest { + attributes('Implementation-Title': project.name, 'Implementation-Version': project.version) + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId project.group + artifactId "jaeger-extension-native" + version = project.version + artifact jar + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/${System.getenv("packagePublishRepo")}") + credentials { + username = System.getenv("packageUser") + password = System.getenv("packagePAT") + } + } + } +} + +task copyJavaClassFiles(type: Copy) { + dependsOn(compileJava) + from("${project.buildDir}/classes") { + exclude '**/module-info.class' + include '**/*.class' + } + into "${project.rootDir.absolutePath}/build/classes" +} diff --git a/native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java b/native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java new file mode 100644 index 0000000..23345fd --- /dev/null +++ b/native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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 io.ballerina.observe.trace.jaeger; + +import io.ballerina.observe.trace.jaeger.sampler.RateLimitingSampler; +import io.ballerina.runtime.api.values.BDecimal; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.observability.tracer.spi.TracerProvider; +import io.grpc.ManagedChannel; +import io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.extension.trace.propagation.JaegerPropagator; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.samplers.Sampler; + +import java.io.PrintStream; +import java.util.concurrent.TimeUnit; + +import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME; + +/** + * This is the Jaeger tracing extension class for {@link TracerProvider}. + */ +public class JaegerTracerProvider implements TracerProvider { + private static final String TRACER_NAME = "jaeger"; + private static final PrintStream console = System.out; + + static SdkTracerProviderBuilder tracerProviderBuilder; + + @Override + public String getName() { + return TRACER_NAME; + } + + @Override + public void init() { // Do Nothing + } + + public static void initializeConfigurations(BString agentHostname, int agentPort, BString samplerType, + BDecimal samplerParam, int reporterFlushInterval, + int reporterBufferSize) { + + String reporterEndpoint = agentHostname + ":" + agentPort; + + ManagedChannel jaegerChannel = new NettyChannelProvider() + .builderForTarget(reporterEndpoint) + .usePlaintext() + .build(); + + OtlpGrpcSpanExporter exporter = OtlpGrpcSpanExporter.builder() + .setChannel(jaegerChannel) + .build(); + + tracerProviderBuilder = SdkTracerProvider.builder() + .addSpanProcessor(BatchSpanProcessor + .builder(exporter) + .setMaxExportBatchSize(reporterBufferSize) + .setExporterTimeout(reporterFlushInterval, TimeUnit.MILLISECONDS) + .build()); + + tracerProviderBuilder.setSampler(selectSampler(samplerType, samplerParam)); + + console.println("ballerina: started publishing traces to Jaeger on " + reporterEndpoint); + } + + private static Sampler selectSampler(BString samplerType, BDecimal samplerParam) { + switch (samplerType.getValue()) { + default: + case "const": + if (samplerParam.value().intValue() == 0) { + return Sampler.alwaysOff(); + } else { + return Sampler.alwaysOn(); + } + case "probabilistic": + return Sampler.traceIdRatioBased(samplerParam.value().doubleValue()); + case RateLimitingSampler.TYPE: + return new RateLimitingSampler(samplerParam.value().intValue()); + } + } + + @Override + public Tracer getTracer(String serviceName) { + + return tracerProviderBuilder.setResource( + Resource.create(Attributes.of(SERVICE_NAME, serviceName))) + .build().get("jaeger"); + } + + @Override + public ContextPropagators getPropagators() { + + return ContextPropagators.create(JaegerPropagator.getInstance()); + } +} diff --git a/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java b/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java new file mode 100644 index 0000000..0f5ea15 --- /dev/null +++ b/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java @@ -0,0 +1,47 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package io.ballerina.observe.trace.jaeger.sampler; + +import io.opentelemetry.sdk.common.Clock; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.0.0/sdk-extensions/ + * jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/RateLimiter.java. + */ +class RateLimiter { + private final Clock clock; + private final double creditsPerNanosecond; + private final long maxBalance; // max balance in nano ticks + private final AtomicLong debit; // last op nano time less remaining balance + + RateLimiter(double creditsPerSecond, double maxBalance, Clock clock) { + this.clock = clock; + this.creditsPerNanosecond = creditsPerSecond / 1.0e9; + this.maxBalance = (long) (maxBalance / creditsPerNanosecond); + this.debit = new AtomicLong(clock.nanoTime() - this.maxBalance); + } + + public boolean checkCredit(double itemCost) { + long cost = (long) (itemCost / creditsPerNanosecond); + long credit; + long currentDebit; + long balance; + do { + currentDebit = debit.get(); + credit = clock.nanoTime(); + balance = credit - currentDebit; + if (balance > maxBalance) { + balance = maxBalance; + } + balance -= cost; + if (balance < 0) { + return false; + } + } while (!debit.compareAndSet(currentDebit, credit - balance)); + return true; + } +} diff --git a/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java b/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java new file mode 100644 index 0000000..c93d2aa --- /dev/null +++ b/native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java @@ -0,0 +1,83 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package io.ballerina.observe.trace.jaeger.sampler; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.internal.RateLimiter; +import io.opentelemetry.sdk.trace.data.LinkData; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.sdk.trace.samplers.SamplingDecision; +import io.opentelemetry.sdk.trace.samplers.SamplingResult; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.List; + +import static io.opentelemetry.api.common.AttributeKey.doubleKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +/** + * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.32.0/sdk-extensions/ + * jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/RateLimitingSampler.java. + * This sampler uses a leaky bucket rate limiter to ensure that traces are sampled with a certain constant rate. + */ +public class RateLimitingSampler implements Sampler { + public static final String TYPE = "ratelimiting"; + static final AttributeKey SAMPLER_TYPE = stringKey("sampler.type"); + static final AttributeKey SAMPLER_PARAM = doubleKey("sampler.param"); + + private final RateLimiter rateLimiter; + private final SamplingResult onSamplingResult; + private final SamplingResult offSamplingResult; + private final String description; + + /** + * Creates rate limiting sampler. + * + * @param maxTracesPerSecond the maximum number of sampled traces per second. + */ + public RateLimitingSampler(int maxTracesPerSecond) { + double maxBalance = maxTracesPerSecond < 1.0 ? 1.0 : maxTracesPerSecond; + this.rateLimiter = new RateLimiter(maxTracesPerSecond, maxBalance, Clock.getDefault()); + Attributes attributes = + Attributes.of(SAMPLER_TYPE, TYPE, SAMPLER_PARAM, (double) maxTracesPerSecond); + this.onSamplingResult = SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE, attributes); + this.offSamplingResult = SamplingResult.create(SamplingDecision.DROP, attributes); + description = "RateLimitingSampler{" + decimalFormat(maxTracesPerSecond) + "}"; + } + + @Override + public SamplingResult shouldSample( + Context parentContext, + String traceId, + String name, + SpanKind spanKind, + Attributes attributes, + List parentLinks) { + return this.rateLimiter.trySpend(1.0) ? onSamplingResult : offSamplingResult; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String toString() { + return getDescription(); + } + + private static String decimalFormat(double value) { + DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); + decimalFormatSymbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("0.00", decimalFormatSymbols); + return decimalFormat.format(value); + } +} diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java new file mode 100644 index 0000000..b2a70c4 --- /dev/null +++ b/native/src/main/java/module-info.java @@ -0,0 +1,15 @@ +module io.ballerina.observe.trace.extension.jaeger { + requires io.ballerina.runtime; + requires io.opentelemetry.api; + requires io.opentelemetry.context; + requires io.opentelemetry.sdk.trace; + requires io.opentelemetry.sdk.common; + requires io.opentelemetry.extension.trace.propagation; + requires io.opentelemetry.semconv; + requires io.opentelemetry.exporter.otlp.trace; + requires grpc.api; + requires grpc.netty.shaded; + + provides io.ballerina.runtime.observability.tracer.spi.TracerProvider + with io.ballerina.observe.trace.jaeger.JaegerTracerProvider; +} From 9a62469c29dd6c6d0af5c7088cae42918fafa086 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 30 Nov 2023 14:21:36 +0530 Subject: [PATCH 02/16] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 12a2c2c..a2ec420 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ build/ gradle-app.setting !gradle-wrapper.jar .gradletasknamecache +.DS_Store # Ballerina target/ From 513c367653e962090574030b99baf0aa8cd36292 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 30 Nov 2023 15:03:56 +0530 Subject: [PATCH 03/16] Refractor module --- .../Ballerina.toml | 38 +- ballerina/Dependencies.toml | 62 ++++ .../Package.md | 0 ballerina/build.gradle | 120 ++----- .../tracer_provider.bal | 0 build.gradle | 48 +-- gradle.properties | 22 -- jaeger-extension-ballerina/Dependencies.toml | 20 -- jaeger-extension-ballerina/build.gradle | 326 ------------------ jaeger-extension-native/build.gradle | 112 ------ .../trace/jaeger/JaegerTracerProvider.java | 116 ------- .../trace/jaeger/sampler/RateLimiter.java | 47 --- .../jaeger/sampler/RateLimitingSampler.java | 70 ---- .../src/main/java/module-info.java | 17 - native/build.gradle | 1 - .../native-image.properties | 0 .../reflect-config.json | 0 .../resource-config.json | 0 ...me.observability.tracer.spi.TracerProvider | 0 settings.gradle | 6 +- .../build.gradle | 0 .../spotbugs-test-exclude.xml | 0 .../observe/trace/jaeger/BaseTestCase.java | 0 .../trace/jaeger/JaegerTracesTestCase.java | 0 .../jaeger/backend/ContainerLogReader.java | 0 .../backend/ContainerizedJaegerServer.java | 0 .../trace/jaeger/backend/JaegerServer.java | 0 .../jaeger/backend/JaegerServerProtocol.java | 0 .../jaeger/backend/ProcessJaegerServer.java | 0 .../jaeger/backend/ProcessLogReader.java | 0 .../trace/jaeger/model/JaegerProcess.java | 0 .../jaeger/model/JaegerQueryResponse.java | 0 .../model/JaegerQueryResponseTypeToken.java | 0 .../trace/jaeger/model/JaegerSpan.java | 0 .../jaeger/model/JaegerSpanReference.java | 0 .../observe/trace/jaeger/model/JaegerTag.java | 0 .../trace/jaeger/model/JaegerTrace.java | 0 .../test/resources/bal/01_http_svc_test.bal | 0 .../src/test/resources/bal/ConfigAgent.toml | 0 .../src/test/resources/bal/ConfigDefault.toml | 0 .../resources/bal/ConfigInvalidProvider.toml | 0 .../resources/bal/ConfigInvalidSampler.toml | 0 .../resources/bal/ConfigSamplerConst.toml | 0 .../bal/ConfigSamplerProbabilistic.toml | 0 .../bal/ConfigSamplerRatelimiting.toml | 0 .../src/test/resources/logging.properties | 0 .../src/test/resources/testng.xml | 0 47 files changed, 135 insertions(+), 870 deletions(-) rename {jaeger-extension-ballerina => ballerina}/Ballerina.toml (76%) create mode 100644 ballerina/Dependencies.toml rename {jaeger-extension-ballerina => ballerina}/Package.md (100%) rename {jaeger-extension-ballerina => ballerina}/tracer_provider.bal (100%) delete mode 100644 jaeger-extension-ballerina/Dependencies.toml delete mode 100644 jaeger-extension-ballerina/build.gradle delete mode 100644 jaeger-extension-native/build.gradle delete mode 100644 jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java delete mode 100644 jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java delete mode 100644 jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java delete mode 100644 jaeger-extension-native/src/main/java/module-info.java rename {jaeger-extension-native => native}/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/native-image.properties (100%) rename {jaeger-extension-native => native}/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/reflect-config.json (100%) rename {jaeger-extension-native => native}/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/resource-config.json (100%) rename {jaeger-extension-native => native}/src/main/resources/META-INF/services/io.ballerina.runtime.observability.tracer.spi.TracerProvider (100%) rename {jaeger-extension-tests => tests}/build.gradle (100%) rename {jaeger-extension-tests => tests}/spotbugs-test-exclude.xml (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/BaseTestCase.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/JaegerTracesTestCase.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerLogReader.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerizedJaegerServer.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServer.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServerProtocol.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessJaegerServer.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessLogReader.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerProcess.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponse.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponseTypeToken.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpan.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpanReference.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTag.java (100%) rename {jaeger-extension-tests => tests}/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTrace.java (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/01_http_svc_test.bal (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigAgent.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigDefault.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigInvalidProvider.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigInvalidSampler.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigSamplerConst.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigSamplerProbabilistic.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/bal/ConfigSamplerRatelimiting.toml (100%) rename {jaeger-extension-tests => tests}/src/test/resources/logging.properties (100%) rename {jaeger-extension-tests => tests}/src/test/resources/testng.xml (100%) diff --git a/jaeger-extension-ballerina/Ballerina.toml b/ballerina/Ballerina.toml similarity index 76% rename from jaeger-extension-ballerina/Ballerina.toml rename to ballerina/Ballerina.toml index c574e64..875045a 100644 --- a/jaeger-extension-ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -24,58 +24,46 @@ distribution = "2201.7.0" graalvmCompatible = true [[platform.java17.dependency]] -path = "../jaeger-extension-native/build/libs/jaeger-extension-native-@project.version@.jar" +path = "../native/build/libs/jaeger-extension-native-@project.version@.jar" groupId = "ballerina" artifactId = "jaeger-extension-native" version = "@project.version@" [[platform.java17.dependency]] -path = "./lib/jaeger-core-@jaeger.version@.jar" -groupId = "io.jaegertracing" -artifactId = "jaeger-core" -version = "@jaeger.version@" - -[[platform.java17.dependency]] -path = "./lib/opentelemetry-api-metrics-@openTelemetryAlpha.version@.jar" -groupId = "io.opentelemetry" -artifactId = "opentelemetry-api-metrics" -version = "@openTelemetryAlpha.version@" - -[[platform.java17.dependency]] -path = "./lib/opentelemetry-sdk-trace-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-sdk-trace-@opentelemetrySDK.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-sdk-trace" -version = "@opentelemetry.version@" +version = "@opentelemetrySDK.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-sdk-common-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-sdk-common-@opentelemetrySDK.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-sdk-common" -version = "@opentelemetry.version@" +version = "@opentelemetrySDK.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-semconv-@openTelemetryAlpha.version@.jar" +path = "./lib/opentelemetry-semconv-@opentelemetrySemconv.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-semconv" -version = "@openTelemetryAlpha.version@" +version = "@opentelemetrySemconv.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-proto-@openTelemetryAlpha.version@.jar" +path = "./lib/opentelemetry-proto-@opentelemetryProto.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-proto" -version = "@openTelemetryAlpha.version@" +version = "@opentelemetryProto.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-exporter-otlp-trace-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-exporter-otlp-trace-@opentelemetryExporter.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-exporter-otlp-trace" -version = "@opentelemetry.version@" +version = "@opentelemetryExporter.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-exporter-otlp-common-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-exporter-otlp-common-@opentelemetryExporter.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-exporter-otlp-common" -version = "@opentelemetry.version@" +version = "@opentelemetryExporter.version@" [[platform.java17.dependency]] path = "./lib/opentelemetry-extension-trace-propagators-@opentelemetry.version@.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml new file mode 100644 index 0000000..b12fb99 --- /dev/null +++ b/ballerina/Dependencies.toml @@ -0,0 +1,62 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.3" + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "observe", moduleName = "observe"}, + {org = "ballerina", packageName = "observe", moduleName = "observe.mockextension"} +] + +[[package]] +org = "ballerinax" +name = "jaeger" +version = "0.5.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinax", packageName = "jaeger", moduleName = "jaeger"} +] + diff --git a/jaeger-extension-ballerina/Package.md b/ballerina/Package.md similarity index 100% rename from jaeger-extension-ballerina/Package.md rename to ballerina/Package.md diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 1e0e1c1..5b1421c 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -34,7 +34,6 @@ configurations { dependencies { nativeJar project(':jaeger-extension-native') - externalJars "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" @@ -69,63 +68,23 @@ jar { } } -task unpackJballerinaTools(type: Copy, dependsOn: configurations.jbalTools) { - configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact -> - from zipTree(artifact.getFile()) - into new File("${buildDir}/extracted-distributions", "jballerina-tools-zip") - } -} - -task unpackStdLibs(dependsOn: configurations.ballerinaStdLibs) { - doLast { - configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> - copy { - from project.zipTree(artifact.getFile()) - into new File("${buildDir}/extracted-distributions", artifact.name + "-zip") - } - } - } -} - task copyExternalJarsToLib(type: Copy) { into "${project.projectDir}/lib" from configurations.externalJars } -task copyStdlibs(type: Copy) { - dependsOn unpackJballerinaTools - dependsOn unpackStdLibs - - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - into "${project.buildDir}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}" - - /* Standard Libraries */ - configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> - def artifactExtractedPath = "${buildDir}/extracted-distributions/" + artifact.name + "-zip" - into("repo/bala") { - from "${artifactExtractedPath}/bala" - } - into("repo/cache") { - from "${artifactExtractedPath}/cache" - } - } -} - def packageOrg = "ballerinax" def packageName = "jaeger" def ballerinaConfigFile = new File("${project.projectDir}/Ballerina.toml") -def ballerinaDependencyFile = new File("$project.projectDir/Dependencies.toml") def artifactBallerinaDocs = file("${project.projectDir}/build/docs_parent/") def artifactCacheParent = file("${project.buildDir}/cache_parent/") def artifactLibParent = file("${project.buildDir}/lib_parent/") -def snapshotVersion = "-SNAPSHOT" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") def ballerinaCentralAccessToken = System.getenv('BALLERINA_CENTRAL_ACCESS_TOKEN') def originalConfig = ballerinaConfigFile.text -def originalDependencyConfig = ballerinaDependencyFile.text def artifactJar = file("$project.projectDir/target/cache/${packageOrg}/${packageName}/${tomlVersion}/java17/") def platform = "java17" -def distributionBinPath = "${project.buildDir.absolutePath}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}/bin" +def skipTests = false def stripBallerinaExtensionVersion(String extVersion) { if (extVersion.matches(project.ext.timestampedVersionRegex)) { @@ -141,9 +100,8 @@ def stripBallerinaExtensionVersion(String extVersion) { } } -task updateTomlVerions { +task updateTomlVersions { doLast { - def stdlibDependentIoVersion = stripBallerinaExtensionVersion(project.stdlibIoVersion) def openTelemetryVersion = project.openTelemetryVersion def openTelemetrySDKVersion = project.openTelemetrySDKVersion def openTelemetryExporterVersion = project.openTelemetryExporterVersion @@ -170,25 +128,20 @@ task updateTomlVerions { newConfig = newConfig.replace("@protobuf.version@", protobufVersion) newConfig = newConfig.replace("@perfmark.version@", perfmarkVersion) ballerinaConfigFile.text = newConfig - - def newDependencyConfig = ballerinaDependencyFile.text.replace("@stdlib.io.version@", stdlibDependentIoVersion) - ballerinaDependencyFile.text = newDependencyConfig } } task revertTomlFile { doLast { ballerinaConfigFile.text = originalConfig - ballerinaDependencyFile.text = originalDependencyConfig } } task ballerinaBuild { - dependsOn copyExternalJarsToLib - dependsOn copyStdlibs - dependsOn updateTomlVerions + dependsOn updateTomlVersions dependsOn configurations.nativeJar dependsOn configurations.externalJars + dependsOn copyExternalJarsToLib dependsOn compileJava dependsOn compileTestJava dependsOn jar @@ -196,10 +149,13 @@ task ballerinaBuild { dependsOn checkstyleTest dependsOn spotbugsMain dependsOn spotbugsTest + dependsOn test dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" inputs.dir file(project.projectDir) - finalizedBy(revertTomlFile) + if (skipTests) { + finalizedBy(revertTomlFile) + } doLast { def additionalBuildParams = "" @@ -207,15 +163,10 @@ task ballerinaBuild { additionalBuildParams = "--debug ${project.findProperty("debug")}" } - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat pack --offline ${additionalBuildParams} && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "${distributionBinPath}/bal pack --offline ${additionalBuildParams}" - } - } + // build bala file + executeBalCommand ("build", "${project.projectDir}") + executeBalCommand ("pack", "${project.projectDir}") + // extract bala file to artifact cache directory file("${project.projectDir}/target/bala").eachFileMatch(~/.*.bala/) { balaFile -> copy { @@ -231,15 +182,8 @@ task ballerinaBuild { } // Doc creation and packing - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "$distributionBinPath/bal.bat doc && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "$distributionBinPath/bal doc" - } - } + executeBalCommand ("doc", "${project.projectDir}") + copy { from file("$project.projectDir/target/apidocs/${packageName}") into file("$project.buildDir/docs_parent/docs/${packageName}") @@ -261,28 +205,20 @@ artifacts { } task ballerinaPublish { - dependsOn updateTomlVerions + dependsOn updateTomlVersions dependsOn ballerinaBuild - dependsOn ":${packageName}-extension-tests:test" dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" finalizedBy(revertTomlFile) doLast { - if (project.version.endsWith('-SNAPSHOT')) { + if (project.version.toString().split("-").length > 1) { return } if (ballerinaCentralAccessToken != null) { println("Publishing to the ballerina central...") - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "$distributionBinPath/bal push" - } - } + def env = "JAVA_OPTS -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + executeBalCommand ("push", "${project.projectDir}", env) } else { throw new InvalidUserDataException("Central Access Token is not present") } @@ -325,3 +261,23 @@ task extractBallerinaClassFiles(type: Copy) { into "${project.rootDir.absolutePath}/build/classes" } } + +task publishBalaFileToLocal { + dependsOn ballerinaBuild + + finalizedBy(revertTomlFile) + + doLast { + if (!skipTests) { + exec { + workingDir "${project.rootDir}/ballerina" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "bal.bat push --repository=local" + + " && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "bal push --repository=local" + } + } + } + } +} diff --git a/jaeger-extension-ballerina/tracer_provider.bal b/ballerina/tracer_provider.bal similarity index 100% rename from jaeger-extension-ballerina/tracer_provider.bal rename to ballerina/tracer_provider.bal diff --git a/build.gradle b/build.gradle index 64bff9c..9192abf 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,8 @@ * limitations under the License. */ +import org.apache.tools.ant.taskdefs.condition.Os + plugins { id 'checkstyle' id "com.github.spotbugs" version "5.0.14" @@ -68,35 +70,6 @@ subprojects { ballerinaStdLibs } - dependencies { - // Ballerina Pack - jbalTools "org.ballerinalang:jballerina-tools:${ballerinaLangVersion}" - - // Observe Modules - ballerinaStdLibs "io.ballerina.stdlib:observe-ballerina:${observeVersion}" - ballerinaStdLibs "io.ballerina:observe-ballerina:${observeInternalVersion}" - - // Standard Library Dependencies - ballerinaStdLibs "io.ballerina.stdlib:regex-ballerina:${stdlibRegexVersion}" - ballerinaStdLibs "io.ballerina.stdlib:http-ballerina:${stdlibHttpVersion}" - - // Standard Library Transitive Dependencies - ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" - ballerinaStdLibs "io.ballerina.stdlib:os-ballerina:${stdlibOsVersion}" - ballerinaStdLibs "io.ballerina.stdlib:time-ballerina:${stdlibTimeVersion}" - ballerinaStdLibs "io.ballerina.stdlib:url-ballerina:${stdlibUrlVersion}" - ballerinaStdLibs "io.ballerina.stdlib:task-ballerina:${stdlibTaskVersion}" - ballerinaStdLibs "io.ballerina.stdlib:file-ballerina:${stdlibFileVersion}" - ballerinaStdLibs "io.ballerina.stdlib:crypto-ballerina:${stdlibCryptoVersion}" - ballerinaStdLibs "io.ballerina.stdlib:log-ballerina:${stdlibLogVersion}" - ballerinaStdLibs "io.ballerina.stdlib:mime-ballerina:${stdlibMimeVersion}" - ballerinaStdLibs "io.ballerina.stdlib:cache-ballerina:${stdlibCacheVersion}" - ballerinaStdLibs "io.ballerina.stdlib:auth-ballerina:${stdlibAuthVersion}" - ballerinaStdLibs "io.ballerina.stdlib:jwt-ballerina:${stdlibJwtVersion}" - ballerinaStdLibs "io.ballerina.stdlib:oauth2-ballerina:${stdlibOAuth2Version}" - ballerinaStdLibs "io.ballerina.stdlib:uuid-ballerina:${stdlibUuidVersion}" - } - checkstyle { toolVersion '10.12.1' } @@ -136,6 +109,23 @@ subprojects { def moduleVersion = project.version.replace("-SNAPSHOT", "") +def executeBalCommand(String command, String dir, env = "") { + try { + exec { + workingDir dir + environment environment: env + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "bal.bat ${command} && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "bal ${command}" + } + } + } catch (Exception e) { + println("bal command failed. " + e.message) + throw e + } +} + release { failOnPublishNeeded = false failOnSnapshotDependencies = true diff --git a/gradle.properties b/gradle.properties index 0d85b58..8fb49e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,28 +33,6 @@ protobufVersion=3.20.3 nettyVersion=4.1.100.Final perfmarkVersion=0.23.0 -# Observe Modules -observeVersion=1.0.2 -observeInternalVersion=1.0.2 - -# Test Module Dependecy Versions -stdlibHttpVersion=2.10.4 -stdlibIoVersion=1.6.0 -stdlibRegexVersion=1.2.1 -stdlibOsVersion=1.8.0 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 -stdlibTaskVersion=2.5.0 -stdlibFileVersion=1.9.0 -stdlibCryptoVersion=2.5.0 -stdlibLogVersion=2.9.0 -stdlibMimeVersion=2.9.0 -stdlibCacheVersion=3.7.0 -stdlibAuthVersion=2.10.0 -stdlibJwtVersion=2.10.0 -stdlibOAuth2Version=2.10.0 -stdlibUuidVersion=1.7.0 - # Test Dependency Versions testngVersion=7.6.1 slf4jVersion=1.7.26 diff --git a/jaeger-extension-ballerina/Dependencies.toml b/jaeger-extension-ballerina/Dependencies.toml deleted file mode 100644 index c4ebd9e..0000000 --- a/jaeger-extension-ballerina/Dependencies.toml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. 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. - -[[dependency]] -org = "ballerina" -name = "io" -version = "@stdlib.io.version@" diff --git a/jaeger-extension-ballerina/build.gradle b/jaeger-extension-ballerina/build.gradle deleted file mode 100644 index bed44b3..0000000 --- a/jaeger-extension-ballerina/build.gradle +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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. - */ - -import org.apache.tools.ant.taskdefs.condition.Os - -description = 'Ballerina - Jaeger Extension - Ballerina Module' - -configurations { - nativeJar { - transitive false - } - externalJars { - transitive false - } - distribution { - canBeConsumed true - canBeResolved false - } -} - -dependencies { - nativeJar project(':jaeger-extension-native') - - externalJars "io.jaegertracing:jaeger-core:${jaegerVersion}" - externalJars "io.jaegertracing:jaeger-thrift:${jaegerVersion}" - externalJars "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-api-metrics:${openTelemetryAlphaVersion}" - externalJars "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-semconv:${openTelemetryAlphaVersion}" - externalJars "io.opentelemetry:opentelemetry-proto:${openTelemetryAlphaVersion}" - externalJars "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-exporter-otlp-common:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" - externalJars "com.google.guava:guava:${guavaVersion}" - externalJars "com.google.guava:failureaccess:${failureAccessVersion}" - externalJars "io.grpc:grpc-api:${grpcVersion}" - externalJars "io.grpc:grpc-context:${grpcVersion}" - externalJars "io.grpc:grpc-core:${grpcVersion}" - externalJars "io.grpc:grpc-stub:${grpcVersion}" - externalJars "io.grpc:grpc-protobuf:${grpcVersion}" - externalJars "io.grpc:grpc-protobuf-lite:${grpcVersion}" - externalJars "io.grpc:grpc-netty-shaded:${grpcVersion}" - externalJars "com.google.protobuf:protobuf-java:${protobufVersion}" - externalJars "io.netty:netty-handler:${nettyVersion}" - externalJars "io.perfmark:perfmark-api:${perfmarkVersion}" -} - -clean { - delete "${project.projectDir}/target" - delete "${project.projectDir}/Ballerina.lock" - delete "${project.projectDir}/ballerina-internal.log" -} - -jar { - manifest { - attributes('Implementation-Title': project.name, 'Implementation-Version': project.version) - } -} - -task unpackJballerinaTools(type: Copy, dependsOn: configurations.jbalTools) { - configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact -> - from zipTree(artifact.getFile()) - into new File("${buildDir}/extracted-distributions", "jballerina-tools-zip") - } -} - -task unpackStdLibs(dependsOn: configurations.ballerinaStdLibs) { - doLast { - configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> - copy { - from project.zipTree(artifact.getFile()) - into new File("${buildDir}/extracted-distributions", artifact.name + "-zip") - } - } - } -} - -task copyExternalJarsToLib(type: Copy) { - into "${project.projectDir}/lib" - from configurations.externalJars -} - -task copyStdlibs(type: Copy) { - dependsOn unpackJballerinaTools - dependsOn unpackStdLibs - - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - into "${project.buildDir}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}" - - /* Standard Libraries */ - configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact -> - def artifactExtractedPath = "${buildDir}/extracted-distributions/" + artifact.name + "-zip" - into("repo/bala") { - from "${artifactExtractedPath}/bala" - } - into("repo/cache") { - from "${artifactExtractedPath}/cache" - } - } -} - -def packageOrg = "ballerinax" -def packageName = "jaeger" -def ballerinaConfigFile = new File("${project.projectDir}/Ballerina.toml") -def ballerinaDependencyFile = new File("$project.projectDir/Dependencies.toml") -def artifactBallerinaDocs = file("${project.projectDir}/build/docs_parent/") -def artifactCacheParent = file("${project.buildDir}/cache_parent/") -def artifactLibParent = file("${project.buildDir}/lib_parent/") -def snapshotVersion = "-SNAPSHOT" -def tomlVersion = stripBallerinaExtensionVersion("${project.version}") -def ballerinaCentralAccessToken = System.getenv('BALLERINA_CENTRAL_ACCESS_TOKEN') -def originalConfig = ballerinaConfigFile.text -def originalDependencyConfig = ballerinaDependencyFile.text -def artifactJar = file("$project.projectDir/target/cache/${packageOrg}/${packageName}/${tomlVersion}/java17/") -def platform = "java17" -def distributionBinPath = "${project.buildDir.absolutePath}/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ballerinaLangVersion}/bin" - -def stripBallerinaExtensionVersion(String extVersion) { - if (extVersion.matches(project.ext.timestampedVersionRegex)) { - def splitVersion = extVersion.split('-'); - if (splitVersion.length > 3) { - def strippedValues = splitVersion[0..-4] - return strippedValues.join('-') - } else { - return extVersion - } - } else { - return extVersion.replace("${project.ext.snapshotVersion}", "") - } -} - -task updateTomlVerions { - doLast { - def stdlibDependentIoVersion = stripBallerinaExtensionVersion(project.stdlibIoVersion) - def jaegerVersion = project.jaegerVersion - def openTelemetryVersion = project.openTelemetryVersion - def openTelemetryAlphaVersion = project.openTelemetryAlphaVersion - def guavaVersion = project.guavaVersion - def failureAccessVersion = project.failureAccessVersion - def grpcVersion = project.grpcVersion - def nettyVersion = project.nettyVersion - def protobufVersion = project.protobufVersion - def perfmarkVersion = project.perfmarkVersion - - def newConfig = ballerinaConfigFile.text.replace("@project.version@", project.version) - newConfig = newConfig.replace("@toml.version@", tomlVersion) - newConfig = newConfig.replace("@jaeger.version@", jaegerVersion) - newConfig = newConfig.replace("@opentelemetry.version@", openTelemetryVersion) - newConfig = newConfig.replace("@openTelemetryAlpha.version@", openTelemetryAlphaVersion) - newConfig = newConfig.replace("@guava.version@", guavaVersion) - newConfig = newConfig.replace("@failureAccess.version@", failureAccessVersion) - newConfig = newConfig.replace("@grpc.version@", grpcVersion) - newConfig = newConfig.replace("@netty.version@", nettyVersion) - newConfig = newConfig.replace("@protobuf.version@", protobufVersion) - newConfig = newConfig.replace("@perfmark.version@", perfmarkVersion) - ballerinaConfigFile.text = newConfig - - def newDependencyConfig = ballerinaDependencyFile.text.replace("@stdlib.io.version@", stdlibDependentIoVersion) - ballerinaDependencyFile.text = newDependencyConfig - } -} - -task revertTomlFile { - doLast { - ballerinaConfigFile.text = originalConfig - ballerinaDependencyFile.text = originalDependencyConfig - } -} - -task ballerinaBuild { - dependsOn copyExternalJarsToLib - dependsOn copyStdlibs - dependsOn updateTomlVerions - dependsOn configurations.nativeJar - dependsOn configurations.externalJars - dependsOn compileJava - dependsOn compileTestJava - dependsOn jar - dependsOn checkstyleMain - dependsOn checkstyleTest - dependsOn spotbugsMain - dependsOn spotbugsTest - dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" - - inputs.dir file(project.projectDir) - finalizedBy(revertTomlFile) - - doLast { - def additionalBuildParams = "" - if (project.hasProperty("debug")) { - additionalBuildParams = "--debug ${project.findProperty("debug")}" - } - - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat pack --offline ${additionalBuildParams} && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "${distributionBinPath}/bal pack --offline ${additionalBuildParams}" - } - } - // extract bala file to artifact cache directory - file("${project.projectDir}/target/bala").eachFileMatch(~/.*.bala/) { balaFile -> - copy { - from zipTree(balaFile) - into file("$artifactCacheParent/bala/${packageOrg}/${packageName}/${tomlVersion}/${platform}") - } - } - copy { - from file("${project.projectDir}/target/cache") - exclude '**/*-testable.jar' - exclude '**/tests_cache/' - into file("$artifactCacheParent/cache/") - } - - // Doc creation and packing - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "$distributionBinPath/bal.bat doc && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "$distributionBinPath/bal doc" - } - } - copy { - from file("$project.projectDir/target/apidocs/${packageName}") - into file("$project.buildDir/docs_parent/docs/${packageName}") - } - } - - outputs.dir artifactCacheParent - outputs.dir artifactBallerinaDocs - outputs.dir artifactLibParent -} - -task createArtifactZip(type: Zip) { - destinationDirectory = file("${project.buildDir}/distributions") - from ballerinaBuild -} - -artifacts { - distribution createArtifactZip -} - -task ballerinaPublish { - dependsOn updateTomlVerions - dependsOn ballerinaBuild - dependsOn ":${packageName}-extension-tests:test" - dependsOn ":jaeger-extension-ballerina:generatePomFileForMavenJavaPublication" - - finalizedBy(revertTomlFile) - - doLast { - if (project.version.endsWith('-SNAPSHOT')) { - return - } - if (ballerinaCentralAccessToken != null) { - println("Publishing to the ballerina central...") - exec { - workingDir project.projectDir - environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', '-c', "$distributionBinPath/bal push" - } - } - } else { - throw new InvalidUserDataException("Central Access Token is not present") - } - } -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifact source: createArtifactZip, extension: 'zip' - } - } - - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/${System.getenv("packagePublishRepo")}") - credentials { - username = System.getenv("packageUser") - password = System.getenv("packagePAT") - } - } - } -} - -build { - dependsOn ballerinaBuild -} - -publish { - dependsOn ballerinaPublish -} - -task extractBallerinaClassFiles(type: Copy) { - fileTree(artifactJar).forEach { file -> - from zipTree(file).matching { - exclude '**/tests/*' - include '**/*.class' - } - into "${project.rootDir.absolutePath}/build/classes" - } -} diff --git a/jaeger-extension-native/build.gradle b/jaeger-extension-native/build.gradle deleted file mode 100644 index 58e100c..0000000 --- a/jaeger-extension-native/build.gradle +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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. - */ - -plugins { - id 'java-library' -} - -description = 'Ballerina - Jaeger Extension - Native Module' - -dependencies { - implementation "org.ballerinalang:ballerina-runtime:${ballerinaLangVersion}" - implementation "io.jaegertracing:jaeger-core:${jaegerVersion}" - implementation "io.jaegertracing:jaeger-thrift:${jaegerVersion}" - implementation "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-api-metrics:${openTelemetryAlphaVersion}" - implementation "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-semconv:${openTelemetryAlphaVersion}" - implementation "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" - implementation("com.google.guava:guava:${guavaVersion}") { - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("com.google.guava:failureaccess:${failureAccessVersion}") - implementation("io.grpc:grpc-api:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("io.grpc:grpc-core:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("io.grpc:grpc-stub:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("io.grpc:grpc-protobuf:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("io.grpc:grpc-protobuf-lite:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation("io.grpc:grpc-netty-shaded:${grpcVersion}") { - exclude group: 'io.grpc', module: 'grpc-context' - exclude group: 'com.google.code.findbugs', module: 'jsr305' - } - implementation "com.google.protobuf:protobuf-java:${protobufVersion}" - implementation("io.netty:netty-handler:${nettyVersion}") - implementation "io.perfmark:perfmark-api:${perfmarkVersion}" -} - -compileJava { - doFirst { - options.compilerArgs = [ - '--module-path', classpath.asPath, - ] - classpath = files() - } -} - -jar { - manifest { - attributes('Implementation-Title': project.name, 'Implementation-Version': project.version) - } -} - -publishing { - publications { - mavenJava(MavenPublication) { - groupId project.group - artifactId "jaeger-extension-native" - version = project.version - artifact jar - } - } - - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/${System.getenv("packagePublishRepo")}") - credentials { - username = System.getenv("packageUser") - password = System.getenv("packagePAT") - } - } - } -} - -task copyJavaClassFiles(type: Copy) { - dependsOn(compileJava) - from("${project.buildDir}/classes") { - exclude '**/module-info.class' - include '**/*.class' - } - into "${project.rootDir.absolutePath}/build/classes" -} diff --git a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java b/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java deleted file mode 100644 index f9e3c08..0000000 --- a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/JaegerTracerProvider.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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 io.ballerina.observe.trace.jaeger; - -import io.ballerina.observe.trace.jaeger.sampler.RateLimitingSampler; -import io.ballerina.runtime.api.values.BDecimal; -import io.ballerina.runtime.api.values.BString; -import io.ballerina.runtime.observability.tracer.spi.TracerProvider; -import io.grpc.ManagedChannel; -import io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.extension.trace.propagation.JaegerPropagator; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; -import io.opentelemetry.sdk.trace.samplers.Sampler; - -import java.io.PrintStream; -import java.util.concurrent.TimeUnit; - -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; - -/** - * This is the Jaeger tracing extension class for {@link TracerProvider}. - */ -public class JaegerTracerProvider implements TracerProvider { - private static final String TRACER_NAME = "jaeger"; - private static final PrintStream console = System.out; - - static SdkTracerProviderBuilder tracerProviderBuilder; - - @Override - public String getName() { - return TRACER_NAME; - } - - @Override - public void init() { // Do Nothing - } - - public static void initializeConfigurations(BString agentHostname, int agentPort, BString samplerType, - BDecimal samplerParam, int reporterFlushInterval, - int reporterBufferSize) { - - String reporterEndpoint = agentHostname + ":" + agentPort; - - ManagedChannel jaegerChannel = new NettyChannelProvider() - .builderForTarget(reporterEndpoint) - .usePlaintext() - .build(); - - OtlpGrpcSpanExporter exporter = OtlpGrpcSpanExporter.builder() - .setChannel(jaegerChannel) - .build(); - - tracerProviderBuilder = SdkTracerProvider.builder() - .addSpanProcessor(BatchSpanProcessor - .builder(exporter) - .setMaxExportBatchSize(reporterBufferSize) - .setExporterTimeout(reporterFlushInterval, TimeUnit.MILLISECONDS) - .build()); - - tracerProviderBuilder.setSampler(selectSampler(samplerType, samplerParam)); - - console.println("ballerina: started publishing traces to Jaeger on " + reporterEndpoint); - } - - private static Sampler selectSampler(BString samplerType, BDecimal samplerParam) { - switch (samplerType.getValue()) { - default: - case "const": - if (samplerParam.value().intValue() == 0) { - return Sampler.alwaysOff(); - } else { - return Sampler.alwaysOn(); - } - case "probabilistic": - return Sampler.traceIdRatioBased(samplerParam.value().doubleValue()); - case RateLimitingSampler.TYPE: - return new RateLimitingSampler(samplerParam.value().intValue()); - } - } - - @Override - public Tracer getTracer(String serviceName) { - - return tracerProviderBuilder.setResource( - Resource.create(Attributes.of(SERVICE_NAME, serviceName))) - .build().get("jaeger"); - } - - @Override - public ContextPropagators getPropagators() { - - return ContextPropagators.create(JaegerPropagator.getInstance()); - } -} diff --git a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java b/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java deleted file mode 100644 index 0f5ea15..0000000 --- a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimiter.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package io.ballerina.observe.trace.jaeger.sampler; - -import io.opentelemetry.sdk.common.Clock; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.0.0/sdk-extensions/ - * jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/RateLimiter.java. - */ -class RateLimiter { - private final Clock clock; - private final double creditsPerNanosecond; - private final long maxBalance; // max balance in nano ticks - private final AtomicLong debit; // last op nano time less remaining balance - - RateLimiter(double creditsPerSecond, double maxBalance, Clock clock) { - this.clock = clock; - this.creditsPerNanosecond = creditsPerSecond / 1.0e9; - this.maxBalance = (long) (maxBalance / creditsPerNanosecond); - this.debit = new AtomicLong(clock.nanoTime() - this.maxBalance); - } - - public boolean checkCredit(double itemCost) { - long cost = (long) (itemCost / creditsPerNanosecond); - long credit; - long currentDebit; - long balance; - do { - currentDebit = debit.get(); - credit = clock.nanoTime(); - balance = credit - currentDebit; - if (balance > maxBalance) { - balance = maxBalance; - } - balance -= cost; - if (balance < 0) { - return false; - } - } while (!debit.compareAndSet(currentDebit, credit - balance)); - return true; - } -} diff --git a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java b/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java deleted file mode 100644 index 579b350..0000000 --- a/jaeger-extension-native/src/main/java/io/ballerina/observe/trace/jaeger/sampler/RateLimitingSampler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package io.ballerina.observe.trace.jaeger.sampler; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.context.Context; -import io.opentelemetry.sdk.internal.SystemClock; -import io.opentelemetry.sdk.trace.data.LinkData; -import io.opentelemetry.sdk.trace.samplers.Sampler; -import io.opentelemetry.sdk.trace.samplers.SamplingDecision; -import io.opentelemetry.sdk.trace.samplers.SamplingResult; - -import java.util.List; - -/** - * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.0.0/sdk-extensions/ - * jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/RateLimitingSampler.java. - * This sampler uses a leaky bucket rate limiter to ensure that traces are sampled with a certain constant rate. - */ -public class RateLimitingSampler implements Sampler { - public static final String TYPE = "ratelimiting"; - - private final double maxTracesPerSecond; - private final RateLimiter rateLimiter; - private final SamplingResult onSamplingResult; - private final SamplingResult offSamplingResult; - - /** - * Creates rate limiting sampler. - * - * @param maxTracesPerSecond the maximum number of sampled traces per second. - */ - public RateLimitingSampler(int maxTracesPerSecond) { - this.maxTracesPerSecond = maxTracesPerSecond; - double maxBalance = maxTracesPerSecond < 1.0 ? 1.0 : maxTracesPerSecond; - this.rateLimiter = new RateLimiter(maxTracesPerSecond, maxBalance, SystemClock.getInstance()); - Attributes attributes = Attributes.empty(); - this.onSamplingResult = SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE, attributes); - this.offSamplingResult = SamplingResult.create(SamplingDecision.DROP, attributes); - } - - @Override - public SamplingResult shouldSample( - Context parentContext, - String traceId, - String name, - SpanKind spanKind, - Attributes attributes, - List parentLinks) { - return this.rateLimiter.checkCredit(1.0) ? onSamplingResult : offSamplingResult; - } - - @Override - public String getDescription() { - return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond); - } - - @Override - public String toString() { - return getDescription(); - } - - // Visible for testing - double getMaxTracesPerSecond() { - return maxTracesPerSecond; - } -} diff --git a/jaeger-extension-native/src/main/java/module-info.java b/jaeger-extension-native/src/main/java/module-info.java deleted file mode 100644 index c50e2af..0000000 --- a/jaeger-extension-native/src/main/java/module-info.java +++ /dev/null @@ -1,17 +0,0 @@ -module io.ballerina.observe.trace.extension.jaeger { - requires io.ballerina.runtime; - requires jaeger.core; - requires io.opentelemetry.api; - requires io.opentelemetry.api.metrics; - requires io.opentelemetry.context; - requires io.opentelemetry.sdk.trace; - requires io.opentelemetry.sdk.common; - requires io.opentelemetry.extension.trace.propagation; - requires io.opentelemetry.semconv; - requires io.opentelemetry.exporter.otlp.trace; - requires grpc.api; - requires grpc.netty.shaded; - - provides io.ballerina.runtime.observability.tracer.spi.TracerProvider - with io.ballerina.observe.trace.jaeger.JaegerTracerProvider; -} diff --git a/native/build.gradle b/native/build.gradle index 5783ca0..15f3990 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -22,7 +22,6 @@ description = 'Ballerina - Jaeger Extension - Native Module' dependencies { implementation "org.ballerinalang:ballerina-runtime:${ballerinaLangVersion}" - implementation "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" implementation "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" implementation "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetrySDKVersion}" implementation "io.opentelemetry:opentelemetry-sdk-common:${openTelemetrySDKVersion}" diff --git a/jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/native-image.properties b/native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/native-image.properties similarity index 100% rename from jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/native-image.properties rename to native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/native-image.properties diff --git a/jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/reflect-config.json b/native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/reflect-config.json similarity index 100% rename from jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/reflect-config.json rename to native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/reflect-config.json diff --git a/jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/resource-config.json b/native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/resource-config.json similarity index 100% rename from jaeger-extension-native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/resource-config.json rename to native/src/main/resources/META-INF/native-image/org.ballerinalang/jaeger-extension-native/resource-config.json diff --git a/jaeger-extension-native/src/main/resources/META-INF/services/io.ballerina.runtime.observability.tracer.spi.TracerProvider b/native/src/main/resources/META-INF/services/io.ballerina.runtime.observability.tracer.spi.TracerProvider similarity index 100% rename from jaeger-extension-native/src/main/resources/META-INF/services/io.ballerina.runtime.observability.tracer.spi.TracerProvider rename to native/src/main/resources/META-INF/services/io.ballerina.runtime.observability.tracer.spi.TracerProvider diff --git a/settings.gradle b/settings.gradle index 76a7809..9f4c1f7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,9 +26,9 @@ include(':jaeger-extension-native') include(':jaeger-extension-tests') project(':build-config:checkstyle').projectDir = file('build-config/checkstyle') -project(':jaeger-extension-ballerina').projectDir = file('jaeger-extension-ballerina') -project(':jaeger-extension-native').projectDir = file('jaeger-extension-native') -project(':jaeger-extension-tests').projectDir = file('jaeger-extension-tests') +project(':jaeger-extension-ballerina').projectDir = file('ballerina') +project(':jaeger-extension-native').projectDir = file('native') +project(':jaeger-extension-tests').projectDir = file('tests') gradleEnterprise { buildScan { diff --git a/jaeger-extension-tests/build.gradle b/tests/build.gradle similarity index 100% rename from jaeger-extension-tests/build.gradle rename to tests/build.gradle diff --git a/jaeger-extension-tests/spotbugs-test-exclude.xml b/tests/spotbugs-test-exclude.xml similarity index 100% rename from jaeger-extension-tests/spotbugs-test-exclude.xml rename to tests/spotbugs-test-exclude.xml diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/BaseTestCase.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/BaseTestCase.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/BaseTestCase.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/BaseTestCase.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/JaegerTracesTestCase.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/JaegerTracesTestCase.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/JaegerTracesTestCase.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/JaegerTracesTestCase.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerLogReader.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerLogReader.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerLogReader.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerLogReader.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerizedJaegerServer.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerizedJaegerServer.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerizedJaegerServer.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ContainerizedJaegerServer.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServer.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServer.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServer.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServer.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServerProtocol.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServerProtocol.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServerProtocol.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/JaegerServerProtocol.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessJaegerServer.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessJaegerServer.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessJaegerServer.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessJaegerServer.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessLogReader.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessLogReader.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessLogReader.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/backend/ProcessLogReader.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerProcess.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerProcess.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerProcess.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerProcess.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponse.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponse.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponse.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponse.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponseTypeToken.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponseTypeToken.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponseTypeToken.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerQueryResponseTypeToken.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpan.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpan.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpan.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpan.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpanReference.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpanReference.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpanReference.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerSpanReference.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTag.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTag.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTag.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTag.java diff --git a/jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTrace.java b/tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTrace.java similarity index 100% rename from jaeger-extension-tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTrace.java rename to tests/src/test/java/io/ballerina/observe/trace/jaeger/model/JaegerTrace.java diff --git a/jaeger-extension-tests/src/test/resources/bal/01_http_svc_test.bal b/tests/src/test/resources/bal/01_http_svc_test.bal similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/01_http_svc_test.bal rename to tests/src/test/resources/bal/01_http_svc_test.bal diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigAgent.toml b/tests/src/test/resources/bal/ConfigAgent.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigAgent.toml rename to tests/src/test/resources/bal/ConfigAgent.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigDefault.toml b/tests/src/test/resources/bal/ConfigDefault.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigDefault.toml rename to tests/src/test/resources/bal/ConfigDefault.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigInvalidProvider.toml b/tests/src/test/resources/bal/ConfigInvalidProvider.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigInvalidProvider.toml rename to tests/src/test/resources/bal/ConfigInvalidProvider.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigInvalidSampler.toml b/tests/src/test/resources/bal/ConfigInvalidSampler.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigInvalidSampler.toml rename to tests/src/test/resources/bal/ConfigInvalidSampler.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigSamplerConst.toml b/tests/src/test/resources/bal/ConfigSamplerConst.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigSamplerConst.toml rename to tests/src/test/resources/bal/ConfigSamplerConst.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigSamplerProbabilistic.toml b/tests/src/test/resources/bal/ConfigSamplerProbabilistic.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigSamplerProbabilistic.toml rename to tests/src/test/resources/bal/ConfigSamplerProbabilistic.toml diff --git a/jaeger-extension-tests/src/test/resources/bal/ConfigSamplerRatelimiting.toml b/tests/src/test/resources/bal/ConfigSamplerRatelimiting.toml similarity index 100% rename from jaeger-extension-tests/src/test/resources/bal/ConfigSamplerRatelimiting.toml rename to tests/src/test/resources/bal/ConfigSamplerRatelimiting.toml diff --git a/jaeger-extension-tests/src/test/resources/logging.properties b/tests/src/test/resources/logging.properties similarity index 100% rename from jaeger-extension-tests/src/test/resources/logging.properties rename to tests/src/test/resources/logging.properties diff --git a/jaeger-extension-tests/src/test/resources/testng.xml b/tests/src/test/resources/testng.xml similarity index 100% rename from jaeger-extension-tests/src/test/resources/testng.xml rename to tests/src/test/resources/testng.xml From d94ba50dc53da2ebb0abad9c88f3f4360c82865a Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 30 Nov 2023 15:05:41 +0530 Subject: [PATCH 04/16] Update workflows --- .github/workflows/build-main.yml | 31 ++++++++++- .github/workflows/central-publish.yml | 12 +++-- .github/workflows/daily-build.yml | 75 +++++++++++++++++---------- .github/workflows/graalvm-check.yml | 34 +++++++----- .github/workflows/publish-release.yml | 36 +++++++++---- .github/workflows/pull-request.yml | 34 +++--------- 6 files changed, 140 insertions(+), 82 deletions(-) diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index eb17fb6..722df6e 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -2,10 +2,18 @@ name: Build on: workflow_dispatch: + inputs: + ballerina_version: + description: 'Ballerina version' + required: true + default: '2201.8.3' push: branches: - main +env: + BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + jobs: build: runs-on: ubuntu-latest @@ -16,8 +24,27 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: adopt + distribution: 'temurin' java-version: 17.0.7 + - name: Set up Ballerina + if: github.event_name == 'workflow_dispatch' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ github.event.inputs.ballerina_version }} + - name: Set up Ballerina + if: github.event_name == 'push' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }} + - name: Change to Timestamped Version + run: | + startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00') + latestCommit=$(git log -n 1 --pretty=format:"%h") + VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev) + updatedVersion=$VERSION-$startTime-$latestCommit + echo $updatedVersion + echo TIMESTAMPED_VERSION=$updatedVersion >> $GITHUB_ENV + sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Set Docker Host env variable @@ -40,5 +67,5 @@ jobs: with: name: distribution path: | - jaeger-extension-ballerina/build/distributions/jaeger-extension-ballerina-*.zip + ballerina/build/distributions/jaeger-extension-ballerina-*.zip if-no-files-found: error diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 5afb9c3..479234c 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -3,6 +3,10 @@ name: Publish to the Ballerina central on: workflow_dispatch: inputs: + ballerina_version: + description: 'Ballerina version' + required: true + default: '2201.8.3' environment: type: choice description: Select environment @@ -23,18 +27,20 @@ jobs: with: distribution: 'temurin' java-version: 17.0.7 + - name: Set up Ballerina + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ github.event.inputs.ballerina_version }} - name: Build with Gradle env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew build -x check -x test - - name: Create lib directory if not exists - run: mkdir -p jaeger-extension-ballerina/lib - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: scan-type: 'rootfs' - scan-ref: '/github/workspace/jaeger-extension-ballerina/lib' + scan-ref: '/github/workspace/ballerina/lib' format: 'table' timeout: '10m0s' exit-code: '1' diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 7d8f939..81c05fe 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -1,8 +1,17 @@ -name: Daily build +name: GraalVM Check on: schedule: - - cron: '30 2 * * *' + - cron: '30 18 * * *' + workflow_dispatch: + inputs: + ballerina_version: + description: 'Ballerina version' + required: true + default: '2201.8.3' + +env: + BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version jobs: build: @@ -10,32 +19,44 @@ jobs: steps: - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 + - name: Set up GraalVM + uses: graalvm/setup-graalvm@v1 with: - distribution: adopt - java-version: 17.0.7 - - # Build the project with Gradle + version: 'latest' + java-version: '17.0.7' + components: 'native-image' + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Check GraalVM installation + run: | + echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" + echo "JAVA_HOME: ${{ env.JAVA_HOME }}" + native-image --version + - name: Set up Ballerina + if: github.event_name == 'workflow_dispatch' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ github.event.inputs.ballerina_version }} + - name: Set up Ballerina + if: github.event_name == 'schedule' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }} + - name: Grant execute permission for gradlew + run: chmod +x gradlew - name: Build with Gradle env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: | - ./gradlew clean build - - # Send notification when build fails - - name: Notify failure - if: ${{ failure() }} + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true run: | - curl -X POST \ - 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ - -H 'Accept: application/vnd.github.v3+json' \ - -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ - --data "{ - \"event_type\": \"notify-build-failure\", - \"client_payload\": { - \"repoName\": \"module-ballerinax-jaeger\" - } - }" + ./gradlew build + - name: Update dependency versions + run: ./gradlew :jaeger-extension-ballerina:updateTomlVerions + env: + packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} + packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} + JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true + - name: Run Ballerina build using the native executable + run: bal build --native ./ballerina + - name: Run Ballerina tests using the native executable + run: bal test --native ./ballerina diff --git a/.github/workflows/graalvm-check.yml b/.github/workflows/graalvm-check.yml index 381093e..81c05fe 100644 --- a/.github/workflows/graalvm-check.yml +++ b/.github/workflows/graalvm-check.yml @@ -4,6 +4,14 @@ on: schedule: - cron: '30 18 * * *' workflow_dispatch: + inputs: + ballerina_version: + description: 'Ballerina version' + required: true + default: '2201.8.3' + +env: + BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version jobs: build: @@ -11,7 +19,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up GraalVM uses: graalvm/setup-graalvm@v1 with: @@ -19,16 +26,23 @@ jobs: java-version: '17.0.7' components: 'native-image' github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Check GraalVM installation run: | echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" echo "JAVA_HOME: ${{ env.JAVA_HOME }}" native-image --version - + - name: Set up Ballerina + if: github.event_name == 'workflow_dispatch' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ github.event.inputs.ballerina_version }} + - name: Set up Ballerina + if: github.event_name == 'schedule' + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }} - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Build with Gradle env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} @@ -36,21 +50,13 @@ jobs: JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true run: | ./gradlew build - - - name: Set Up Ballerina - uses: ballerina-platform/setup-ballerina@v1 - with: - version: 2201.6.0 - - name: Update dependency versions run: ./gradlew :jaeger-extension-ballerina:updateTomlVerions env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - - name: Run Ballerina build using the native executable - run: bal build --native ./jaeger-extension-ballerina - + run: bal build --native ./ballerina - name: Run Ballerina tests using the native executable - run: bal test --native ./jaeger-extension-ballerina + run: bal test --native ./ballerina diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b8fa916..b18386e 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,6 +1,12 @@ name: Publish Release -on: [workflow_dispatch] +on: + workflow_dispatch: + inputs: + distribution_version: + description: 'Ballerina distribution version (e.g.; 2201.8.0)' + required: true + default: '2201.8.0' jobs: publish-release: @@ -12,8 +18,12 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: adopt + distribution: 'temurin' java-version: 17.0.7 + - name: Set up Ballerina + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ github.event.inputs.ballerina_version }} - name: Set version env variable run: echo "VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV - name: Pre release depenency version update @@ -24,18 +34,25 @@ jobs: git config user.name ${{ secrets.BALLERINA_BOT_USERNAME }} git config user.email ${{ secrets.BALLERINA_BOT_EMAIL }} git checkout -b release-${VERSION} - sed -i 's/ballerinaLangVersion=\(.*\)-SNAPSHOT/ballerinaLangVersion=\1/g' gradle.properties - sed -i 's/ballerinaLangVersion=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/ballerinaLangVersion=\1/g' gradle.properties - sed -i 's/observe\(.*\)=\(.*\)-SNAPSHOT/observe\1=\2/g' gradle.properties - sed -i 's/observe\(.*\)=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/observe\1=\2/g' gradle.properties - sed -i 's/stdlib\(.*\)=\(.*\)-SNAPSHOT/stdlib\1=\2/g' gradle.properties - sed -i 's/stdlib\(.*\)=\(.*\)-[0-9]\{8\}-[0-9]\{6\}-.*$/stdlib\1=\2/g' gradle.properties git add gradle.properties git commit -m "Move dependencies to stable version" || echo "No changes to commit" - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Set Docker Host env variable run: echo "DOCKER_HOST=$(docker context ls --format '{{print .DockerEndpoint}}' | tr -d '\n')" >> $GITHUB_ENV + - name: Build with Gradle + env: + packageUser: ${{ github.actor }} + packagePAT: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew build -x check -x test + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + scan-type: 'rootfs' + scan-ref: '/github/workspace/ballerina/lib' + format: 'table' + timeout: '10m0s' + exit-code: '1' - name: Publish artifact env: DOCKER_HOST: unix:///var/run/docker.sock @@ -45,11 +62,12 @@ jobs: packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} packagePublishRepo: ${{ github.repository }} run: | + git stash ./gradlew release -Prelease.useAutomaticVersion=true ./gradlew -Pversion=${VERSION} publish -x test - name: Create Github release from the release tag run: | - curl --request POST 'https://api.github.com/repos/ballerina-platform/module-ballerinax-jaeger/releases' \ + curl --request POST 'https://api.github.com/repos/${{ github.repository }}/releases' \ --header 'Accept: application/vnd.github.v3+json' \ --header 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ --header 'Content-Type: application/json' \ diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 16661e7..f7dcf98 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,6 +2,9 @@ name: Validate Pull Request on: pull_request +env: + BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + jobs: ubuntu-build: runs-on: ubuntu-latest @@ -13,6 +16,10 @@ jobs: with: distribution: adopt java-version: 17.0.7 + - name: Set up Ballerina + uses: ballerina-platform/setup-ballerina@v1.1.0 + with: + version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }} - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Set Docker Host env variable @@ -28,30 +35,3 @@ jobs: uses: codecov/codecov-action@v1 with: fail_ci_if_error: true - - windows-build: - if: false # because there is no opentelemetry-jaeger-executable available - runs-on: windows-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: 17.0.7 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Download Jaeger server executable - env: - JAEGER_VERSION: 1.21.0 - run: | - Invoke-WebRequest https://github.com/jaegertracing/jaeger/releases/download/v$env:JAEGER_VERSION/jaeger-$env:JAEGER_VERSION-windows-amd64.tar.gz -O jaeger.tar.gz - tar -xzvf jaeger.tar.gz - mv jaeger-$env:JAEGER_VERSION-windows-amd64 jaeger - echo "JAEGER_SERVER_EXECUTABLE=$(Resolve-Path jaeger\jaeger-all-in-one.exe)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew.bat clean build --stacktrace --scan --console=plain --no-daemon From 0a53754f1e4e5bb225ddaf0a6185d04f529a7752 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Tue, 12 Dec 2023 17:52:09 +0530 Subject: [PATCH 05/16] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a2ec420..12afb61 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ gradle-app.setting # Ballerina target/ +bin/ From 350bb2c9126c536817e7ba4905cc829606b77f22 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Tue, 12 Dec 2023 17:52:54 +0530 Subject: [PATCH 06/16] Include ballerina tests --- ballerina-tests/build.gradle | 205 +++++++++ .../jaeger-server-tests/.devcontainer.json | 4 + .../jaeger-server-tests/.gitignore | 2 + .../jaeger-server-tests/Ballerina.toml | 14 + .../jaeger-server-tests/Config.toml | 7 + .../jaeger-server-tests/Dependencies.toml | 358 +++++++++++++++ ballerina-tests/jaeger-server-tests/main.bal | 53 +++ .../jaeger-server-tests/tests/Config.toml | 7 + .../tests/get_http_version.bal | 58 +++ .../jaeger-server-tests/tests/test.bal | 411 ++++++++++++++++++ .../jaeger-server/docker-compose.yml | 9 + settings.gradle | 2 +- 12 files changed, 1129 insertions(+), 1 deletion(-) create mode 100644 ballerina-tests/build.gradle create mode 100644 ballerina-tests/jaeger-server-tests/.devcontainer.json create mode 100644 ballerina-tests/jaeger-server-tests/.gitignore create mode 100644 ballerina-tests/jaeger-server-tests/Ballerina.toml create mode 100644 ballerina-tests/jaeger-server-tests/Config.toml create mode 100644 ballerina-tests/jaeger-server-tests/Dependencies.toml create mode 100644 ballerina-tests/jaeger-server-tests/main.bal create mode 100644 ballerina-tests/jaeger-server-tests/tests/Config.toml create mode 100644 ballerina-tests/jaeger-server-tests/tests/get_http_version.bal create mode 100644 ballerina-tests/jaeger-server-tests/tests/test.bal create mode 100644 ballerina-tests/resources/jaeger-server/docker-compose.yml diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle new file mode 100644 index 0000000..2a2ec79 --- /dev/null +++ b/ballerina-tests/build.gradle @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. + * + * WSO2 LLC. 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. + */ + +import org.apache.tools.ant.taskdefs.condition.Os + +description = 'Ballerina - Jaeger Extension - Ballerina Tests' + +configurations { + nativeJar { + transitive false + } + externalJars { + transitive false + } + distribution { + canBeConsumed true + canBeResolved false + } +} + +clean { + delete "${project.projectDir}/target" + delete "${project.projectDir}/Ballerina.lock" + delete "${project.projectDir}/ballerina-internal.log" +} + +jar { + manifest { + attributes('Implementation-Title': project.name, 'Implementation-Version': project.version) + } +} + +def groupParams = "" +def disableGroups = "" +def windowsDisableGroups = "--disable-groups disabledOnWindows" +def debugParams = "" +def balJavaDebugParam = "" +def testParams = "" +def nativeFlag = "" + +def packageOrg = "ballerinax" +def packageName = "jaeger" +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def testPackages = ["jaeger-server-tests"] + +def jaegerServerTestConfigFile = new File("${project.projectDir}/jaeger-server-tests/Ballerina.toml") +def jaegerServerTestOriginalConfig = jaegerServerTestConfigFile.text +def jaegerServerTestDependenciesFile = new File("${project.projectDir}/jaeger-server-tests/Dependencies.toml") +def jaegerServerTestOriginalDependencies = jaegerServerTestDependenciesFile.text + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-'); + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +def skipTests = false + +gradle.taskGraph.whenReady { graph -> + if (graph.hasTask(":jaeger-extension-ballerina-tests:ballerinaTest")) { + skipTests = true + } +} + +task initializeVariables { + if (project.hasProperty("groups")) { + groupParams = "--groups ${project.findProperty("groups")}" + } + if (project.hasProperty("disable")) { + disableGroups = "--disable-groups ${project.findProperty("disable")}" + } + if (project.hasProperty("debug")) { + debugParams = "--debug ${project.findProperty("debug")}" + } + if (project.hasProperty("balJavaDebug")) { + balJavaDebugParam = "BAL_JAVA_DEBUG=${project.findProperty("balJavaDebug")}" + } + if (project.hasProperty('balNativeTest')) { + nativeFlag = '--native' + } + if (project.hasProperty('balTests')) { + testPackages = project.findProperty('balTests').toString().split(",") + } + if (project.hasProperty('skipBalTests')) { + project.findProperty('skipBalTests').toString().split(",").each {testPackage -> + testPackages.remove(testPackage) + } + } +} + +task updateTomlVerions { + dependsOn ":jaeger-extension-ballerina:ballerinaBuild" + + doLast { + def newConfig = jaegerServerTestConfigFile.text.replace("@toml.version@", tomlVersion) + jaegerServerTestConfigFile.text = newConfig + def newDependencies = jaegerServerTestDependenciesFile.text.replace("@toml.version@", tomlVersion) + jaegerServerTestDependenciesFile.text = newDependencies + } +} + +task startJaegerServer() { + dependsOn ":jaeger-extension-ballerina:ballerinaBuild" + + doLast { + // This check is added to prevent starting the server in Windows OS, since the Docker image does not support + // for Windows OS. + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def stdOut = new ByteArrayOutputStream() + exec { + commandLine 'sh', '-c', "docker ps --filter name=jaeger-server" + standardOutput = stdOut + } + if (!stdOut.toString().contains("jaeger-server")) { + println "Starting Jaeger server." + exec { + commandLine 'sh', '-c', "docker-compose -f $project.projectDir/resources/jaeger-server/docker-compose.yml up -d" + standardOutput = stdOut + } + println stdOut.toString() + println "Waiting 15s until the Jaeger server get initiated." + sleep(15 * 1000) + } else { + println "Jaeger server is already started." + } + } + } +} + +task stopJaegerServer() { + doLast { + // This check is added to prevent trying to stop the server in Windows OS, since the Docker image not started + // in Windows OS. + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def stdOut = new ByteArrayOutputStream() + exec { + commandLine 'sh', '-c', "docker ps --filter name=jaeger-server" + standardOutput = stdOut + } + if (stdOut.toString().contains("jaeger-server")) { + println "Stopping LDAP server." + exec { + commandLine 'sh', '-c', "docker stop jaeger-server" + standardOutput = stdOut + } + println stdOut.toString() + println "Waiting 5s until the Jaeger server get stopped." + sleep(5 * 1000) + } else { + println "Jaeger server is not started." + } + } + } +} + +task revertTomlFile { + doLast { + jaegerServerTestConfigFile.text = jaegerServerTestOriginalConfig + jaegerServerTestDependenciesFile.text = jaegerServerTestOriginalDependencies + } +} + +task ballerinaTest { + dependsOn ":jaeger-extension-ballerina:ballerinaBuild" + dependsOn ":jaeger-extension-ballerina:publishBalaFileToLocal" + dependsOn initializeVariables + dependsOn updateTomlVerions + dependsOn startJaegerServer + + finalizedBy(revertTomlFile) + finalizedBy(stopJaegerServer) + + doLast { + testPackages.each { testPackage -> + def env = "JAVA_OPTS -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true ${testParams} ${groupParams}" + + " ${disableGroups} ${windowsDisableGroups} ${debugParams}" + executeBalCommand("test", "${project.projectDir}/${testPackage}", env) + } + } +} + +test.dependsOn ballerinaTest diff --git a/ballerina-tests/jaeger-server-tests/.devcontainer.json b/ballerina-tests/jaeger-server-tests/.devcontainer.json new file mode 100644 index 0000000..22579f9 --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.0-20230830-220400-8a7556d8", + "extensions": ["WSO2.ballerina"], +} diff --git a/ballerina-tests/jaeger-server-tests/.gitignore b/ballerina-tests/jaeger-server-tests/.gitignore new file mode 100644 index 0000000..b61463a --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/.gitignore @@ -0,0 +1,2 @@ +target +generated diff --git a/ballerina-tests/jaeger-server-tests/Ballerina.toml b/ballerina-tests/jaeger-server-tests/Ballerina.toml new file mode 100644 index 0000000..6314c82 --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/Ballerina.toml @@ -0,0 +1,14 @@ +[package] +org = "ballerinax" +name = "jaeger_server_tests" +version = "0.1.0" +distribution = "2201.8.3" + +[build-options] +observabilityIncluded = true + +[[dependency]] +org="ballerinax" +name="jaeger" +repository="local" +version = "@toml.version@" diff --git a/ballerina-tests/jaeger-server-tests/Config.toml b/ballerina-tests/jaeger-server-tests/Config.toml new file mode 100644 index 0000000..b34d4ca --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/Config.toml @@ -0,0 +1,7 @@ +[ballerina.observe] +tracingEnabled=true +tracingProvider="jaeger" + +[ballerinax.jaeger] +agentHostname="localhost" # Optional Configuration. Default value is localhost +agentPort=4317 # Optional Configuration. Default value is 4317 diff --git a/ballerina-tests/jaeger-server-tests/Dependencies.toml b/ballerina-tests/jaeger-server-tests/Dependencies.toml new file mode 100644 index 0000000..4ef3c27 --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/Dependencies.toml @@ -0,0 +1,358 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.5-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "auth" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"} +] + +[[package]] +org = "ballerina" +name = "cache" +version = "3.7.0" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "task"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "crypto" +version = "2.6.1" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "file" +version = "1.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "http" +version = "2.10.5" +dependencies = [ + {org = "ballerina", name = "auth"}, + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.decimal"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "oauth2"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] +modules = [ + {org = "ballerina", packageName = "http", moduleName = "http"}, + {org = "ballerina", packageName = "http", moduleName = "http.httpscerr"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "jwt" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.decimal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.int" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "lang.regexp" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.runtime" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"} +] + +[[package]] +org = "ballerina" +name = "lang.string" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.regexp"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "log" +version = "2.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "observe"} +] + +[[package]] +org = "ballerina" +name = "mime" +version = "2.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"} +] + +[[package]] +org = "ballerina" +name = "oauth2" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "observe", moduleName = "observe"}, + {org = "ballerina", packageName = "observe", moduleName = "observe.mockextension"} +] + +[[package]] +org = "ballerina" +name = "os" +version = "1.8.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "task" +version = "2.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "time" +version = "2.4.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "toml" +version = "0.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "time"} +] +modules = [ + {org = "ballerina", packageName = "toml", moduleName = "toml"}, + {org = "ballerina", packageName = "toml", moduleName = "toml.lexer"}, + {org = "ballerina", packageName = "toml", moduleName = "toml.parser"}, + {org = "ballerina", packageName = "toml", moduleName = "toml.writer"} +] + +[[package]] +org = "ballerina" +name = "url" +version = "2.4.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "ballerinax" +name = "jaeger" +version = "0.5.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinax", packageName = "jaeger", moduleName = "jaeger"} +] + +[[package]] +org = "ballerinax" +name = "jaeger_server_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "test"}, + {org = "ballerina", name = "toml"}, + {org = "ballerinai", name = "observe"}, + {org = "ballerinax", name = "jaeger"} +] +modules = [ + {org = "ballerinax", packageName = "jaeger_server_tests", moduleName = "jaeger_server_tests"} +] + diff --git a/ballerina-tests/jaeger-server-tests/main.bal b/ballerina-tests/jaeger-server-tests/main.bal new file mode 100644 index 0000000..ba09f49 --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/main.bal @@ -0,0 +1,53 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. 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. + +import ballerina/http; +import ballerina/observe; +import ballerinax/jaeger as _; + +service /test on new http:Listener(9091) { + # Description. + # + # + caller - http caller + # + req - http request + resource function get sum(http:Caller caller, http:Request req) { + ObservableAdderClass adder = new ObservableAdder(20, 33); + var sum = adder.getSum(); + + http:Response resp = new; + resp.setTextPayload(<@untainted> "Sum: " + sum.toString()); + checkpanic caller->respond(resp); + } +} + +type ObservableAdderClass object { + @observe:Observable + function getSum() returns int; +}; + +class ObservableAdder { + private int firstNumber; + private int secondNumber; + + function init(int a, int b) { + self.firstNumber = a; + self.secondNumber = b; + } + + function getSum() returns int { + return self.firstNumber + self.secondNumber; + } +} diff --git a/ballerina-tests/jaeger-server-tests/tests/Config.toml b/ballerina-tests/jaeger-server-tests/tests/Config.toml new file mode 100644 index 0000000..b34d4ca --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/tests/Config.toml @@ -0,0 +1,7 @@ +[ballerina.observe] +tracingEnabled=true +tracingProvider="jaeger" + +[ballerinax.jaeger] +agentHostname="localhost" # Optional Configuration. Default value is localhost +agentPort=4317 # Optional Configuration. Default value is 4317 diff --git a/ballerina-tests/jaeger-server-tests/tests/get_http_version.bal b/ballerina-tests/jaeger-server-tests/tests/get_http_version.bal new file mode 100644 index 0000000..e47969d --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/tests/get_http_version.bal @@ -0,0 +1,58 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. 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. + +import ballerina/toml; + +const string DEPENDENCIES_TOML_FILE = "Dependencies.toml"; + +type DependenciesTomlData record {| + ProjectDetails ballerina; + Package[] package; +|}; + +type Package record {| + string org; + string name; + string version; + string scope?; + Dependency[] dependencies?; + Module[] modules?; +|}; + +type Module record {| + string org; + string packageName; + string moduleName; +|}; + +type Dependency record {| + string org; + string name; +|}; + +type ProjectDetails record {| + string dependencies\-toml\-version; + string distribution\-version; +|}; + +public function getHTTPModuleVersion() returns string|error { + map tomlFile = check toml:readFile(DEPENDENCIES_TOML_FILE); + DependenciesTomlData dependenciesTomlData = check (tomlFile.toJson()).fromJsonWithType(); + Package[] packages = dependenciesTomlData.package; + Package httpModuleData = packages.filter(package => package.name == "http")[0]; + + return httpModuleData.version; +} diff --git a/ballerina-tests/jaeger-server-tests/tests/test.bal b/ballerina-tests/jaeger-server-tests/tests/test.bal new file mode 100644 index 0000000..d727b28 --- /dev/null +++ b/ballerina-tests/jaeger-server-tests/tests/test.bal @@ -0,0 +1,411 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +// +// WSO2 LLC. 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. + +import ballerina/http; +import ballerina/test; +import ballerina/lang.runtime; + +type ServicePayload record {| + string[] data; + int total; + int 'limit; + int offset; + string? 'errors; +|}; + +type TracePayload record {| + Trace[] data; + int total; + int 'limit; + int offset; + string? 'errors; +|}; + +type Trace record {| + string traceID; + Span[] spans; + json processes; + string? warnings; +|}; + +type Span record {| + string traceID; + string spanID; + string operationName; + Reference[] references; + int startTime; + int duration; + Tag[] tags; + Log[] logs; + string processID; + string[]? warnings; +|}; + +type Log record {| + int timestamp; + Tag[] fields; +|}; + +type Tag record {| + string key; + string 'type; + string|int value; +|}; + +type Reference record {| + string refType; + string traceID; + string spanID; +|}; + +const string GET_SUM_SPAN_NAME = "get /sum"; +const string OBSERVABLE_ADDER_SPAN_NAME = "ballerinax/jaeger_server_tests/ObservableAdder:getSum"; +const string HTTP_CALLER_SPAN_NAME = "ballerina/http/Caller:respond"; +const string CLIENT_SPAN_NAME = "ballerina/http/Client:get"; +const string HTTP_CLIENT_SPAN_NAME = "ballerina/http/HttpClient:get"; +const string HTTP_CACHING_CLIENT_SPAN_NAME = "ballerina/http/HttpCachingClient:get"; + +const string CLIENT_SPAN_KIND = "client"; +const string SERVER_SPAN_KIND = "server"; + +http:Client jaegerClient = check new (string `http://localhost:16686`); +http:Client cl = check new (string `http://localhost:9091`); +http:Response res = new(); +string httpModuleVersion = check getHTTPModuleVersion(); +Trace? testServiceTrace = null; +map spanMap = {}; + +@test:BeforeSuite +function sendRequest() returns error? { + res = check cl->get("/test/sum"); + + runtime:sleep(10); + + json testServiceTracePayloadData = check jaegerClient->get("/api/traces?service=%2Ftest"); + TracePayload testServiceTracePayload = check testServiceTracePayloadData.fromJsonWithType(TracePayload); + + do { + testServiceTrace = testServiceTracePayload.data[0]; + } on fail { + test:assertFail("No traces found with service name: \"/test\"."); + } + + foreach Span span in ( testServiceTrace).spans { + spanMap[span.operationName] = span; + } +} + +@test:Config +function testResponse() returns error? { + test:assertEquals(res.statusCode, http:STATUS_OK, "Status code mismatched"); + test:assertEquals(res.getTextPayload(), "Sum: 53", "Payload mismatched"); +} + +@test:Config +function testServices() returns error? { + json servicesPayloadData = check jaegerClient->get("/api/services"); + ServicePayload servicesPayload = check servicesPayloadData.fromJsonWithType(ServicePayload); + + test:assertTrue(isContain(servicesPayload.data, "/test")); + test:assertTrue(isContain(servicesPayload.data, "Ballerina")); +} + +@test:Config +function testSpanNames() returns error? { + string[] spanNames = spanMap.keys(); + + test:assertTrue(isContain(spanNames, GET_SUM_SPAN_NAME), "Span name: \""+ GET_SUM_SPAN_NAME +"\" not found"); + test:assertTrue(isContain(spanNames, OBSERVABLE_ADDER_SPAN_NAME), "Span name: \"" + OBSERVABLE_ADDER_SPAN_NAME + "\" not found"); + test:assertTrue(isContain(spanNames, HTTP_CALLER_SPAN_NAME), "Span name: \"" + HTTP_CALLER_SPAN_NAME + "\" not found"); + + test:assertTrue(isContain(spanNames, CLIENT_SPAN_NAME), "Span name: \"" + CLIENT_SPAN_NAME + "\" not found"); + test:assertTrue(isContain(spanNames, HTTP_CACHING_CLIENT_SPAN_NAME), "Span name: \"" + HTTP_CACHING_CLIENT_SPAN_NAME + "\" not found"); + test:assertTrue(isContain(spanNames, HTTP_CLIENT_SPAN_NAME), "Span name: \"" + HTTP_CLIENT_SPAN_NAME + "\" not found"); +} + +@test:Config +function testProcessIDs() returns error? { + // Spans in the Ballerina service + test:assertEquals(( spanMap[CLIENT_SPAN_NAME]).processID, + ( spanMap[HTTP_CACHING_CLIENT_SPAN_NAME]).processID); + test:assertEquals(( spanMap[HTTP_CACHING_CLIENT_SPAN_NAME]).processID, + ( spanMap[HTTP_CLIENT_SPAN_NAME]).processID); + + // Spans in the /test service + test:assertEquals(( spanMap[GET_SUM_SPAN_NAME]).processID, + ( spanMap[OBSERVABLE_ADDER_SPAN_NAME]).processID); + test:assertEquals(( spanMap[OBSERVABLE_ADDER_SPAN_NAME]).processID, + ( spanMap[HTTP_CALLER_SPAN_NAME]).processID); +} + +@test:Config +function testSpanInheritance() returns error? { + Span clientSpan = spanMap[CLIENT_SPAN_NAME]; + Span httpCachingClientSpan = spanMap[HTTP_CACHING_CLIENT_SPAN_NAME]; + Span httpClientSpan = spanMap[HTTP_CLIENT_SPAN_NAME]; + Span getSumSpan = spanMap[GET_SUM_SPAN_NAME]; + Span observableAdderSpan = spanMap[OBSERVABLE_ADDER_SPAN_NAME]; + Span httpCallerSpan = spanMap[HTTP_CALLER_SPAN_NAME]; + + test:assertEquals(clientSpan.spanID, httpCachingClientSpan.references[0].spanID, + "ParentId mismatched for " + HTTP_CACHING_CLIENT_SPAN_NAME); + test:assertEquals(httpCachingClientSpan.spanID, httpClientSpan.references[0].spanID, + "ParentId mismatched for " + HTTP_CLIENT_SPAN_NAME); + test:assertEquals(httpClientSpan.spanID, getSumSpan.references[0].spanID, + "ParentId mismatched for " + GET_SUM_SPAN_NAME); + test:assertEquals(getSumSpan.spanID, observableAdderSpan.references[0].spanID, + "ParentId mismatched for " + OBSERVABLE_ADDER_SPAN_NAME); + test:assertEquals(getSumSpan.spanID, httpCallerSpan.references[0].spanID, + "ParentId mismatched for " + HTTP_CALLER_SPAN_NAME); +} + +@test:Config +function testSpanKind() returns error? { + string|int clientSpanKind = ( spanMap[CLIENT_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + string|int httpCachingClientSpanKind = ( spanMap[HTTP_CACHING_CLIENT_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + string|int httpClientSpanKind = ( spanMap[HTTP_CLIENT_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + string|int getSumSpanKind = ( spanMap[GET_SUM_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + string|int observableAdderSpanKind = ( spanMap[OBSERVABLE_ADDER_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + string|int httpCallerSpanKind = ( spanMap[HTTP_CALLER_SPAN_NAME]).tags.filter(tag => tag.key == "span.kind")[0].value; + + test:assertEquals(clientSpanKind, CLIENT_SPAN_KIND, "Span kind mismatched for " + CLIENT_SPAN_NAME); + test:assertEquals(httpCachingClientSpanKind, CLIENT_SPAN_KIND, "Span kind mismatched for " + HTTP_CACHING_CLIENT_SPAN_NAME); + test:assertEquals(httpClientSpanKind, CLIENT_SPAN_KIND, "Span kind mismatched for " + HTTP_CLIENT_SPAN_NAME); + test:assertEquals(getSumSpanKind, SERVER_SPAN_KIND, "Span kind mismatched for " + GET_SUM_SPAN_NAME); + test:assertEquals(observableAdderSpanKind, CLIENT_SPAN_KIND, "Span kind mismatched for " + OBSERVABLE_ADDER_SPAN_NAME); + test:assertEquals(httpCallerSpanKind, CLIENT_SPAN_KIND, "Span kind mismatched for " + HTTP_CALLER_SPAN_NAME); +} + +@test:Config +function testGetSumSpanTags() returns error? { + map getSumSpanTags = {}; + foreach Tag tag in ( spanMap[GET_SUM_SPAN_NAME]).tags { + getSumSpanTags[tag.key] = tag.value.toString(); + } + string[] getSumSpanTagKeys = getSumSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["entrypoint.function.name"], "/sum"); + test:assertTrue(containsTag("entrypoint.resource.accessor", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["entrypoint.resource.accessor"], "get"); + test:assertTrue(containsTag("entrypoint.service.name", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["entrypoint.service.name"], "/test"); + test:assertTrue(containsTag("http.method", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["http.method"], http:GET); + test:assertTrue(containsTag("http.status_code", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["http.status_code"], http:STATUS_OK.toString()); + test:assertTrue(containsTag("http.url", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["http.url"], "/test/sum"); + test:assertTrue(containsTag("listener.name", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["listener.name"], "http"); + test:assertTrue(containsTag("otlp.instrumentation.library.name", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("protocol", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["protocol"], "http"); + test:assertTrue(containsTag("span.kind", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["span.kind"], "server"); + test:assertTrue(containsTag("src.module", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("src.object.name", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.object.name"], "/test"); + test:assertTrue(containsTag("src.position", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.position"], "main.bal:26:5"); + test:assertTrue(containsTag("src.resource.accessor", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.resource.accessor"], "get"); + test:assertTrue(containsTag("src.resource.path", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.resource.path"], "/sum"); + test:assertTrue(containsTag("src.service.resource", getSumSpanTagKeys)); + test:assertEquals(getSumSpanTags["src.service.resource"], "true"); +} + +@test:Config +function testObservableAdderSpanTags() returns error? { + map observableAdderSpanTags = {}; + foreach Tag tag in ( spanMap[OBSERVABLE_ADDER_SPAN_NAME]).tags { + observableAdderSpanTags[tag.key] = tag.value.toString(); + } + string[] observableAdderSpanTagKeys = observableAdderSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["entrypoint.function.name"], "/sum"); + test:assertTrue(containsTag("entrypoint.resource.accessor", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["entrypoint.resource.accessor"], "get"); + test:assertTrue(containsTag("entrypoint.service.name", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["entrypoint.service.name"], "/test"); + test:assertTrue(containsTag("otlp.instrumentation.library.name", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("span.kind", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["span.kind"], "client"); + test:assertTrue(containsTag("src.function.name", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["src.function.name"], "getSum"); + test:assertTrue(containsTag("src.module", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["src.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("src.object.name", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["src.object.name"], "ballerinax/jaeger_server_tests/ObservableAdder"); + test:assertTrue(containsTag("src.position", observableAdderSpanTagKeys)); + test:assertEquals(observableAdderSpanTags["src.position"], "main.bal:28:19"); +} + +@test:Config +function testHttpCallerSpanTags() returns error? { + map httpCallerSpanTags = {}; + foreach Tag tag in ( spanMap[HTTP_CALLER_SPAN_NAME]).tags { + httpCallerSpanTags[tag.key] = tag.value.toString(); + } + string[] httpCallerSpanTagKeys = httpCallerSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["entrypoint.function.name"], "/sum"); + test:assertTrue(containsTag("entrypoint.resource.accessor", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["entrypoint.resource.accessor"], "get"); + test:assertTrue(containsTag("entrypoint.service.name", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["entrypoint.service.name"], "/test"); + test:assertTrue(containsTag("http.status_code", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["http.status_code"], http:STATUS_OK.toString()); + test:assertTrue(containsTag("otlp.instrumentation.library.name", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("span.kind", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["span.kind"], "client"); + test:assertTrue(containsTag("src.client.remote", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["src.client.remote"], "true"); + test:assertTrue(containsTag("src.function.name", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["src.function.name"], "respond"); + test:assertTrue(containsTag("src.module", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["src.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("src.object.name", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["src.object.name"], "ballerina/http/Caller"); + test:assertTrue(containsTag("src.position", httpCallerSpanTagKeys)); + test:assertEquals(httpCallerSpanTags["src.position"], "main.bal:32:20"); +} + +@test:Config +function testClientSpanTags() returns error? { + map clientSpanTags = {}; + foreach Tag tag in ( spanMap[CLIENT_SPAN_NAME]).tags { + clientSpanTags[tag.key] = tag.value.toString(); + } + string[] clientSpanTagKeys = clientSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["entrypoint.function.name"], "get"); + test:assertTrue(containsTag("http.base_url", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["http.base_url"], "http://localhost:9091"); + test:assertTrue(containsTag("http.method", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["http.method"], http:GET); + test:assertTrue(containsTag("http.status_code", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["http.status_code"], http:STATUS_OK.toString()); + test:assertTrue(containsTag("http.url", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["http.url"], "/test/sum"); + test:assertTrue(containsTag("otlp.instrumentation.library.name", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("span.kind", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["span.kind"], "client"); + test:assertTrue(containsTag("src.client.remote", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["src.client.remote"], "true"); + test:assertTrue(containsTag("src.function.name", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["src.function.name"], "get"); + test:assertTrue(containsTag("src.module", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["src.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("src.object.name", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["src.object.name"], "ballerina/http/Client"); + test:assertTrue(containsTag("src.position", clientSpanTagKeys)); + test:assertEquals(clientSpanTags["src.position"], "tests/test.bal:93:17"); +} + +@test:Config +function testHttpCachingClientSpanTags() returns error? { + map httpCachingClientSpanTags = {}; + foreach Tag tag in ( spanMap[HTTP_CACHING_CLIENT_SPAN_NAME]).tags { + httpCachingClientSpanTags[tag.key] = tag.value.toString(); + } + string[] httpCachingClientSpanTagKeys = httpCachingClientSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["entrypoint.function.name"], "get"); + test:assertTrue(containsTag("otlp.instrumentation.library.name", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("span.kind", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["span.kind"], "client"); + test:assertTrue(containsTag("src.client.remote", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["src.client.remote"], "true"); + test:assertTrue(containsTag("src.function.name", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["src.function.name"], "get"); + test:assertTrue(containsTag("src.module", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["src.module"], string `ballerina/http:${httpModuleVersion}`); + test:assertTrue(containsTag("src.object.name", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["src.object.name"], "ballerina/http/HttpCachingClient"); + test:assertTrue(containsTag("src.position", httpCachingClientSpanTagKeys)); + test:assertEquals(httpCachingClientSpanTags["src.position"], "http_client_endpoint.bal:282:41"); +} + +@test:Config +function testHttpClientSpanTags() returns error? { + map httpClientSpanTags = {}; + foreach Tag tag in ( spanMap[HTTP_CLIENT_SPAN_NAME]).tags { + httpClientSpanTags[tag.key] = tag.value.toString(); + } + string[] httpClientSpanTagKeys = httpClientSpanTags.keys(); + + test:assertTrue(containsTag("entrypoint.function.module", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["entrypoint.function.module"], "ballerinax/jaeger_server_tests:0.1.0"); + test:assertTrue(containsTag("entrypoint.function.name", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["entrypoint.function.name"], "get"); + test:assertTrue(containsTag("http.method", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["http.method"], http:GET); + test:assertTrue(containsTag("http.status_code", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["http.status_code"], http:STATUS_OK.toString()); + test:assertTrue(containsTag("http.url", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["http.url"], "/test/sum"); + test:assertTrue(containsTag("otlp.instrumentation.library.name", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["otlp.instrumentation.library.name"], "jaeger"); + test:assertTrue(containsTag("peer.address", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["peer.address"], "localhost:9091"); + test:assertTrue(containsTag("span.kind", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["span.kind"], "client"); + test:assertTrue(containsTag("src.client.remote", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["src.client.remote"], "true"); + test:assertTrue(containsTag("src.function.name", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["src.function.name"], "get"); + test:assertTrue(containsTag("src.module", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["src.module"], string `ballerina/http:${httpModuleVersion}`); + test:assertTrue(containsTag("src.object.name", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["src.object.name"], "ballerina/http/HttpClient"); + test:assertTrue(containsTag("src.position", httpClientSpanTagKeys)); + test:assertEquals(httpClientSpanTags["src.position"], "caching_http_caching_client.bal:371:16"); +} + +function isContain(string[] array, string id) returns boolean { + return array.indexOf(id) != (); +} + +function containsTag(string tagKey, string[] traceTagKeys) returns boolean { + foreach string key in traceTagKeys { + if (key == tagKey) { + return true; + } + } + return false; +} diff --git a/ballerina-tests/resources/jaeger-server/docker-compose.yml b/ballerina-tests/resources/jaeger-server/docker-compose.yml new file mode 100644 index 0000000..f053e67 --- /dev/null +++ b/ballerina-tests/resources/jaeger-server/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.7' +services: + jaeger_server: + image: jaegertracing/opentelemetry-all-in-one:latest + container_name: jaeger-server + ports: + - 13133:13133 + - 16686:16686 + - 4317:4317 diff --git a/settings.gradle b/settings.gradle index 9f4c1f7..1dfe18f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -28,7 +28,7 @@ include(':jaeger-extension-tests') project(':build-config:checkstyle').projectDir = file('build-config/checkstyle') project(':jaeger-extension-ballerina').projectDir = file('ballerina') project(':jaeger-extension-native').projectDir = file('native') -project(':jaeger-extension-tests').projectDir = file('tests') +project(':jaeger-extension-tests').projectDir = file('ballerina-tests') gradleEnterprise { buildScan { From c2bccbc5a5eb0fbb05d270ec38a866cc4da77f4c Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Tue, 12 Dec 2023 23:47:28 +0530 Subject: [PATCH 07/16] Include opentelemetry-api dependency --- ballerina/Ballerina.toml | 6 ++++++ ballerina/build.gradle | 1 + 2 files changed, 7 insertions(+) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 875045a..8159880 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -29,6 +29,12 @@ groupId = "ballerina" artifactId = "jaeger-extension-native" version = "@project.version@" +[[platform.java17.dependency]] +path = "./lib/opentelemetry-api-@opentelemetry.version@.jar" +groupId = "io.opentelemetry" +artifactId = "opentelemetry-api" +version = "@opentelemetry.version@" + [[platform.java17.dependency]] path = "./lib/opentelemetry-sdk-trace-@opentelemetrySDK.version@.jar" groupId = "io.opentelemetry" diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 5b1421c..a9ea486 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -34,6 +34,7 @@ configurations { dependencies { nativeJar project(':jaeger-extension-native') + externalJars "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" From 8d0d71ea50bfb3a2d7d0754f2dd8428ec5f860e8 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 29 Apr 2024 13:47:15 +0530 Subject: [PATCH 08/16] Include property to publish to ballerina-central --- ballerina/build.gradle | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index a9ea486..e786c7c 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -189,6 +189,20 @@ task ballerinaBuild { from file("$project.projectDir/target/apidocs/${packageName}") into file("$project.buildDir/docs_parent/docs/${packageName}") } + + boolean publishToCentral = project.hasProperty('publishToCentral') ? project.publishToCentral.toBoolean() : false + if (publishToCentral) { + if (project.version.toString().split("-").length > 1) { + return + } + if (ballerinaCentralAccessToken != null) { + println("Publishing to the ballerina central...") + def env = "JAVA_OPTS -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + executeBalCommand ("push", "${project.projectDir}", env) + } else { + throw new InvalidUserDataException("Central Access Token is not present") + } + } } outputs.dir artifactCacheParent From ef7f930181a6414ef1f1fea707396e3e84328cad Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:22:44 +0530 Subject: [PATCH 09/16] Update netty version --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 81b4ca5..11c81cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ group=org.ballerinalang version=0.5.0-SNAPSHOT -ballerinaLangVersion=2201.8.3 +ballerinaLangVersion=2201.9.0-20240410-095500-2653a74d org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs='-Dfile.encoding=UTF-8' @@ -30,7 +30,7 @@ guavaVersion=30.1-jre failureAccessVersion=1.0.1 grpcVersion=1.35.0 protobufVersion=3.20.3 -nettyVersion=4.1.100.Final +nettyVersion=4.1.108.Final perfmarkVersion=0.23.0 # Test Dependency Versions From 6241f88bbd273df3d336c4c464590fffb8155aa8 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:29:23 +0530 Subject: [PATCH 10/16] Update lang version for builds --- .github/workflows/build-main.yml | 4 ++-- .github/workflows/central-publish.yml | 2 +- .github/workflows/daily-build.yml | 4 ++-- .github/workflows/graalvm-check.yml | 4 ++-- .github/workflows/publish-release.yml | 4 ++-- .github/workflows/pull-request.yml | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index 722df6e..4b585a4 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -6,13 +6,13 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.9.0' push: branches: - main env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version jobs: build: diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 479234c..08a72c1 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -6,7 +6,7 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.9.0' environment: type: choice description: Select environment diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 81c05fe..e90ef61 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -8,10 +8,10 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.9.0' env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version jobs: build: diff --git a/.github/workflows/graalvm-check.yml b/.github/workflows/graalvm-check.yml index 81c05fe..e90ef61 100644 --- a/.github/workflows/graalvm-check.yml +++ b/.github/workflows/graalvm-check.yml @@ -8,10 +8,10 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.9.0' env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version jobs: build: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b18386e..a4073b8 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -4,9 +4,9 @@ on: workflow_dispatch: inputs: distribution_version: - description: 'Ballerina distribution version (e.g.; 2201.8.0)' + description: 'Ballerina distribution version (e.g.; 2201.9.0)' required: true - default: '2201.8.0' + default: '2201.9.0' jobs: publish-release: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f7dcf98..375baef 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,7 +3,7 @@ name: Validate Pull Request on: pull_request env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version jobs: ubuntu-build: From 608ee86ef42f01fd6b7c3be4639cfa45c736eaad Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:33:32 +0530 Subject: [PATCH 11/16] Update daily-build --- .github/workflows/daily-build.yml | 57 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index e90ef61..57a4637 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -1,4 +1,4 @@ -name: GraalVM Check +name: Daily Build on: schedule: @@ -11,52 +11,53 @@ on: default: '2201.9.0' env: - BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.9.0 # Update this with the latest Ballerina version jobs: build: runs-on: ubuntu-latest - + if: github.repository_owner == 'ballerina-platform' steps: - - uses: actions/checkout@v3 - - name: Set up GraalVM - uses: graalvm/setup-graalvm@v1 + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - version: 'latest' - java-version: '17.0.7' - components: 'native-image' - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Check GraalVM installation - run: | - echo "GRAALVM_HOME: ${{ env.GRAALVM_HOME }}" - echo "JAVA_HOME: ${{ env.JAVA_HOME }}" - native-image --version + distribution: 'temurin' + java-version: 17.0.7 - name: Set up Ballerina if: github.event_name == 'workflow_dispatch' uses: ballerina-platform/setup-ballerina@v1.1.0 with: version: ${{ github.event.inputs.ballerina_version }} - name: Set up Ballerina - if: github.event_name == 'schedule' + if: github.event_name == 'push' uses: ballerina-platform/setup-ballerina@v1.1.0 with: version: ${{ env.BALLERINA_DISTRIBUTION_VERSION }} + - name: Change to Timestamped Version + run: | + startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00') + latestCommit=$(git log -n 1 --pretty=format:"%h") + VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev) + updatedVersion=$VERSION-$startTime-$latestCommit + echo $updatedVersion + echo TIMESTAMPED_VERSION=$updatedVersion >> $GITHUB_ENV + sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Set Docker Host env variable + run: echo "DOCKER_HOST=$(docker context ls --format '{{print .DockerEndpoint}}' | tr -d '\n')" >> $GITHUB_ENV - name: Build with Gradle env: + DOCKER_HOST: unix:///var/run/docker.sock packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true + packagePublishRepo: ${{ github.repository }} run: | - ./gradlew build - - name: Update dependency versions - run: ./gradlew :jaeger-extension-ballerina:updateTomlVerions - env: - packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} - packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} - JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - - name: Run Ballerina build using the native executable - run: bal build --native ./ballerina - - name: Run Ballerina tests using the native executable - run: bal test --native ./ballerina + ./gradlew clean build publish --stacktrace --scan --console=plain --no-daemon + ./gradlew codeCoverageReport --console=plain --no-daemon + - name: Upload Coverage Report + uses: codecov/codecov-action@v1 + with: + fail_ci_if_error: true From cdc8b2523a664ec18d57370bbe541205870b43f6 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:35:26 +0530 Subject: [PATCH 12/16] Update daily-build --- .github/workflows/daily-build.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 57a4637..ac57090 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -61,3 +61,16 @@ jobs: uses: codecov/codecov-action@v1 with: fail_ci_if_error: true + - name: Notify failure + if: ${{ failure() }} + run: | + curl -X POST \ + 'https://api.github.com/repos/ballerina-platform/ballerina-release/dispatches' \ + -H 'Accept: application/vnd.github.v3+json' \ + -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \ + --data "{ + \"event_type\": \"notify-build-failure\", + \"client_payload\": { + \"repoName\": \"module-ballerinax-jaeger\" + } + }" From acb9704fc58056a50018e1f4c620e13097643351 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:41:16 +0530 Subject: [PATCH 13/16] Fix uploading codecov report --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 375baef..1f65af3 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -34,4 +34,4 @@ jobs: - name: Upload Coverage Report uses: codecov/codecov-action@v1 with: - fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} From bfac4d50d7bb8ab955164a59806254b03f3b4d2a Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:45:43 +0530 Subject: [PATCH 14/16] Fix uploading codecov report --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 1f65af3..660927e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -32,6 +32,6 @@ jobs: ./gradlew clean build --stacktrace --scan --console=plain --no-daemon ./gradlew codeCoverageReport --console=plain --no-daemon - name: Upload Coverage Report - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} From 461fff934342022973d5772e2177bda3fd92f082 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:47:16 +0530 Subject: [PATCH 15/16] Update lang version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 11c81cb..c654fa1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ group=org.ballerinalang version=0.5.0-SNAPSHOT -ballerinaLangVersion=2201.9.0-20240410-095500-2653a74d +ballerinaLangVersion=2201.9.0 org.gradle.caching=true org.gradle.parallel=true org.gradle.jvmargs='-Dfile.encoding=UTF-8' From 3a620829721c96bcf1163297d1325326d69f792c Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Mon, 6 May 2024 10:55:09 +0530 Subject: [PATCH 16/16] Update distribution version --- ballerina/Ballerina.toml | 2 +- ballerina/Dependencies.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 8159880..9273d2c 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -18,7 +18,7 @@ org = "ballerinax" name = "jaeger" version = "@toml.version@" -distribution = "2201.7.0" +distribution = "2201.9.0" [platform.java17] graalvmCompatible = true diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index b12fb99..7d38d6f 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.3" +distribution-version = "2201.9.0" [[package]] org = "ballerina" @@ -38,7 +38,7 @@ dependencies = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.0" +version = "1.2.3" dependencies = [ {org = "ballerina", name = "jballerina.java"} ]