From 886b13c1823186742950210d447aac4e2dfe2952 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Fri, 10 Feb 2023 17:14:56 +0530 Subject: [PATCH 1/9] Update AzureBackendClient.java Only Send SampleData and Response payload if error Occured. --- .../jmeter/backendlistener/azure/AzureBackendClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java index dd596cf..f452e94 100644 --- a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java +++ b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java @@ -213,7 +213,8 @@ private void trackRequest(String name, SampleResult sr) { if (sr.getURL() != null) { req.setUrl(sr.getURL()); } - +if (sr.getErrorCount() != 0) +{ if (logSampleData) { req.getProperties().put("SampleData", sr.getSamplerData()); } @@ -221,7 +222,7 @@ private void trackRequest(String name, SampleResult sr) { if (logResponseData) { properties.put("ResponseData", sr.getResponseDataAsString()); } - + } MapUtil.copy(properties, req.getProperties()); telemetryClient.trackRequest(req); } From 2368b5ed2c310165ff64a9ac3c0b8b165ca116a5 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:24:47 +0530 Subject: [PATCH 2/9] Added Changes rekated to giving option to choose from onError/always which can be selected by user to send the response Data and SampleData to App Insights. --- .../azure/AzureBackendClient.java | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java index f452e94..95e878c 100644 --- a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java +++ b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java @@ -43,8 +43,10 @@ public class AzureBackendClient extends AbstractBackendListenerClient { private static final String KEY_CUSTOM_PROPERTIES_PREFIX = "ai."; private static final String KEY_HEADERS_PREFIX = "aih."; private static final String KEY_RESPONSE_HEADERS = "responseHeaders"; - private static final String KEY_LOG_RESPONSE_DATA = "logResponseData"; - private static final String KEY_LOG_SAMPLE_DATA = "logSampleData"; + //private static final String KEY_LOG_RESPONSE_DATA = "logResponseData"; + private static final String KEY_LOG_RESPONSE_DATA_OPTION = "logResponseDataOption"; + //private static final String KEY_LOG_SAMPLE_DATA = "logSampleData"; + private static final String KEY_LOG_SAMPLE_DATA_OPTION = "logResponseDataOption"; /** * Default argument values. @@ -54,8 +56,10 @@ public class AzureBackendClient extends AbstractBackendListenerClient { private static final boolean DEFAULT_LIVE_METRICS = true; private static final String DEFAULT_SAMPLERS_LIST = ""; private static final boolean DEFAULT_USE_REGEX_FOR_SAMPLER_LIST = false; - private static final boolean DEFAULT_LOG_RESPONSE_DATA = false; - private static final boolean DEFAULT_LOG_SAMPLE_DATA = false; + //private static final boolean DEFAULT_LOG_RESPONSE_DATA = false; + private static final String DEFAULT_LOG_RESPONSE_DATA_OPTION = "OnError"; + //private static final boolean DEFAULT_LOG_SAMPLE_DATA = false; + private static final String DEFAULT_LOG_SAMPLE_DATA_OPTION = "onError"; /** * Separator for samplers list. @@ -105,12 +109,21 @@ public class AzureBackendClient extends AbstractBackendListenerClient { /** * Whether to log the response data to the backend */ - private boolean logResponseData; + //private boolean logResponseData; + /** + * Option value selected for response data which can be sent to the backend + */ + private String logResponseDataOption; /** * Whether to log the sample data to the backend */ - private boolean logSampleData; + //private boolean logSampleData; + + /** + * Option value selected for sample data which can be sent to the backend + */ + private String logSampleDataOption; public AzureBackendClient() { super(); @@ -124,8 +137,10 @@ public Arguments getDefaultParameters() { arguments.addArgument(KEY_LIVE_METRICS, Boolean.toString(DEFAULT_LIVE_METRICS)); arguments.addArgument(KEY_SAMPLERS_LIST, DEFAULT_SAMPLERS_LIST); arguments.addArgument(KEY_USE_REGEX_FOR_SAMPLER_LIST, Boolean.toString(DEFAULT_USE_REGEX_FOR_SAMPLER_LIST)); - arguments.addArgument(KEY_LOG_RESPONSE_DATA, Boolean.toString(DEFAULT_LOG_RESPONSE_DATA)); - arguments.addArgument(KEY_LOG_SAMPLE_DATA, Boolean.toString(DEFAULT_LOG_SAMPLE_DATA)); + //arguments.addArgument(KEY_LOG_RESPONSE_DATA, Boolean.toString(DEFAULT_LOG_RESPONSE_DATA)); + arguments.addArgument(KEY_LOG_RESPONSE_DATA_OPTION, DEFAULT_LOG_RESPONSE_DATA_OPTION); + //arguments.addArgument(KEY_LOG_SAMPLE_DATA, Boolean.toString(DEFAULT_LOG_SAMPLE_DATA)); + arguments.addArgument(KEY_LOG_SAMPLE_DATA_OPTION, DEFAULT_LOG_SAMPLE_DATA_OPTION); return arguments; } @@ -136,8 +151,13 @@ public void setupTest(BackendListenerContext context) throws Exception { liveMetrics = context.getBooleanParameter(KEY_LIVE_METRICS, DEFAULT_LIVE_METRICS); samplersList = context.getParameter(KEY_SAMPLERS_LIST, DEFAULT_SAMPLERS_LIST).trim(); useRegexForSamplerList = context.getBooleanParameter(KEY_USE_REGEX_FOR_SAMPLER_LIST, DEFAULT_USE_REGEX_FOR_SAMPLER_LIST); - logResponseData = context.getBooleanParameter(KEY_LOG_RESPONSE_DATA, DEFAULT_LOG_RESPONSE_DATA); - logSampleData = context.getBooleanParameter(KEY_LOG_SAMPLE_DATA, DEFAULT_LOG_SAMPLE_DATA); + //logResponseData = context.getBooleanParameter(KEY_LOG_RESPONSE_DATA, DEFAULT_LOG_RESPONSE_DATA); + logResponseDataOption = context.getParameter(KEY_LOG_RESPONSE_DATA_OPTION, DEFAULT_LOG_RESPONSE_DATA_OPTION); + //logSampleData = context.getBooleanParameter(KEY_LOG_SAMPLE_DATA, DEFAULT_LOG_SAMPLE_DATA); + logSampleDataOption = context.getParameter(KEY_LOG_SAMPLE_DATA_OPTION, DEFAULT_LOG_SAMPLE_DATA_OPTION); + log.warn("Logging Response Data on "+logResponseDataOption); + log.warn("Logging Sample Data on "+logSampleDataOption); + Iterator iterator = context.getParameterNamesIterator(); while (iterator.hasNext()) { @@ -213,16 +233,30 @@ private void trackRequest(String name, SampleResult sr) { if (sr.getURL() != null) { req.setUrl(sr.getURL()); } -if (sr.getErrorCount() != 0) -{ - if (logSampleData) { +// Verify what Option for SampleData Collection is Selected if 'onError' is Selected And Error is observed, Log it + if (logSampleDataOption.equals("onError")) { + // If There is error Reported Log the Message + if (sr.getErrorCount() != 0) + { + req.getProperties().put("SampleData", sr.getSamplerData()); + } + } + // Else Check if 'always' Selected, Always Log Sample Data + else if (logSampleDataOption.equals("always")) { req.getProperties().put("SampleData", sr.getSamplerData()); } - if (logResponseData) { +// Verify what Option for ResponseData Collection is Selected if 'onError' is Selected And Error is observed, Log it + if (logResponseDataOption.equals("onError")) { + if (sr.getErrorCount() != 0) { + properties.put("ResponseData", sr.getResponseDataAsString()); + } + } + // Else Check if 'always' Selected, Always Log Response Data + else if (logResponseDataOption.equals("always")) { properties.put("ResponseData", sr.getResponseDataAsString()); } - } + MapUtil.copy(properties, req.getProperties()); telemetryClient.trackRequest(req); } From 79eeaa7aa599d6b7a30a12b626e31aca9401f788 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:40:44 +0530 Subject: [PATCH 3/9] Create maven-publish.1yml --- .github/workflows/maven-publish.1yml | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/maven-publish.1yml diff --git a/.github/workflows/maven-publish.1yml b/.github/workflows/maven-publish.1yml new file mode 100644 index 0000000..56f27e8 --- /dev/null +++ b/.github/workflows/maven-publish.1yml @@ -0,0 +1,43 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn -B package --file pom.xml + with: + name: jmeter-backendlistener-azure + path: target/*.jar + !target/*-javadoc.jar + !target/*-sources.jar + !target/original-*.jar + if-no-files-found: warn + env: + JAVA_HOME: /opt/hostedtoolcache/Java_Zulu_jdk/8.0.362-9/x64 + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} From 4be0b7e15b41bf155555d24ecc0923b98b005946 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:43:06 +0530 Subject: [PATCH 4/9] Added Steps to upload an Artifact --- .github/workflows/maven-publish.1yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/maven-publish.1yml b/.github/workflows/maven-publish.1yml index 56f27e8..1423f0f 100644 --- a/.github/workflows/maven-publish.1yml +++ b/.github/workflows/maven-publish.1yml @@ -27,16 +27,17 @@ jobs: - name: Build with Maven run: mvn -B package --file pom.xml - with: - name: jmeter-backendlistener-azure - path: target/*.jar - !target/*-javadoc.jar - !target/*-sources.jar - !target/original-*.jar - if-no-files-found: warn - env: - JAVA_HOME: /opt/hostedtoolcache/Java_Zulu_jdk/8.0.362-9/x64 - + + - name: Attach JAR as artifact + uses: actions/upload-artifact@v3 + with: + name: jmeter-backendlistener-azure + path: | + target/*.jar + !target/*-javadoc.jar + !target/*-sources.jar + !target/original-*.jar + - name: Publish to GitHub Packages Apache Maven run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml env: From e0a5b00773965c1cd77c686b5e2418be61592ffb Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 15:49:26 +0530 Subject: [PATCH 5/9] Update maven-publish.1yml --- .github/workflows/maven-publish.1yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/maven-publish.1yml b/.github/workflows/maven-publish.1yml index 1423f0f..0e699c7 100644 --- a/.github/workflows/maven-publish.1yml +++ b/.github/workflows/maven-publish.1yml @@ -3,9 +3,7 @@ name: Maven Package -on: - release: - types: [created] +on: [push, pull_request, workflow_dispatch] jobs: build: From a3f1cdcfa3fb374b8758cd995f9901db9e8996e3 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:38:13 +0530 Subject: [PATCH 6/9] Fixed the Typo in VariableName --- .../jmeter/backendlistener/azure/AzureBackendClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java index 95e878c..0603777 100644 --- a/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java +++ b/src/main/java/io/github/adrianmo/jmeter/backendlistener/azure/AzureBackendClient.java @@ -46,7 +46,7 @@ public class AzureBackendClient extends AbstractBackendListenerClient { //private static final String KEY_LOG_RESPONSE_DATA = "logResponseData"; private static final String KEY_LOG_RESPONSE_DATA_OPTION = "logResponseDataOption"; //private static final String KEY_LOG_SAMPLE_DATA = "logSampleData"; - private static final String KEY_LOG_SAMPLE_DATA_OPTION = "logResponseDataOption"; + private static final String KEY_LOG_SAMPLE_DATA_OPTION = "logSampleDataOption"; /** * Default argument values. @@ -57,7 +57,7 @@ public class AzureBackendClient extends AbstractBackendListenerClient { private static final String DEFAULT_SAMPLERS_LIST = ""; private static final boolean DEFAULT_USE_REGEX_FOR_SAMPLER_LIST = false; //private static final boolean DEFAULT_LOG_RESPONSE_DATA = false; - private static final String DEFAULT_LOG_RESPONSE_DATA_OPTION = "OnError"; + private static final String DEFAULT_LOG_RESPONSE_DATA_OPTION = "onError"; //private static final boolean DEFAULT_LOG_SAMPLE_DATA = false; private static final String DEFAULT_LOG_SAMPLE_DATA_OPTION = "onError"; From 774ef61afd51c147a91afaa3c29b995a30349142 Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:44:23 +0530 Subject: [PATCH 7/9] Made Changes Related to Option Selection Added Comments for responseDataOption and sampleDataOption field to be selected by user --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89a8d69..5f4b989 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Then, in the Parameters table, configure the following attributes. | *samplersList* | Optional list of samplers separated by a semi-colon (`;`) that the listener will collect and send metrics to Application Insights. If the list is empty, the listener will not filter samplers and send metrics from all of them. Defaults to an empty string. | No | | *useRegexForSamplerList* | If set to `true` the `samplersList` will be evaluated as a regex to filter samplers. Defaults to `false`. | No | | *responseHeaders* | Optional list of response headers separated by a semi-colon (`;`) that the listener will collect and send values to Application Insights. | No | -| *logResponseData* | Boolean to indicate whether or not the response data should be captured. If set to `true`, the response data will be captured as a string into the _ResponseData_ property. Defaults to `false`. | No | -| *logSampleData* | Boolean to indicate whether or not the sample data should be captured. If set to `true`, the sample data will be captured as a string into the _SampleData_ property. Defaults to `false`. | No | +| *logResponseDataOption* | Option to Selected "onError"/"always"/"None", if onError is selected if any sample fails ResponseData of that sample will also be logged and incase of always, responseData will be saved adlways , if selected Nothing/None, ReponseData will never be saved Defaults to `onError`. | No | +| *logSampleDataOption* | Option to Selected "onError"/"always"/"None", if onError is selected if any sample fails SanpleData of that sample will also be logged and incase of always, SampleData will be saved adlways , if selected Nothing/None, SampleData will never be saved Defaults to `onError`. | No | | *instrumentationKey* | The Instrumentation Key of your Application Insights instance.
⚠️ **Deprecated**: use *connectionString* instead. | No | *Example of configuration:* From bb3edd8693c7efa3a8e1e61cef42d4181f5f6aed Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:46:26 +0530 Subject: [PATCH 8/9] updated image for configuration --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f4b989..b1c9246 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,7 @@ Then, in the Parameters table, configure the following attributes. | *instrumentationKey* | The Instrumentation Key of your Application Insights instance.
⚠️ **Deprecated**: use *connectionString* instead. | No | *Example of configuration:* - -![Screenshot of configuration](docs/configuration.jpg "Screenshot of JMeter configuration") +![image](https://user-images.githubusercontent.com/46219412/232789063-023f578e-069c-4f29-bf7c-64292f1aaa0c.png) #### Custom properties From b0e6ee9a26e6ef16f2279bf432b62268dbb2067e Mon Sep 17 00:00:00 2001 From: Surender Sharma <46219412+ssharmasurender3@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:36:11 +0530 Subject: [PATCH 9/9] Delete maven-publish.1yml --- .github/workflows/maven-publish.1yml | 42 ---------------------------- 1 file changed, 42 deletions(-) delete mode 100644 .github/workflows/maven-publish.1yml diff --git a/.github/workflows/maven-publish.1yml b/.github/workflows/maven-publish.1yml deleted file mode 100644 index 0e699c7..0000000 --- a/.github/workflows/maven-publish.1yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path - -name: Maven Package - -on: [push, pull_request, workflow_dispatch] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Attach JAR as artifact - uses: actions/upload-artifact@v3 - with: - name: jmeter-backendlistener-azure - path: | - target/*.jar - !target/*-javadoc.jar - !target/*-sources.jar - !target/original-*.jar - - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml - env: - GITHUB_TOKEN: ${{ github.token }}