Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(examples/docs): Updating Synth Monitoring Examples #3971

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ To view the full guide on how to configure the Node.js app, view [this recipe](/
**Tracetest Account**:

- Sign up to [`app.tracetest.io`](https://app.tracetest.io) or follow the [get started](/getting-started/installation) docs.
- Create an [environment](/concepts/environments).
- Create an [environment token](/concepts/environment-tokens).
- Have access to the environment's [agent API key](/configuration/agent).
- Have access to the environment's [agent API key](https://app.tracetest.io/retrieve-token).

**Docker**: Have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed on your machine.

Expand All @@ -56,76 +54,55 @@ cd tracetest/examples/quick-start-nodejs-synthetic-monitoring
Follow these instructions to run the quick start:

1. Copy the `.env.template` file to `.env`.
2. Log into the [Tracetest app](https://app.tracetest.io/).
3. This example is configured to use the OpenTelemetry Tracing Backend. Ensure the environment you will be utilizing to run this example is also configured to use the OpenTelemetry Tracing Backend by clicking on Settings, Tracing Backend, OpenTelemetry, Save.
4. Fill out the [token](https://docs.tracetest.io/concepts/environment-tokens) and [API key](https://docs.tracetest.io/concepts/agent) details by editing your `.env` file. You can find these values in the Settings area for your environment.
5. Run `docker compose up -d`.
6. Configure your CLI with `tracetest configure -t <YOUR_API_TOKEN>`.
7. Apply the Tracetest Monitor with `tracetest apply monitor -f tracetest-synthetic-monitor.yaml`. This will start running the `./tracetest-test-api.yaml` test every minute.
8. Run tests manually from the CLI with `tracetest run test -f ./tracetest-test-api.yaml` or from the Tracetest Web UI by accessing the app with the URL `http://app:8080/books`.
2. Fill out the [TRACETEST_TOKEN and ENVIRONMENT_ID](https://app.tracetest.io/retrieve-token) details by editing your `.env` file.
3. Run `docker compose run tracetest-run`.
4. Follow the links in the output to view the test results.

Follow along with the sections below for a detailed breakdown of what the example you just ran did and how it works.
Follow along with the sections below for an in detail breakdown of what the example you just ran did and how it works.

## Running the Node.js App

To start the full setup, run the following command:

```bash
docker compose up -d
docker compose run tracetest-run
```

## Run Tracetest Tests

1. Open [Tracetest](https://app.tracetest.io/)
2. Start creating tests! Make sure to use the `http://app:8080/books` URL in your test creation.
3. To trigger tests in the CLI, first [install the CLI](/cli/cli-installation-reference), [configure it](/cli/configuring-your-cli), and [run a test](/cli/running-tests). From the root of the quick start directory, run:
This will:
1. Start the Node.js app, the OpenTelemetry Collector, and send the traces to Tempo.
2. Start the Tracetest Agent.
3. Configure the tracing backend and create the monitor and tests in your environment.
4. Run the tests.

```bash
tracetest configure -t <YOUR_API_TOKEN>
tracetest run test -f ./tracetest-test-api.yaml
```

Here's a sample of a failed test run, which happens if you use this selector and assertion pair.

Selector:
```
span[tracetest.span.type="general" name="Books List"]
```

Assertion:
```
attr: books.list.count = 4
```

![assertion](https://res.cloudinary.com/djwdcmwdz/image/upload/v1715607148/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_56b66bc6e1a1cbbd_test_e9CCQuLSg_run_3_selectedAssertion_0_selectedSpan_d0c03aa5d02b9975_uqhhwl.png)

It fails because `books.length` is equal to `3`.
Open the URL and start creating tests! Make sure to use the `http://app:8080/` URL in your test creation, because your Node.js app and Tracetest are in the same network.

## Run Synthetic Monitoring

You can apply the Tracetest Monitor with the CLI.
The monitor will be automatically applied when running this example, You can find the Tracetest Monitor Definition and apply it directly yourself using the CLI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The monitor will be automatically applied when running this example, You can find the Tracetest Monitor Definition and apply it directly yourself using the CLI.
The monitor will be automatically applied when running this example. You can find the Tracetest Monitor Definition and apply it directly yourself using the CLI.


```bash
tracetest apply monitor -f tracetest-synthetic-monitor.yaml
tracetest apply monitor -f ./resources/monitor.yaml
```

This will start running the `./tracetest-test-api.yaml` test every minute.
This will start running the `./resources/monitor.yaml` test every minute.

With the Web UI follow these steps to create a monitor.

1. Select `Monitors` in the [Tracetest](https://app.tracetest.io/) sidebar.
2. Create a Monitor. Select a schedule and toggle the enable monitor switch.
![create a monitor](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_guf2id.png)
![create a monitor](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_guf2id.png)
3. Select the test you want to add to the Monitor.
![select tests for monitor](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921383/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_1_dsbb1k.png)
![select tests for monitor](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921383/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_1_dsbb1k.png)
4. Select the webhook you want to notify.
![select webhook](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_2_rzz5vm.png)
![select webhook](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_2_rzz5vm.png)
5. Click `Create` and you will see the Monitor run.
![monitor run overview](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_3_pktmr0.png)
![monitor run overview](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921382/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_3_pktmr0.png)
6. To view the YAML definition for the Monitor, click `Automate`.
![monitor automate overview](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921383/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_4_ysjbnx.png)
![monitor automate overview](https://res.cloudinary.com/djwdcmwdz/image/upload/v1721921383/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_8fca16a31b8b6e24_monitors_page_1_4_ysjbnx.png)

With this setup, your Monitor will trigger the `Books list with availability` test, defined in `./tracetest-test-api.yaml`, every 5 minutes.
With this setup, your Monitor will trigger the `Books list with availability` test, defined in `./resources/test.yaml`, every 5 minutes.

## Learn More

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Get the required information here: https://app.tracetest.io/retrieve-token

TRACETEST_TOKEN="<YOUR_TRACETEST_TOKEN>"
TRACETEST_ENVIRONMENT_ID="<YOUR_ENV_ID>"

# GRPC
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://tracetest-agent:4317/"
# or, use HTTP
# OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://tracetest-agent:4318/v1/traces"
TRACETEST_API_KEY="<YOUR_TRACETEST_API_KEY>"
TRACETEST_API_TOKEN="<YOUR_TRACETEST_TOKEN>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine

WORKDIR /app
ARG TRACETEST_IMAGE_VERSION=v1.4.0

RUN apk --update add bash jq curl
RUN curl -L https://raw.githubusercontent.com/kubeshop/tracetest/main/install-cli.sh | bash -s -- $TRACETEST_IMAGE_VERSION

WORKDIR /resources

ENTRYPOINT ["echo", "Tracetest CLI installed"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
app:
image: quick-start-nodejs
Expand All @@ -8,6 +8,9 @@ services:
- "8080:8080"
environment:
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT}
depends_on:
availability:
condition: service_started

availability:
image: quick-start-nodejs-availability
Expand All @@ -21,11 +24,43 @@ services:
# Cloud-based Managed Tracetest
tracetest-agent:
image: kubeshop/tracetest-agent:latest
command:
- "--mode=verbose"
environment:
# Find the Agent API Key here: https://docs.tracetest.io/configuration/agent
- TRACETEST_API_KEY=${TRACETEST_API_KEY}
ports:
- 4317:4317
- 4318:4318
# Get the required information here: https://app.tracetest.io/retrieve-token
- TRACETEST_API_KEY=${TRACETEST_TOKEN}
- TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID}

tracetest-apply:
build:
dockerfile: Dockerfile.tracetest
volumes:
- ./resources:/resources
environment:
TRACETEST_TOKEN: ${TRACETEST_TOKEN}
TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID}
entrypoint:
- bash
- /resources/apply.sh
networks:
default: null
depends_on:
app:
condition: service_started
tracetest-agent:
condition: service_started

tracetest-run:
build:
dockerfile: Dockerfile.tracetest
volumes:
- ./resources:/resources
environment:
TRACETEST_TOKEN: ${TRACETEST_TOKEN}
TRACETEST_ENVIRONMENT_ID: ${TRACETEST_ENVIRONMENT_ID}
entrypoint:
- bash
- /resources/run.sh
networks:
default: null
depends_on:
tracetest-apply:
condition: service_completed_successfully
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -e

TOKEN=$TRACETEST_TOKEN
ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID

apply() {
echo "Configuring TraceTest"
tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID

echo "Applying Resources"
tracetest apply datastore -f /resources/datastore.yaml
tracetest apply test -f /resources/test.yaml
tracetest apply monitor -f /resources/monitor.yaml
}

apply
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: DataStore
spec:
id: current
name: otlp
type: otlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type: Monitor
spec:
id: JtFYYc9SR
name: Quick Start Synthetic Monitor
enabled: true
variableSetId: ""
tests:
- phAZcrT4B
schedule:
cron: "*/1 * * * *"
timeZone: Etc/UTC
alerts:
- id: slack-webhook-message
type: webhook
webhook:
body: "{\n \"text\": \"Monitor ${.Monitor.Name} has failed, follow the link to find the <${.URL}|results>\"\n}"
method: POST
url: <your-webhook-url>
headers:
- key: Content-Type
value: application/json
events:
- FAILED
16 changes: 16 additions & 0 deletions examples/quick-start-nodejs-synthetic-monitoring/resources/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -e

TOKEN=$TRACETEST_TOKEN
ENVIRONMENT_ID=$TRACETEST_ENVIRONMENT_ID

run() {
echo "Configuring Tracetest"
tracetest configure --token $TOKEN --environment $ENVIRONMENT_ID

echo "Running Trace-Based Tests..."
tracetest run test -f /resources/test.yaml
}

run

This file was deleted.

Loading