From 430067cfe07eb70d3552499f746acc9a06835ce9 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Wed, 20 Mar 2024 16:56:40 +0530 Subject: [PATCH 01/13] Make external methods isolated --- ballerina/natives.bal | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 46d1ebd..093c1da 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -26,7 +26,7 @@ final map DEFAULT_TAGS = {}; # + spanName - Name of the span # + tags - Tags to be associated to the span # + return - SpanId of the started span -public function startRootSpan(string spanName, map? tags = ()) returns int = @java:Method { +public isolated function startRootSpan(string spanName, map? tags = ()) returns int = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.StartRootSpan", name: "startRootSpan" } external; @@ -37,7 +37,7 @@ public function startRootSpan(string spanName, map? tags = ()) returns i # + tags - Tags to be associated to the span # + parentSpanId - Id of the parent span or -1 if parent span should be taken from system trace # + return - SpanId of the started span -public function startSpan(string spanName, map? tags = (), int parentSpanId = -1) returns int|error = @java:Method { +public isolated function startSpan(string spanName, map? tags = (), int parentSpanId = -1) returns int|error = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.StartSpan", name: "startSpan" } external; @@ -67,7 +67,7 @@ public isolated function addTagToMetrics(string tagKey, string tagValue) returns # # + spanId - Id of span to finish # + return - An error if an error occurred while finishing the span -public function finishSpan(int spanId) returns error? = @java:Method { +public isolated function finishSpan(int spanId) returns error? = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.FinishSpan", name: "finishSpan" } external; @@ -83,7 +83,7 @@ public isolated function getSpanContext() returns map = @java:Method { # Retrieve all registered metrics including default metrics from the ballerina runtime, and user defined metrics. # # + return - Array of all registered metrics -public function getAllMetrics() returns Metric[] = @java:Method { +public isolated function getAllMetrics() returns Metric[] = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GetAllMetrics", name: "getAllMetrics" } external; @@ -93,7 +93,7 @@ public function getAllMetrics() returns Metric[] = @java:Method { # + name - Name of the metric to lookup # + tags - The key/value pair tags associated with the metric that should be looked up # + return - The metric instance -public function lookupMetric(string name, map? tags = ()) returns Counter|Gauge? = @java:Method { +public isolated function lookupMetric(string name, map? tags = ()) returns Counter|Gauge? = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.LookupMetric", name: "lookupMetric" } external; @@ -103,7 +103,7 @@ public function lookupMetric(string name, map? tags = ()) returns Counte # + name - Name of the counter metric # + description - Description of the counter metric # + metricTags - Tags associated with the counter metric -public class Counter { +public class Counter { public string name; public string description; From d0ab92f9bb9b2c608a037f23f56bb5151d92cfb0 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Wed, 20 Mar 2024 16:58:49 +0530 Subject: [PATCH 02/13] Make external methods isolated --- ballerina/natives.bal | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 093c1da..8aa257f 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -165,32 +165,32 @@ public class Counter { } } -function externCounterInit(Counter counter) = @java:Method { +isolated function externCounterInit(Counter counter) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterInitialize", name: "initialize" } external; -function externCounterRegister(Counter counter) returns error? = @java:Method { +isolated function externCounterRegister(Counter counter) returns error? = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterRegister", name: "register" } external; -function externCounterUnRegister(Counter counter) = @java:Method { +isolated function externCounterUnRegister(Counter counter) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterUnregister", name: "unregister" } external; -function externCounterIncrement(Counter counter, int amount) = @java:Method { +isolated function externCounterIncrement(Counter counter, int amount) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterIncrement", name: "increment" } external; -function externCounterReset(Counter counter) = @java:Method { +isolated function externCounterReset(Counter counter) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterReset", name: "reset" } external; -function externCounterGetValue(Counter counter) returns int = @java:Method { +isolated function externCounterGetValue(Counter counter) returns int = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.CounterGetValue", name: "getValue" } external; @@ -282,42 +282,42 @@ public class Gauge { } } -function externGaugeInit(Gauge gauge) = @java:Method { +isolated function externGaugeInit(Gauge gauge) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeInitialize", name: "initialize" } external; -function externGaugeRegister(Gauge gauge) returns error? = @java:Method { +isolated function externGaugeRegister(Gauge gauge) returns error? = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeRegister", name: "register" } external; -function externGaugeUnRegister(Gauge gauge) = @java:Method { +isolated function externGaugeUnRegister(Gauge gauge) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeUnregister", name: "unregister" } external; -function externGaugeIncrement(Gauge gauge, float amount) = @java:Method { +isolated function externGaugeIncrement(Gauge gauge, float amount) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeIncrement", name: "increment" } external; -function externGaugeDecrement(Gauge gauge, float amount) = @java:Method { +isolated function externGaugeDecrement(Gauge gauge, float amount) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeDecrement", name: "decrement" } external; -function externGaugeGetValue(Gauge gauge) returns float = @java:Method { +isolated function externGaugeGetValue(Gauge gauge) returns float = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeGetValue", name: "getValue" } external; -function externGaugeSetValue(Gauge gauge, float amount) = @java:Method { +isolated function externGaugeSetValue(Gauge gauge, float amount) = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeSetValue", name: "setValue" } external; -function externGaugeGetSnapshot(Gauge gauge) returns Snapshot[]? = @java:Method { +isolated function externGaugeGetSnapshot(Gauge gauge) returns Snapshot[]? = @java:Method { 'class: "io.ballerina.stdlib.observe.nativeimpl.GaugeGetSnapshot", name: "getSnapshot" } external; From 1d6c87f5ea15f65f3746daba3afa17efca76ecba Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 May 2024 10:53:19 +0530 Subject: [PATCH 03/13] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 4 ++-- ballerina/Dependencies.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 05f9b76..0fce066 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "observe" -version = "1.2.2" +version = "1.3.0" distribution = "2201.8.0" export = ["observe", "observe.mockextension" ] @@ -9,7 +9,7 @@ export = ["observe", "observe.mockextension" ] graalvmCompatible = true [[platform.java17.dependency]] -path = "../native/build/libs/observe-native-1.2.2-SNAPSHOT.jar" +path = "../native/build/libs/observe-native-1.3.0-SNAPSHOT.jar" groupId = "ballerina" artifactId = "observe" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 2725a36..61f019c 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -18,7 +18,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.2" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] From e836984ee031b95b402bbdb88bfb1e9163b8e01c Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 May 2024 12:09:05 +0530 Subject: [PATCH 04/13] Make public classes isolated --- ballerina/natives.bal | 60 ++++++++++++++++++++++++------------------- gradle.properties | 2 +- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 8aa257f..9ee5544 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -16,10 +16,10 @@ import ballerina/jballerina.java; -final StatisticConfig[] DEFAULT_GAUGE_STATS_CONFIG = [{ timeWindow: 600000, buckets: 5, +isolated final StatisticConfig[] DEFAULT_GAUGE_STATS_CONFIG = [{ timeWindow: 600000, buckets: 5, percentiles: [0.33, 0.5, 0.66, 0.75, 0.95, 0.99, 0.999] }]; -final map DEFAULT_TAGS = {}; +isolated final map DEFAULT_TAGS = {}; # Start a span with no parent span. # @@ -103,11 +103,11 @@ public isolated function lookupMetric(string name, map? tags = ()) retur # + name - Name of the counter metric # + description - Description of the counter metric # + metricTags - Tags associated with the counter metric -public class Counter { +public isolated class Counter { - public string name; - public string description; - public map metricTags; + public final string name; + public final string description; + public final map & readonly metricTags; # This instantiates the Counter object. Name field is mandatory, and description and tags fields # are optional and have its own default values when no params are passed. @@ -116,7 +116,7 @@ public class Counter { # + desc - Description of the Counter instance. If no description is provided, the the default empty string # will be used # + tags - The key/value pair of Tags. If no tags are provided, the default nil value will be used - public function init(string name, string? desc = "", map? tags = ()) { + public isolated function init(string name, string? desc = "", map? tags = ()) { self.name = name; if (desc is string) { self.description = desc; @@ -124,9 +124,11 @@ public class Counter { self.description = ""; } if (tags is map) { - self.metricTags = tags; + self.metricTags = tags.cloneReadOnly(); } else { - self.metricTags = DEFAULT_TAGS; + lock { + self.metricTags = DEFAULT_TAGS.cloneReadOnly(); + } } externCounterInit(self); } @@ -135,7 +137,7 @@ public class Counter { # # + return - Returns error if there is any metric registered already with the same name # but different parameters or in a different kind - public function register() returns error? { + public isolated function register() returns error? { return externCounterRegister(self); } @@ -148,7 +150,7 @@ public class Counter { # # + amount - The amount by which the value needs to be increased. The amount is defaulted as 1 and will be # used if there is no amount passed in - public function increment(int amount = 1) { + public isolated function increment(int amount = 1) { externCounterIncrement(self, amount); } @@ -160,7 +162,7 @@ public class Counter { # Retrieves the counter's current value. # # + return - The current value of the counter - public function getValue() returns int { + public isolated function getValue() returns int { return externCounterGetValue(self); } } @@ -203,12 +205,12 @@ isolated function externCounterGetValue(Counter counter) returns int = @java:Met # + metricTags - Tags associated with the counter metric # + statisticConfigs - Array of StatisticConfig objects which defines about the statistical calculation # of the gauge during its usage -public class Gauge { +public isolated class Gauge { - public string name; - public string description; - public map metricTags; - public StatisticConfig[] statisticConfigs; + public final string name; + public final string description; + public final map & readonly metricTags; + public final StatisticConfig[] & readonly statisticConfigs; # This instantiates the Gauge object. Name field is mandatory, and description, tags, and statitics config fields # are optional and have its own default values when no params are passed. @@ -221,12 +223,16 @@ public class Gauge { # statistics configurations array is passed, then statistics calculation will be disabled. # If nil () is passed, then default statistics configs will be used for the statitics # calculation - public function init(string name, string? desc = "", map? tags = (), + public isolated function init(string name, string? desc = "", map? tags = (), StatisticConfig[]? statisticConfig = ()) { self.name = name; self.description = desc ?: ""; - self.metricTags = tags ?: DEFAULT_TAGS; - self.statisticConfigs = statisticConfig ?: DEFAULT_GAUGE_STATS_CONFIG; + lock { + self.metricTags = tags.cloneReadOnly() ?: DEFAULT_TAGS.cloneReadOnly(); + } + lock { + self.statisticConfigs = statisticConfig.cloneReadOnly() ?: DEFAULT_GAUGE_STATS_CONFIG.cloneReadOnly(); + } externGaugeInit(self); } @@ -234,12 +240,12 @@ public class Gauge { # # + return - Returns error if there is any metric registered already with the same name # but different parameters or in a different kind - public function register() returns error? { + public isolated function register() returns error? { return externGaugeRegister(self); } # Unregister the counter metric instance with the Metric Registry. - public function unregister() { + public isolated function unregister() { externGaugeUnRegister(self); } @@ -247,7 +253,7 @@ public class Gauge { # # + amount - The amount by which the value of gauge needs to be increased. # The amount is defaulted as 1.0 and will be used if there is no amount passed in - public function increment(float amount = 1.0) { + public isolated function increment(float amount = 1.0) { externGaugeIncrement(self, amount); } @@ -255,21 +261,21 @@ public class Gauge { # # + amount - The amount by which the value of gauge needs to be decreased. # The amount is defaulted as 1.0 and will be used if there is no amount passed in - public function decrement(float amount = 1.0) { + public isolated function decrement(float amount = 1.0) { externGaugeDecrement(self, amount); } # Sets the instantaneous value for gauge. # # + amount - The instantaneous value that needs to be set as gauge value - public function setValue(float amount) { + public isolated function setValue(float amount) { return externGaugeSetValue(self, amount); } # Retrieves the gauge's current value. # # + return - The current value of the gauge - public function getValue() returns float { + public isolated function getValue() returns float { return externGaugeGetValue(self); } @@ -277,7 +283,7 @@ public class Gauge { # # + return - Array of the statistics snapshots. # If there is no statisticsConfigs provided, then it will be nil - public function getSnapshot() returns Snapshot[]? { + public isolated function getSnapshot() returns Snapshot[]? { return externGaugeGetSnapshot(self); } } diff --git a/gradle.properties b/gradle.properties index 4fea060..7631eba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ org.gradle.caching=true group=io.ballerina.stdlib -version=1.2.2-SNAPSHOT +version=1.3.0-SNAPSHOT ballerinaLangVersion=2201.8.0 githubSpotbugsVersion=5.0.14 githubJohnrengelmanShadowVersion=8.1.1 From c79fd58cd2d37c98bfd65f574bde6cdc62db97ba Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 May 2024 12:09:55 +0530 Subject: [PATCH 05/13] Remove extra space --- ballerina/natives.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 9ee5544..06128c2 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -207,7 +207,7 @@ isolated function externCounterGetValue(Counter counter) returns int = @java:Met # of the gauge during its usage public isolated class Gauge { - public final string name; + public final string name; public final string description; public final map & readonly metricTags; public final StatisticConfig[] & readonly statisticConfigs; From da130c1c8f900d0e049bf071f50a936621f4e96e Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Tue, 14 May 2024 14:15:54 +0530 Subject: [PATCH 06/13] Fix uploading codecov report --- .github/workflows/daily-build.yml | 66 ++++++++++++++++++++++++++++++ .github/workflows/pull-request.yml | 6 ++- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/daily-build.yml diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml new file mode 100644 index 0000000..da964a2 --- /dev/null +++ b/.github/workflows/daily-build.yml @@ -0,0 +1,66 @@ +name: Daily build + +on: + schedule: + - cron: '30 18 * * *' + workflow_dispatch: + +jobs: + ubuntu-build: + name: Build on Ubuntu + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17.0.7 + - name: Build with Gradle + env: + packageUser: ${{ github.actor }} + packagePAT: ${{ secrets.GITHUB_TOKEN }} + run: | + ./gradlew build test --stacktrace --console=plain + - name: Generate Codecov Report + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + windows-build: + name: Build on Windows + runs-on: windows-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17.0.7 + - name: Build with Gradle + env: + packageUser: ${{ github.actor }} + packagePAT: ${{ secrets.GITHUB_TOKEN }} + JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 + run: | + ./gradlew.bat build -x test --stacktrace --console=plain + ./gradlew.bat test --stacktrace --console=plain + + ubuntu-build-without-native-tests: + name: Build on Ubuntu without native tests + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17.0.7 + - name: Build with Gradle + env: + packageUser: ${{ github.actor }} + packagePAT: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew build -x observe-ballerina-tests:test --stacktrace --console=plain diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 79e3b21..d67c2b7 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,7 +21,9 @@ jobs: run: | ./gradlew build test --stacktrace --console=plain - name: Generate Codecov Report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} windows-build: name: Build on Windows @@ -32,7 +34,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v2 with: - distribution: 'adopt' + distribution: 'temurin' java-version: 17.0.7 - name: Build with Gradle env: From b0ec6d6b10ce77dc908167a04604b4d4bede1edc Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 4 Jul 2024 17:28:32 +0530 Subject: [PATCH 07/13] Address review suggestions --- ballerina/natives.bal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 06128c2..162fe85 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -19,7 +19,7 @@ import ballerina/jballerina.java; isolated final StatisticConfig[] DEFAULT_GAUGE_STATS_CONFIG = [{ timeWindow: 600000, buckets: 5, percentiles: [0.33, 0.5, 0.66, 0.75, 0.95, 0.99, 0.999] }]; -isolated final map DEFAULT_TAGS = {}; +isolated final map defaultTags = {}; # Start a span with no parent span. # @@ -105,7 +105,7 @@ public isolated function lookupMetric(string name, map? tags = ()) retur # + metricTags - Tags associated with the counter metric public isolated class Counter { - public final string name; + public final string name; public final string description; public final map & readonly metricTags; @@ -127,7 +127,7 @@ public isolated class Counter { self.metricTags = tags.cloneReadOnly(); } else { lock { - self.metricTags = DEFAULT_TAGS.cloneReadOnly(); + self.metricTags = defaultTags.cloneReadOnly(); } } externCounterInit(self); @@ -228,7 +228,7 @@ public isolated class Gauge { self.name = name; self.description = desc ?: ""; lock { - self.metricTags = tags.cloneReadOnly() ?: DEFAULT_TAGS.cloneReadOnly(); + self.metricTags = tags.cloneReadOnly() ?: defaultTags.cloneReadOnly(); } lock { self.statisticConfigs = statisticConfig.cloneReadOnly() ?: DEFAULT_GAUGE_STATS_CONFIG.cloneReadOnly(); From c3608841acaf932f37855e0e921b111766df0278 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 14:50:38 +0530 Subject: [PATCH 08/13] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 61f019c..c3947d5 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.0" +distribution-version = "2201.10.0-20240802-124900-0b8d2ff7" [[package]] org = "ballerina" From 31835574ee270c5c65e41841b9872037459a0adb Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 14:51:11 +0530 Subject: [PATCH 09/13] Update lang version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1694ae4..d6e0541 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=1.3.0-SNAPSHOT -ballerinaLangVersion=2201.8.0 +ballerinaLangVersion=2201.10.0-20240802-124900-0b8d2ff7 githubSpotbugsVersion=5.0.14 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=5.4.0 From 68d1fe41bfb625142468a785f0ddab8e5d585c5e Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 15:05:13 +0530 Subject: [PATCH 10/13] Update distribution version --- ballerina/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 0fce066..7bffbbc 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ org = "ballerina" name = "observe" version = "1.3.0" -distribution = "2201.8.0" +distribution = "2201.10.0" export = ["observe", "observe.mockextension" ] [platform.java17] From b815b065895292ccd848333ebcfb97d4c9231cbf Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 15:15:36 +0530 Subject: [PATCH 11/13] Update distribution version --- build-config/resources/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index f52dcbe..ae34269 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -2,7 +2,7 @@ org = "ballerina" name = "observe" version = "@toml.version@" -distribution = "2201.8.0" +distribution = "2201.10.0" export = ["observe", "observe.mockextension" ] [platform.java17] From 71215d631185a095fda18ffccbdddb0dfe441bc2 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 16:21:01 +0530 Subject: [PATCH 12/13] Address review suggestions --- ballerina/natives.bal | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 162fe85..6692c4d 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -16,10 +16,10 @@ import ballerina/jballerina.java; -isolated final StatisticConfig[] DEFAULT_GAUGE_STATS_CONFIG = [{ timeWindow: 600000, buckets: 5, +final StatisticConfig[] & readonly defaultGaugeStatsConfig = [{ timeWindow: 600000, buckets: 5, percentiles: [0.33, 0.5, 0.66, 0.75, 0.95, 0.99, 0.999] }]; -isolated final map defaultTags = {}; +const map DEFAULT_TAGS = {}; # Start a span with no parent span. # @@ -126,9 +126,7 @@ public isolated class Counter { if (tags is map) { self.metricTags = tags.cloneReadOnly(); } else { - lock { - self.metricTags = defaultTags.cloneReadOnly(); - } + self.metricTags = DEFAULT_TAGS; } externCounterInit(self); } @@ -227,12 +225,8 @@ public isolated class Gauge { StatisticConfig[]? statisticConfig = ()) { self.name = name; self.description = desc ?: ""; - lock { - self.metricTags = tags.cloneReadOnly() ?: defaultTags.cloneReadOnly(); - } - lock { - self.statisticConfigs = statisticConfig.cloneReadOnly() ?: DEFAULT_GAUGE_STATS_CONFIG.cloneReadOnly(); - } + self.metricTags = tags.cloneReadOnly() ?: DEFAULT_TAGS; + self.statisticConfigs = statisticConfig.cloneReadOnly() ?: defaultGaugeStatsConfig; externGaugeInit(self); } From 0c54a06b70900e8f60df62072d06be508808f9b2 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 2 Aug 2024 17:31:39 +0530 Subject: [PATCH 13/13] Address review suggestions --- ballerina/natives.bal | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ballerina/natives.bal b/ballerina/natives.bal index 6692c4d..ca77e69 100644 --- a/ballerina/natives.bal +++ b/ballerina/natives.bal @@ -123,11 +123,7 @@ public isolated class Counter { } else { self.description = ""; } - if (tags is map) { - self.metricTags = tags.cloneReadOnly(); - } else { - self.metricTags = DEFAULT_TAGS; - } + self.metricTags = tags is map ? tags.cloneReadOnly() : DEFAULT_TAGS; externCounterInit(self); } @@ -225,8 +221,8 @@ public isolated class Gauge { StatisticConfig[]? statisticConfig = ()) { self.name = name; self.description = desc ?: ""; - self.metricTags = tags.cloneReadOnly() ?: DEFAULT_TAGS; - self.statisticConfigs = statisticConfig.cloneReadOnly() ?: defaultGaugeStatsConfig; + self.metricTags = tags is () ? DEFAULT_TAGS : tags.cloneReadOnly(); + self.statisticConfigs = statisticConfig is () ? defaultGaugeStatsConfig : statisticConfig.cloneReadOnly(); externGaugeInit(self); }