From 8debde2560040e9b2a5bf7d3c50c9bbf62ea0b7e Mon Sep 17 00:00:00 2001 From: rodrimendoza Date: Thu, 8 May 2025 15:27:50 +0200 Subject: [PATCH 1/4] Cache support --- README.md | 18 ++++++++++++++++++ action.yml | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/README.md b/README.md index 575a758..3d8f989 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ The action has the following parameters: | api_key | Datadog API key. Can be found at https://app.datadoghq.com/organization-settings/api-keys | true | | | site | Datadog site. See https://docs.datadoghq.com/getting_started/site for more information about sites. | false | datadoghq.com | | service | The name of the service or library being tested. | false | | +| enable-cache | Enable caching of Datadog tracers and dependencies to speed up workflow runs. | false | true | +| cache-key | Custom cache key to use for caching. If not provided, a default key will be generated based on the languages and tracer versions. | false | | | dotnet-tracer-version | The version of Datadog .NET tracer to use. Defaults to the latest release. | false | | | java-tracer-version | The version of Datadog Java tracer to use. Defaults to the latest release. | false | | | js-tracer-version | The version of Datadog JS tracer to use. Defaults to the latest release. | false | | @@ -49,6 +51,22 @@ The action has the following parameters: | go-tracer-version | The version of Orchestrion to use. Defaults to the latest release. | false | | | java-instrumented-build-system | If provided, only the specified build systems will be instrumented (allowed values are `gradle`,`maven`,`sbt`,`ant`,`all`). `all` is a special value that instruments every Java process. If this property is not provided, all known build systems will be instrumented (Gradle, Maven, SBT, Ant). | false | | +### Caching + +The action supports caching of Datadog tracers and dependencies to speed up workflow runs. Caching is enabled by default but can be disabled by setting `enable-cache: false`. The cache key is automatically generated based on the languages and tracer versions, but you can provide a custom cache key using the `cache-key` parameter. + +Example with custom cache key: +```yaml +steps: + - name: Configure Datadog Test Optimization + uses: datadog/test-visibility-github-action@v2 + with: + languages: java + api_key: ${{ secrets.DD_API_KEY }} + enable-cache: true + cache-key: my-custom-cache-key +``` + ### Additional configuration Any [additional configuration values](https://docs.datadoghq.com/tracing/trace_collection/library_config/) can be added directly to the step that runs your tests: diff --git a/action.yml b/action.yml index e17350c..a905490 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,13 @@ inputs: service: description: 'The name of the service or library being tested.' required: false + enable-cache: + description: 'Enable caching of Datadog tracers and dependencies to speed up workflow runs.' + required: false + default: 'true' + cache-key: + description: 'Custom cache key to use for caching. If not provided, a default key will be generated based on the languages and tracer versions.' + required: false dotnet-tracer-version: description: 'The version of Datadog .NET tracer to use (optional). Defaults to the latest release.' required: false @@ -57,8 +64,19 @@ runs: env: GITHUB_ACTION_PATH: ${{ github.action_path }} + - name: Set up cache + if: ${{ inputs.enable-cache == 'true' }} + uses: actions/cache@v3 + id: cache + with: + path: ${{ github.workspace }}/.datadog + key: ${{ inputs.cache-key || format('dd-test-visibility-{0}-{1}-{2}-{3}-{4}-{5}', inputs.languages, inputs.dotnet-tracer-version, inputs.java-tracer-version, inputs.js-tracer-version, inputs.python-tracer-version, inputs.ruby-tracer-version) }} + restore-keys: | + dd-test-visibility-${{ inputs.languages }}- + - name: Download and run configuration script id: run-configuration-script + if: ${{ steps.cache.outputs.cache-hit != 'true' || inputs.enable-cache != 'true' }} run: | mkdir -p $GITHUB_WORKSPACE/.datadog From 826e03578aa6c87b1d6fecb5c8f852a8e9c1c98b Mon Sep 17 00:00:00 2001 From: rodrimendoza Date: Thu, 8 May 2025 15:33:53 +0200 Subject: [PATCH 2/4] Allow cache cleanup --- README.md | 32 ++++++++++++++++++++++++++++++++ action.yml | 14 ++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d8f989..bd89a11 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ The action has the following parameters: | site | Datadog site. See https://docs.datadoghq.com/getting_started/site for more information about sites. | false | datadoghq.com | | service | The name of the service or library being tested. | false | | | enable-cache | Enable caching of Datadog tracers and dependencies to speed up workflow runs. | false | true | +| force-cache-refresh | Force refresh the cache by ignoring any existing cache entries. Useful when cache contains incorrect data. | false | false | | cache-key | Custom cache key to use for caching. If not provided, a default key will be generated based on the languages and tracer versions. | false | | | dotnet-tracer-version | The version of Datadog .NET tracer to use. Defaults to the latest release. | false | | | java-tracer-version | The version of Datadog Java tracer to use. Defaults to the latest release. | false | | @@ -67,6 +68,37 @@ steps: cache-key: my-custom-cache-key ``` +#### Cache Cleaning + +If you encounter issues with cached data, you have two options to clean the cache: + +1. **Force Cache Refresh**: Use the `force-cache-refresh` parameter to ignore existing cache entries and create a fresh cache: +```yaml +steps: + - name: Configure Datadog Test Optimization + uses: datadog/test-visibility-github-action@v2 + with: + languages: java + api_key: ${{ secrets.DD_API_KEY }} + force-cache-refresh: true +``` + +2. **Manual Cache Deletion**: You can manually delete the cache for a specific key using the GitHub Actions Cache API. Create a workflow with the following step: +```yaml +steps: + - name: Delete Cache + uses: actions/github-script@v6 + with: + script: | + const cacheKey = 'dd-test-visibility-java-1.0.0-2.0.0-3.0.0-4.0.0-5.0.0-6.0.0'; // Replace with your cache key + const response = await github.rest.actions.deleteActionsCacheByKey({ + owner: context.repo.owner, + repo: context.repo.repo, + key: cacheKey + }); + console.log(`Cache deletion response: ${response.status}`); +``` + ### Additional configuration Any [additional configuration values](https://docs.datadoghq.com/tracing/trace_collection/library_config/) can be added directly to the step that runs your tests: diff --git a/action.yml b/action.yml index a905490..b090ab5 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,10 @@ inputs: description: 'Enable caching of Datadog tracers and dependencies to speed up workflow runs.' required: false default: 'true' + force-cache-refresh: + description: 'Force refresh the cache by ignoring any existing cache entries. Useful when cache contains incorrect data.' + required: false + default: 'false' cache-key: description: 'Custom cache key to use for caching. If not provided, a default key will be generated based on the languages and tracer versions.' required: false @@ -65,7 +69,7 @@ runs: GITHUB_ACTION_PATH: ${{ github.action_path }} - name: Set up cache - if: ${{ inputs.enable-cache == 'true' }} + if: ${{ inputs.enable-cache == 'true' && inputs.force-cache-refresh != 'true' }} uses: actions/cache@v3 id: cache with: @@ -74,9 +78,15 @@ runs: restore-keys: | dd-test-visibility-${{ inputs.languages }}- + - name: Clean cache directory if force refresh + if: ${{ inputs.force-cache-refresh == 'true' }} + run: | + rm -rf $GITHUB_WORKSPACE/.datadog + shell: bash + - name: Download and run configuration script id: run-configuration-script - if: ${{ steps.cache.outputs.cache-hit != 'true' || inputs.enable-cache != 'true' }} + if: ${{ steps.cache.outputs.cache-hit != 'true' || inputs.enable-cache != 'true' || inputs.force-cache-refresh == 'true' }} run: | mkdir -p $GITHUB_WORKSPACE/.datadog From db89c28aa15aa076dfccbe1f194ec839f7019b3e Mon Sep 17 00:00:00 2001 From: rodrimendoza Date: Thu, 8 May 2025 15:36:08 +0200 Subject: [PATCH 3/4] Allow cache cleanup --- README.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README.md b/README.md index bd89a11..a9c1253 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,8 @@ steps: #### Cache Cleaning -If you encounter issues with cached data, you have two options to clean the cache: +If you encounter issues with cached data, you can use the `force-cache-refresh` parameter to ignore existing cache entries and create a fresh cache: -1. **Force Cache Refresh**: Use the `force-cache-refresh` parameter to ignore existing cache entries and create a fresh cache: ```yaml steps: - name: Configure Datadog Test Optimization @@ -83,22 +82,6 @@ steps: force-cache-refresh: true ``` -2. **Manual Cache Deletion**: You can manually delete the cache for a specific key using the GitHub Actions Cache API. Create a workflow with the following step: -```yaml -steps: - - name: Delete Cache - uses: actions/github-script@v6 - with: - script: | - const cacheKey = 'dd-test-visibility-java-1.0.0-2.0.0-3.0.0-4.0.0-5.0.0-6.0.0'; // Replace with your cache key - const response = await github.rest.actions.deleteActionsCacheByKey({ - owner: context.repo.owner, - repo: context.repo.repo, - key: cacheKey - }); - console.log(`Cache deletion response: ${response.status}`); -``` - ### Additional configuration Any [additional configuration values](https://docs.datadoghq.com/tracing/trace_collection/library_config/) can be added directly to the step that runs your tests: From 96b4f85ac3b8507f411b429442b7c9f69c629b3f Mon Sep 17 00:00:00 2001 From: rodrimendoza Date: Thu, 8 May 2025 16:00:30 +0200 Subject: [PATCH 4/4] Renaming cache param --- README.md | 10 +++++----- action.yml | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a9c1253..c66d764 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ It can help you investigate and mitigate performance problems and test failures The action has the following parameters: | Name | Description | Required | Default | -| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------- | +|--------------------------------| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------- | | languages | List of languages to be instrumented. Can be either "all" or any of "java", "js", "python", "dotnet", "ruby", "go" (multiple languages can be specified as a space-separated list). | true | | | api_key | Datadog API key. Can be found at https://app.datadoghq.com/organization-settings/api-keys | true | | | site | Datadog site. See https://docs.datadoghq.com/getting_started/site for more information about sites. | false | datadoghq.com | | service | The name of the service or library being tested. | false | | -| enable-cache | Enable caching of Datadog tracers and dependencies to speed up workflow runs. | false | true | -| force-cache-refresh | Force refresh the cache by ignoring any existing cache entries. Useful when cache contains incorrect data. | false | false | +| cache | Enable caching of Datadog tracers and dependencies to speed up workflow runs. | false | true | +| force-cache-refresh | Force refresh the cache by ignoring any existing cache entries. Useful when cache contains incorrect data. | false | false | | cache-key | Custom cache key to use for caching. If not provided, a default key will be generated based on the languages and tracer versions. | false | | | dotnet-tracer-version | The version of Datadog .NET tracer to use. Defaults to the latest release. | false | | | java-tracer-version | The version of Datadog Java tracer to use. Defaults to the latest release. | false | | @@ -54,7 +54,7 @@ The action has the following parameters: ### Caching -The action supports caching of Datadog tracers and dependencies to speed up workflow runs. Caching is enabled by default but can be disabled by setting `enable-cache: false`. The cache key is automatically generated based on the languages and tracer versions, but you can provide a custom cache key using the `cache-key` parameter. +The action supports caching of Datadog tracers and dependencies to speed up workflow runs. Caching is enabled by default but can be disabled by setting `cache: false`. The cache key is automatically generated based on the languages and tracer versions, but you can provide a custom cache key using the `cache-key` parameter. Example with custom cache key: ```yaml @@ -64,7 +64,7 @@ steps: with: languages: java api_key: ${{ secrets.DD_API_KEY }} - enable-cache: true + cache: true cache-key: my-custom-cache-key ``` diff --git a/action.yml b/action.yml index b090ab5..d5c5622 100644 --- a/action.yml +++ b/action.yml @@ -17,7 +17,7 @@ inputs: service: description: 'The name of the service or library being tested.' required: false - enable-cache: + cache: description: 'Enable caching of Datadog tracers and dependencies to speed up workflow runs.' required: false default: 'true' @@ -69,7 +69,7 @@ runs: GITHUB_ACTION_PATH: ${{ github.action_path }} - name: Set up cache - if: ${{ inputs.enable-cache == 'true' && inputs.force-cache-refresh != 'true' }} + if: ${{ inputs.cache == 'true' && inputs.force-cache-refresh != 'true' }} uses: actions/cache@v3 id: cache with: @@ -86,7 +86,7 @@ runs: - name: Download and run configuration script id: run-configuration-script - if: ${{ steps.cache.outputs.cache-hit != 'true' || inputs.enable-cache != 'true' || inputs.force-cache-refresh == 'true' }} + if: ${{ steps.cache.outputs.cache-hit != 'true' || inputs.cache != 'true' || inputs.force-cache-refresh == 'true' }} run: | mkdir -p $GITHUB_WORKSPACE/.datadog