From b0d3c31b8673d7a2d410f105455aa59372e4cc38 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Mon, 5 Aug 2024 13:30:10 -0400 Subject: [PATCH 01/15] Create documents for local testing --- doc/dev/testing.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 doc/dev/testing.md diff --git a/doc/dev/testing.md b/doc/dev/testing.md new file mode 100644 index 000000000..7d418d77b --- /dev/null +++ b/doc/dev/testing.md @@ -0,0 +1,74 @@ +# Setting up local testing environment + +Inside the repo, set up a virtual environment and install dependencies +Commands: +* `python -m venv .venv` +* `source .venv/bin/activate` +* `pip install -e .` +* `pip install pytest` +* `pip install mock` + +Create a folder called `./vscode` +Inside the folder, create a file called `launch.json` with the following settings +``` +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} +``` +and also create a file a called settings.json with the following settings +``` +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} +``` + +You should now be able to run the unit tests locally +image + +Create a folder and a file inside the folder for testing with the following code + +e.g testapp/main.py +``` +from datadog import initialize, statsd +import time + +options = { + "statsd_host": "127.0.0.1", + "statsd_port": 8125, +} + +initialize(**options) + + +while(1): + statsd.increment('example_metric.increment', tags=["environment:dev"]) + statsd.decrement('example_metric.decrement', tags=["environment:dev"]) + time.sleep(10) +``` + +Install and run the agent (https://github.com/DataDog/datadog-agent) + +Command to run agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` + +Inside the main.py file that you just created, run the debugger to send logs to the agent. + From 310adbe1747b7779660a99c32541108e016d2961 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:50:44 -0400 Subject: [PATCH 02/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 7d418d77b..7e88869ad 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -8,7 +8,7 @@ Commands: * `pip install pytest` * `pip install mock` -Create a folder called `./vscode` +Create a folder called `./vscode`. Inside the folder, create a file called `launch.json` with the following settings ``` { From 6890aa71588a277f098ed2fcda99ccb225825a28 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:50:54 -0400 Subject: [PATCH 03/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 7e88869ad..d32f0f1de 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -9,7 +9,7 @@ Commands: * `pip install mock` Create a folder called `./vscode`. -Inside the folder, create a file called `launch.json` with the following settings +Inside the folder, create a file called `launch.json` with the following settings: ``` { // Use IntelliSense to learn about possible attributes. From d7ad09be8797c7ae052b3609539e58f28f662002 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:51:00 -0400 Subject: [PATCH 04/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index d32f0f1de..daf8c33e2 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,6 +1,6 @@ # Setting up local testing environment -Inside the repo, set up a virtual environment and install dependencies +Inside the repo, set up a virtual environment and install dependencies from the command line: Commands: * `python -m venv .venv` * `source .venv/bin/activate` From 111a8f417398d9c0e344d0744a90249b906e647d Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:51:12 -0400 Subject: [PATCH 05/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index daf8c33e2..889016f0f 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -27,7 +27,7 @@ Inside the folder, create a file called `launch.json` with the following setting ] } ``` -and also create a file a called settings.json with the following settings +Create a file called `settings.json` with the following settings: ``` { "python.testing.unittestArgs": [ From 7473069ee50c87f36c9d1c9950dad6b919eafc1b Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:51:35 -0400 Subject: [PATCH 06/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 889016f0f..e3fb3ca9f 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -66,7 +66,7 @@ while(1): time.sleep(10) ``` -Install and run the agent (https://github.com/DataDog/datadog-agent) +[Install the Agent](https://github.com/DataDog/datadog-agent). Command to run agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` From a27fb3e88a149b6755bc185efcaec29b5550d889 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:51:56 -0400 Subject: [PATCH 07/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index e3fb3ca9f..1068b84bd 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,4 +1,4 @@ -# Setting up local testing environment +# Setting up a local testing environment Inside the repo, set up a virtual environment and install dependencies from the command line: Commands: From be87fd24d1f7946da0da09f6d538ce4d1414ef55 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 13:57:27 -0400 Subject: [PATCH 08/15] Address all comments --- doc/dev/testing.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 1068b84bd..2c6f9c972 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,7 +1,6 @@ # Setting up a local testing environment Inside the repo, set up a virtual environment and install dependencies from the command line: -Commands: * `python -m venv .venv` * `source .venv/bin/activate` * `pip install -e .` @@ -42,12 +41,10 @@ Create a file called `settings.json` with the following settings: } ``` -You should now be able to run the unit tests locally +You should now be able to run the unit tests locally: image -Create a folder and a file inside the folder for testing with the following code - -e.g testapp/main.py +Create a folder for testing, such as `testapp/main.py`. Create a file inside the folder with the following code: ``` from datadog import initialize, statsd import time @@ -68,7 +65,9 @@ while(1): [Install the Agent](https://github.com/DataDog/datadog-agent). -Command to run agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` +Run the Agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` + +Inside the `main.py` file that you just created, run the debugger to send logs to the agent. -Inside the main.py file that you just created, run the debugger to send logs to the agent. +Those logs should appear in the [Log Explorer](https://dddev.datadoghq.com/logs?query=&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&fromUser=true&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=desc&viz=stream&from_ts=1722966102377&to_ts=1722967002377&live=true) in Datadog From 8391471502d84c7c97d38cf6f8ba427a631e480e Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Tue, 6 Aug 2024 14:12:04 -0400 Subject: [PATCH 09/15] Woops missed a change --- doc/dev/testing.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 2c6f9c972..6b3fc35c9 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,5 +1,6 @@ # Setting up a local testing environment +### Install dependencies Inside the repo, set up a virtual environment and install dependencies from the command line: * `python -m venv .venv` * `source .venv/bin/activate` @@ -7,6 +8,7 @@ Inside the repo, set up a virtual environment and install dependencies from the * `pip install pytest` * `pip install mock` +### Create config files Create a folder called `./vscode`. Inside the folder, create a file called `launch.json` with the following settings: ``` @@ -40,10 +42,12 @@ Create a file called `settings.json` with the following settings: "python.testing.unittestEnabled": true } ``` - +### Run unit tests locally in VS Code You should now be able to run the unit tests locally: + image +### Send logs to the agent Create a folder for testing, such as `testapp/main.py`. Create a file inside the folder with the following code: ``` from datadog import initialize, statsd From c5827282475336ca71c3ab0fcaa018aebc6521f5 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Mon, 9 Sep 2024 09:48:18 -0400 Subject: [PATCH 10/15] Update doc/dev/testing.md Co-authored-by: Brian Floersch --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 6b3fc35c9..965a37649 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,4 +1,4 @@ -# Setting up a local testing environment +# Setting up a local testing environment with VSCode ### Install dependencies Inside the repo, set up a virtual environment and install dependencies from the command line: From e2e465603c2d8dde547166cb61da61fabaaecf86 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Mon, 9 Sep 2024 09:48:26 -0400 Subject: [PATCH 11/15] Update doc/dev/testing.md Co-authored-by: Brian Floersch --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 965a37649..906a5644e 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -47,7 +47,7 @@ You should now be able to run the unit tests locally: image -### Send logs to the agent +### Send metrics to the agent using dogstasd Create a folder for testing, such as `testapp/main.py`. Create a file inside the folder with the following code: ``` from datadog import initialize, statsd From 9bc34632a112666c1b6a238df675ecabd2e319ae Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Mon, 9 Sep 2024 09:49:38 -0400 Subject: [PATCH 12/15] Update docs with requested changes --- doc/dev/testing.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index 906a5644e..f8f575ed0 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -72,6 +72,3 @@ while(1): Run the Agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` Inside the `main.py` file that you just created, run the debugger to send logs to the agent. - -Those logs should appear in the [Log Explorer](https://dddev.datadoghq.com/logs?query=&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&fromUser=true&messageDisplay=inline&refresh_mode=sliding&storage=hot&stream_sort=desc&viz=stream&from_ts=1722966102377&to_ts=1722967002377&live=true) in Datadog - From 0defd5dce5f480d24c45a61adbd6cf658c7dbac0 Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Wed, 18 Sep 2024 13:37:51 -0400 Subject: [PATCH 13/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index f8f575ed0..ff5a0ef5f 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -1,4 +1,4 @@ -# Setting up a local testing environment with VSCode +# Setting up a local testing environment with VS Code ### Install dependencies Inside the repo, set up a virtual environment and install dependencies from the command line: From ec7f2b14b2e8a1721efe23faaebabdc2290c751a Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Wed, 18 Sep 2024 13:37:57 -0400 Subject: [PATCH 14/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index ff5a0ef5f..e705e2d90 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -71,4 +71,4 @@ while(1): Run the Agent: `./bin/agent/agent run -c bin/agent/dist/datadog.yaml` -Inside the `main.py` file that you just created, run the debugger to send logs to the agent. +Inside the `main.py` file that you just created, run the debugger to send logs to the Agent. From 1c53f0e48db4d300a18a3aa3f6287b54ac72f75f Mon Sep 17 00:00:00 2001 From: andrewqian2001datadog Date: Wed, 18 Sep 2024 13:38:04 -0400 Subject: [PATCH 15/15] Update doc/dev/testing.md Co-authored-by: Jen Gilbert --- doc/dev/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/testing.md b/doc/dev/testing.md index e705e2d90..f8f46df98 100644 --- a/doc/dev/testing.md +++ b/doc/dev/testing.md @@ -47,7 +47,7 @@ You should now be able to run the unit tests locally: image -### Send metrics to the agent using dogstasd +### Send metrics to the Agent using DogStatsD Create a folder for testing, such as `testapp/main.py`. Create a file inside the folder with the following code: ``` from datadog import initialize, statsd