From 6ede0820604fc5914a7ca286785e286a887a3d06 Mon Sep 17 00:00:00 2001 From: Cees Bos Date: Wed, 25 Oct 2023 11:07:41 +0200 Subject: [PATCH 1/5] Use parent Call.Factory of OkHttpClient to be able to use OpenTelemetry --- .../java/com/microsoft/graph/core/BaseClient.java | 12 ++++++------ .../com/microsoft/graph/http/CoreHttpProvider.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/microsoft/graph/core/BaseClient.java b/src/main/java/com/microsoft/graph/core/BaseClient.java index cbdbac4e7..d6952b6ff 100644 --- a/src/main/java/com/microsoft/graph/core/BaseClient.java +++ b/src/main/java/com/microsoft/graph/core/BaseClient.java @@ -41,6 +41,7 @@ import javax.annotation.Nonnull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -137,7 +138,7 @@ public static Builder builder() { * @return builder to start configuring the client */ @Nonnull - public static Builder builder(@Nonnull final Class nativeClientClass, @Nonnull final Class nativeRequestClass) { + public static Builder builder(@Nonnull final Class nativeClientClass, @Nonnull final Class nativeRequestClass) { return new Builder<>(); } @@ -146,7 +147,7 @@ public static Builder * @param type of the native http library client * @param type of a request for the native http client */ - public static class Builder { + public static class Builder { private ISerializer serializer; private IHttpProvider httpProvider; private ILogger logger; @@ -174,10 +175,9 @@ private ISerializer getSerializer() { return serializer; } } - @SuppressWarnings("unchecked") - private httpClientType getHttpClient() { + private Call.Factory getHttpClient() { if(httpClient == null) { - return (httpClientType)HttpClients.createDefault(getAuthenticationProvider()); + return HttpClients.createDefault(getAuthenticationProvider()); } else { return httpClient; } @@ -185,7 +185,7 @@ private httpClientType getHttpClient() { @SuppressWarnings("unchecked") private IHttpProvider getHttpProvider() { if(httpProvider == null) { - return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), (OkHttpClient)getHttpClient()); + return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), getHttpClient()); } else { return httpProvider; } diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 7dea22c18..31f357643 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -98,9 +98,9 @@ public class CoreHttpProvider implements IHttpProvider { private final ILogger logger; /** - * The OkHttpClient that handles all requests + * The OkHttpClient(Call.Factory) that handles all requests */ - private OkHttpClient corehttpClient; + private Call.Factory corehttpClient; /** * Creates the CoreHttpProvider @@ -112,7 +112,7 @@ public class CoreHttpProvider implements IHttpProvider { @SuppressFBWarnings public CoreHttpProvider(@Nonnull final ISerializer serializer, @Nonnull final ILogger logger, - @Nonnull final OkHttpClient httpClient) { + @Nonnull final Call.Factory httpClient) { Objects.requireNonNull(logger, "parameter logger cannot be null"); Objects.requireNonNull(serializer, "parameter serializer cannot be null"); Objects.requireNonNull(httpClient, "parameter httpClient cannot be null"); From 8221a4a1391847e71b3a31501a858f310d192b0b Mon Sep 17 00:00:00 2001 From: Cees Bos Date: Wed, 25 Oct 2023 20:32:50 +0200 Subject: [PATCH 2/5] Remove usage of generics --- .../java/com/microsoft/graph/core/BaseClient.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/microsoft/graph/core/BaseClient.java b/src/main/java/com/microsoft/graph/core/BaseClient.java index d6952b6ff..27382a382 100644 --- a/src/main/java/com/microsoft/graph/core/BaseClient.java +++ b/src/main/java/com/microsoft/graph/core/BaseClient.java @@ -138,7 +138,7 @@ public static Builder builder() { * @return builder to start configuring the client */ @Nonnull - public static Builder builder(@Nonnull final Class nativeClientClass, @Nonnull final Class nativeRequestClass) { + public static Builder builder(@Nonnull final Class nativeClientClass, @Nonnull final Class nativeRequestClass) { return new Builder<>(); } @@ -147,7 +147,7 @@ public static Builder type of the native http library client * @param type of a request for the native http client */ - public static class Builder { + public static class Builder { private ISerializer serializer; private IHttpProvider httpProvider; private ILogger logger; @@ -175,9 +175,10 @@ private ISerializer getSerializer() { return serializer; } } - private Call.Factory getHttpClient() { + @SuppressWarnings("unchecked") + private httpClientType getHttpClient() { if(httpClient == null) { - return HttpClients.createDefault(getAuthenticationProvider()); + return (httpClientType)HttpClients.createDefault(getAuthenticationProvider()); } else { return httpClient; } @@ -185,7 +186,7 @@ private Call.Factory getHttpClient() { @SuppressWarnings("unchecked") private IHttpProvider getHttpProvider() { if(httpProvider == null) { - return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), getHttpClient()); + return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), (Call.Factory) getHttpClient()); } else { return httpProvider; } From 7da66034e57bd0454d1014a3fca4e630b3c96f4d Mon Sep 17 00:00:00 2001 From: Cees Bos Date: Wed, 25 Oct 2023 21:47:17 +0200 Subject: [PATCH 3/5] Update changelog and add info how to use OpenTelemetry with GraphServiceClient --- CHANGELOG.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27061f84c..2de0f1e60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Added +### Changed + +- Changed CoreHttpProvider dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient). This make usage of OpenTelemetry tracing possible. + https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/okhttp/okhttp-3.0/library/README.md + +```java + private Call.Factory createTracedClient(OpenTelemetry openTelemetry, @Nonnull final IAuthenticationProvider auth) { + return OkHttpTelemetry.builder(openTelemetry).build().newCallFactory(createClient(auth)); + } + + private OkHttpClient createClient(@Nonnull final IAuthenticationProvider auth) { + return HttpClients.createDefault(auth); + } + + // then create the GraphServiceClient + IAuthenticationProvider authenticationProvider = ...; + GraphServiceClient + .builder(Call.Factory.class, Request.class) + .httpClient(createTracedClient(openTelemetry, authenticationProvider)) + .authenticationProvider(authenticationProvider) + .buildClient(); +``` + ## [2.0.20] - 2023-10-23 From 69294af05c82ccdbc0152dee3c6d69bb3d89fea3 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 8 Nov 2023 08:31:20 -0500 Subject: [PATCH 4/5] - bumps patch version --- CHANGELOG.md | 7 ++++++- gradle.properties | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de0f1e60..b040e5bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +### Changed + +## [2.0.21] - 2023-11-08 + ### Changed - Changed CoreHttpProvider dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient). This make usage of OpenTelemetry tracing possible. @@ -30,7 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 .buildClient(); ``` - ## [2.0.20] - 2023-10-23 ### Changed diff --git a/gradle.properties b/gradle.properties index c270067b9..11030eaf9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 2 mavenMinorVersion = 0 -mavenPatchVersion = 20 +mavenPatchVersion = 21 mavenArtifactSuffix = #These values are used to run functional tests From 1dfcdb3fec019cf5f342ba097ac2176d133c8c64 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 8 Nov 2023 08:38:22 -0500 Subject: [PATCH 5/5] - adds a check secret step for the sonarcloud workflow to avoid failures on PRs --- .github/workflows/sonarcloud.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index c7b367340..02a328912 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -8,8 +8,24 @@ on: - feature/v2 pull_request: types: [opened, synchronize, reopened] + +env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + jobs: + checksecret: + name: check if SONAR_TOKEN is set in github secrets + runs-on: ubuntu-latest + outputs: + is_SONAR_TOKEN_set: ${{ steps.checksecret_job.outputs.is_SONAR_TOKEN_set }} + steps: + - name: Check whether unity activation requests should be done + id: checksecret_job + run: | + echo "is_SONAR_TOKEN_set=${{ env.SONAR_TOKEN != '' }}" >> $GITHUB_OUTPUT build: + needs: [checksecret] + if: needs.checksecret.outputs.is_SONAR_TOKEN_set == 'true' name: Build runs-on: ubuntu-latest steps: @@ -37,5 +53,4 @@ jobs: - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: ./gradlew build sonarqube --info