Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.12-slim

ENV DATADOG_SITE=datadoghq.eu

WORKDIR /app

COPY src/ ./
COPY requirements.txt ./
COPY entrypoint.sh ./

Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entrypoint.sh script needs execute permissions to run properly. Add a RUN command after the COPY operations to set execute permissions: RUN chmod +x entrypoint.sh get_usage_report.py send_to_datadog.py

Suggested change
RUN chmod +x entrypoint.sh

Copilot uses AI. Check for mistakes.
RUN pip install --no-cache-dir -r requirements.txt

ENTRYPOINT ["./entrypoint.sh"]
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ To learn more about graphs using python, check out [Matplotlib](https://matplotl
- An organisation ID is required. This defaults to the ID of the organisation that is executing the job on CircleCI.
- If sending metrics to Datadog, then a `DATADOG_API_KEY` is required.

## Docker Usage

To build the Docker image:

```sh
docker build --tag circleci-usage-api-exporter ./
```

To run the container (set environment variables as needed):

```sh
docker run --rm \
--env CIRCLECI_API_TOKEN=your_token \
--env DATADOG_API_KEY=your_datadog_key \
--env DATADOG_SITE=your_datadog_site \
--env START_DATE=2025-07-22 \
--env END_DATE=2025-07-23 \
--env MERGE_USAGE_REPORTS=false \
--env ORG_ID=your_org_id \
--env SEND_TO_DATADOG=true \
circleci-usage-api-exporter
```

or

```sh
docker run --env-file .env --rm circleci-usage-api-exporter
```

Adjust the environment variables as required for your use case.

### Caveats

- My python skillz aren't great.
Expand Down
16 changes: 16 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

./get_usage_report.py
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script assumes get_usage_report.py is executable, but the Dockerfile doesn't set execute permissions. This will cause a permission denied error when the container runs.

Copilot uses AI. Check for mistakes.

if [ "${SEND_TO_DATADOG}" = "true" ]; then
for csv_file in /tmp/reports/*.csv; do
# Check if the file actually exists (in case the glob didn't match anything)
if [ -e "$csv_file" ]; then
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to get_usage_report.py, this script assumes send_to_datadog.py is executable, but no execute permissions are set in the Dockerfile.

Suggested change
if [ -e "$csv_file" ]; then
if [ -e "$csv_file" ]; then
chmod +x ./send_to_datadog.py

Copilot uses AI. Check for mistakes.
./send_to_datadog.py --site "$DATADOG_SITE" "$csv_file"
else
echo "No CSV files found in /tmp/reports, skipping."
break
fi
done
fi
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
certifi==2025.7.14
charset-normalizer==3.4.2
datadog-api-client==2.40.0
idna==3.10
python-dateutil==2.9.0.post0
requests==2.32.4
six==1.17.0
typing_extensions==4.14.1
urllib3==2.5.0
1 change: 1 addition & 0 deletions src/get_usage_report.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# Import modules
import os
import requests
Expand Down
Empty file modified src/send_to_datadog.py
100644 → 100755
Empty file.