From 9009b8748e63bd6ca3cd667004022bc35eda8405 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Mon, 20 Apr 2020 18:45:29 +0200 Subject: [PATCH 1/7] add stats script --- .github/workflows/stats.yaml | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/stats.yaml diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml new file mode 100644 index 00000000000..a0888078e17 --- /dev/null +++ b/.github/workflows/stats.yaml @@ -0,0 +1,67 @@ +name: download-stats + +on: + push: + branches: + - massi/stats + schedule: + # run every 5 minutes + - cron: '*/5 * * * *' + +jobs: + push-stats: + runs-on: ubuntu-latest + + steps: + - name: Fetch downloads count + uses: actions/github-script@0.2.0 + with: + github-token: ${{github.token}} + script: | + let metrics = [] + + // Get a list of releases + const opts = github.repos.listReleases.endpoint.merge({ + ...context.repo + }) + const releases = await github.paginate(opts) + + // Get download stats for every release + for (const rel of releases) { + // Names for assets are like `arduino-cli_0.4.0_Linux_32bit.tar.gz`, + // we'll use this later to split the asset file name more easily + const baseName = `arduino-cli_${rel.name}_` + + // Get a list of assets for this release + const opts = github.repos.listAssetsForRelease.endpoint.merge({ + ...context.repo, + release_id: rel.id + }) + const assets = await github.paginate(opts) + + for (const asset of assets) { + // Ignore checksums file + if (asset.name.endsWith(".txt")) { + continue + } + + // Strip the base and remove file extension to get `Linux_32bit` + systemArch = asset.name.replace(baseName, "").split(".")[0].split("_") + + // Add a metric object to the list of gathered metrics + metrics.push({ + "type": "gauge", + "name": "arduino.downloads.total", + "value": asset.download_count, + "host": "${{ github.repository }}", + "tags": [ + `os:${systemArch[0]}`, + `arch:${systemArch[1]}`, + "cdn:github.com", + "project:arduino-cli" + ] + }) + } + } + + console.log(`::set-output name=metrics::${metrics}`) From 42b9d317a329636a95b4ee895e8312addb02f2bf Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Mon, 20 Apr 2020 18:59:24 +0200 Subject: [PATCH 2/7] send metrics --- .github/workflows/stats.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml index a0888078e17..c3dc51290fe 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/stats.yaml @@ -14,6 +14,7 @@ jobs: steps: - name: Fetch downloads count + id: fetch uses: actions/github-script@0.2.0 with: github-token: ${{github.token}} @@ -40,8 +41,8 @@ jobs: const assets = await github.paginate(opts) for (const asset of assets) { - // Ignore checksums file - if (asset.name.endsWith(".txt")) { + // Ignore files that are not arduino-cli packages + if (!asset.name.startsWith(baseName)) { continue } @@ -55,6 +56,7 @@ jobs: "value": asset.download_count, "host": "${{ github.repository }}", "tags": [ + `version:${rel.name}`, `os:${systemArch[0]}`, `arch:${systemArch[1]}`, "cdn:github.com", @@ -64,4 +66,10 @@ jobs: } } - console.log(`::set-output name=metrics::${metrics}`) + return metrics + + - name: Send metrics + uses: masci/datadog@v1 + with: + api-key: ${{ secrets.DD_API_KEY }} + metrics: ${{steps.fetch.outputs.result}} \ No newline at end of file From 0474f0dc1776e2bdb81b999879c96ab79cf7bfcf Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 21 Apr 2020 09:23:38 +0200 Subject: [PATCH 3/7] add failure event and comments --- .github/workflows/stats.yaml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml index c3dc51290fe..796fe3889a0 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/stats.yaml @@ -66,10 +66,28 @@ jobs: } } + // The action will put whatever we return from this function in + // `outputs.result`, JSON encoded. So we just return the array + // of objects and GitHub will do the rest. return metrics - name: Send metrics uses: masci/datadog@v1 with: api-key: ${{ secrets.DD_API_KEY }} - metrics: ${{steps.fetch.outputs.result}} \ No newline at end of file + // metrics input expects YAML but JSON will do the job + metrics: ${{steps.fetch.outputs.result}} + + - name: Report failure + if: failure() + uses: masci/datadog@v1 + with: + api-key: ${{ secrets.DD_API_KEY }} + events: | + - title: "Arduino CLI stats failing" + text: "Stats collection failed" + alert_type: "error" + host: ${{ github.repository }} + tags: + - "project:arduino-cli" + - "cdn:github.com" From e6518975f6fca5539566c4b472c5bdf57c69f4f4 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 21 Apr 2020 09:32:15 +0200 Subject: [PATCH 4/7] confusing languages --- .github/workflows/stats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml index 796fe3889a0..602d7d56631 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/stats.yaml @@ -75,7 +75,7 @@ jobs: uses: masci/datadog@v1 with: api-key: ${{ secrets.DD_API_KEY }} - // metrics input expects YAML but JSON will do the job + # Metrics input expects YAML but JSON will work just right. metrics: ${{steps.fetch.outputs.result}} - name: Report failure From 104f2f03039c8f5b268c9c50aa34003a71805d0e Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 21 Apr 2020 09:35:13 +0200 Subject: [PATCH 5/7] testing failures --- .github/workflows/stats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml index 602d7d56631..b011be67379 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/stats.yaml @@ -74,7 +74,7 @@ jobs: - name: Send metrics uses: masci/datadog@v1 with: - api-key: ${{ secrets.DD_API_KEY }} + api-key: ${{ secrets._DD_API_KEY }} # Metrics input expects YAML but JSON will work just right. metrics: ${{steps.fetch.outputs.result}} From 8feff8f104b2fe068072f140f5e1ebabfe4ad525 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 21 Apr 2020 09:36:29 +0200 Subject: [PATCH 6/7] revert, failures reporting works ok --- .github/workflows/stats.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stats.yaml b/.github/workflows/stats.yaml index b011be67379..602d7d56631 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/stats.yaml @@ -74,7 +74,7 @@ jobs: - name: Send metrics uses: masci/datadog@v1 with: - api-key: ${{ secrets._DD_API_KEY }} + api-key: ${{ secrets.DD_API_KEY }} # Metrics input expects YAML but JSON will work just right. metrics: ${{steps.fetch.outputs.result}} From 5a71dd3a86690eaac5eab35896bd3d9e48d67bc4 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 22 Apr 2020 18:27:55 +0200 Subject: [PATCH 7/7] rename file, remove test clause --- .github/workflows/{stats.yaml => github-stats.yaml} | 3 --- 1 file changed, 3 deletions(-) rename .github/workflows/{stats.yaml => github-stats.yaml} (98%) diff --git a/.github/workflows/stats.yaml b/.github/workflows/github-stats.yaml similarity index 98% rename from .github/workflows/stats.yaml rename to .github/workflows/github-stats.yaml index 602d7d56631..f246c879689 100644 --- a/.github/workflows/stats.yaml +++ b/.github/workflows/github-stats.yaml @@ -1,9 +1,6 @@ name: download-stats on: - push: - branches: - - massi/stats schedule: # run every 5 minutes - cron: '*/5 * * * *'