File size: 7,865 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# Development Setup

This guide assumes you have the following commands installed and available in your environment:

- `docker`
- `go` (>= 1.21)
- `node` (>= 18)
- `make`

**Note**: While GoAlert requires Go 1.23 for development, starting from Go 1.21, Go will automatically download and use the correct toolchain version specified in the project (`go 1.23` in `go.mod`). Therefore, Go 1.21 is the minimum version you need to have installed, but the latest version is recommended.

## Quick Start

To start the development environment, ensure that Docker is running and execute:

```bash
make start
```

Once the server is up, you can access the GoAlert UI at [http://localhost:3030](http://localhost:3030). Log in using the default credentials:

- **Username**: `admin`
- **Password**: `admin123`

> **Security Note**: The default credentials are intended for development purposes only. If your development environment is accessible over a network, it's recommended to change the password to prevent unauthorized access.

In development mode, you'll see a `Dev` item in the navigation bar. This allows you to configure and access additional integrations such as Prometheus and email messages.

## VSCode Configuration

If you are using Visual Studio Code (VSCode), you can run:

```bash
make vscode
```

This command installs the Yarn SDK for VSCode, ensuring compatibility with the Yarn Plug'n'Play (PnP) setup used by GoAlert. By default, VSCode extensions expect dependencies to be in `node_modules`, but Yarn PnP uses a different mechanism for dependency resolution. Running `make vscode` resolves this by configuring VSCode to work with Yarn PnP.

## External Traffic

To test features that require external callbacks (e.g., webhooks from third-party services), you'll need a publicly accessible URL that points to your local development server.

Start the development environment with the `PUBLIC_URL` environment variable set:

```bash
make start PUBLIC_URL=https://localdev.example.com
```

### Using `ngrok` to Expose Your Local Server

To expose your local server to the internet, you can use a tool like `ngrok`. First, ensure `ngrok` is installed on your system. Then, add the following line to your `Procfile.local`:

```bash
ngrok: ngrok http 3030
```

This configuration starts `ngrok` automatically when you run `make start`, creating a public URL that tunnels to your local server. The public URL provided by `ngrok` will look something like `https://abcd1234.ngrok.io`.

## Database (PostgreSQL)

GoAlert is built and tested against PostgreSQL 13. While versions 11 and newer should work, using PostgreSQL 13 is recommended for compatibility.

### Starting PostgreSQL

When you run `make start`, GoAlert automatically starts a PostgreSQL instance using Docker. If you need to start it manually, you can run:

```bash
make postgres
```

### Connecting to the Database

You can connect to the local database using `psql` or a GUI tool like pgAdmin or TablePlus. Use the following connection details:

- **Host**: `localhost`
- **Port**: `5432`
- **Database**: `goalert`
- **User**: `goalert`
- **Password**: (leave blank)

Alternatively, you can use the connection URL:

```text
postgres://goalert@localhost:5432/goalert
```

## Database Management

To reset or regenerate the database (e.g., to resolve migration errors or test with a different dataset size), run:

```bash
make regendb
```

> **Warning**: This command will erase any existing data in the database and generate a fresh schema with sample data.

### Scaling Sample Data with `SIZE`

You can control the amount of sample data generated by specifying the `SIZE` parameter. For example:

```bash
make regendb SIZE=10
```

The `SIZE` parameter scales the amount of random data inserted into the database. A higher number creates more data, which can be useful for testing scalability and performance.

This command also creates an admin user with the credentials `admin/admin123`.

### Manual Database Configuration

If you have PostgreSQL running locally and prefer not to use Docker, you can manually set up the `goalert` role:

```sql
CREATE ROLE goalert WITH LOGIN SUPERUSER;
```

> **Note**: The development user must have superuser privileges to enable the `pgcrypto` extension using `CREATE EXTENSION`.

Alternatively, if you prefer not to grant superuser privileges, you can manually enable the `pgcrypto` extension in your database:

```sql
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
```

Ensure that the user `goalert` has the necessary permissions to interact with the database schema.

## Testing

### Playwright Tests

GoAlert uses Playwright for automated browser testing. You can start Playwright in one of the following modes:

- **Start the Playwright UI**:

  ```bash
  make playwright-ui
  ```

  This command opens the Playwright Test Runner UI, allowing you to run and debug tests interactively.

- **Run All Tests in Headless Mode**:

  ```bash
  make playwright-run
  ```

  This command runs all Playwright tests in headless mode, suitable for continuous integration pipelines or automated testing scenarios.

### Running Smoke Tests

A suite of functional and behavioral tests are maintained for the backend code. These tests cover various APIs and behaviors of the GoAlert server component.

Run the full suite of smoke tests with:

```bash
make test-smoke
```

> **Note**: These tests require that PostgreSQL is running.

### Running Unit Tests

#### Go Unit Tests

All Go unit tests can be run with:

```bash
make test-unit
```

To run tests for a specific package or file, you can use the `go test` command directly:

```bash
go test ./path/to/package -v
```

#### UI Unit Tests

UI unit tests are located alongside the components they test, with the same filename appended with `.test.js`.

To run all UI unit tests independently of the Go unit tests, use:

```bash
make jest
```

To run tests in watch mode, which re-runs tests when files change, use:

```bash
make jest JEST_ARGS=--watch
```

To run a specific test file:

```bash
make jest JEST_ARGS=path/to/your.test.js
```

### Generating Test Coverage Reports

To generate test coverage reports for UI tests, run:

```bash
make jest JEST_ARGS=--coverage
```

## Additional Information

### Environment Variables

Some environment variables can affect the behavior of the development environment:

- **`PUBLIC_URL`**: Sets the publicly accessible URL for your local server. Useful for testing integrations that require callbacks from external services.
- **`SIZE`**: Controls the amount of sample data generated during `make regendb`.

### Prerequisites

Ensure that your system meets the following requirements:

- **Operating System**: macOS, Linux, or Windows (with WSL2)
- **Docker**: Install from [Docker's official website](https://www.docker.com/get-started)
- **Go**: Download from [Go's official website](https://golang.org/dl/)
- **Node.js**: Install from [Node.js official website](https://nodejs.org/en/download/)
- **Make**: Typically pre-installed on macOS and Linux. For Windows, consider using [GNU Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm) or WSL2.

### Troubleshooting

#### Common Issues

- **Docker Not Running**: Ensure that Docker Desktop or the Docker daemon is running before executing `make start`.
- **Port Conflicts**: If you receive errors about ports already in use, ensure that no other services are running on the required ports (e.g., 3030 for the GoAlert server).

#### Getting Help

If you encounter issues not covered in this guide, consider reaching out via:

- **GitHub Issues**: [GoAlert GitHub Repository](https://github.com/target/goalert/issues)
- **Community Slack**: Join the GoAlert community on Slack for real-time assistance, [more info here.](https://github.com/target/goalert?tab=readme-ov-file#contact-us)