Skip to content

Commit fe49819

Browse files
committed
docs: expand setup and search guidance
1 parent 3328ad1 commit fe49819

6 files changed

Lines changed: 118 additions & 31 deletions

File tree

doc/admin/Configuration.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ DATABASES = {
2626

2727
**NOTE**: The second argument to `os.getenv` is for the default value if the environment variable is not set.
2828

29+
## Configuration with docker-compose
30+
When running Delve with Docker, configuration values are typically supplied via
31+
environment variables defined in an `.env` file. The project includes a
32+
`docker-compose.yaml` and a corresponding `.env.example` file. Copy the example
33+
file to `.env`, update the values for your database and secret key, and
34+
`docker-compose` will inject those settings into the containers at startup.
35+
36+
The standard `delve/settings.py` already looks for these environment variables,
37+
so no additional changes are required to the image. This approach keeps secrets
38+
out of the settings file while still allowing easy configuration for different
39+
environments.
40+
2941
## Configuring Email Settings
3042
Django provides a flexible email backend system that allows you to configure various email settings. Here are the steps to configure email settings in `settings.py`:
3143

doc/admin/Ingesting_Data.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ This endpoint is provided to allow the resolution of queries.
2525

2626
The `/api/query` endpoint is what is used to power the Explore UI which is available at `/explore`.
2727

28-
The browsable REST API, which is returned when accessing `/api/query` from a browser can be really useful for debugging if you enable `DEBUG` in your `settings.py` as it allows you to track the SQL statements issued by search commands as well as a ton of other useful information.
28+
The browsable REST API, which is returned when accessing `/api/query` from a
29+
browser, can be really useful for debugging when the Django debug toolbar is
30+
enabled. Setting `DEBUG=True` and installing the toolbar allows you to inspect
31+
the SQL statements issued by search commands along with a wealth of other
32+
diagnostic information.
2933

3034
### Example Usage
3135

doc/admin/Installation_and_Setup.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,23 @@ python service.py /?
106106
```
107107

108108
### Installing Delve Supervisor Service on Other Platforms
109-
This feature is coming soon. Until then, please consult your operating system's documentation for information on hosting services (Systemd, etc.) to have Delve automatically started and monitored.
109+
On non-Windows platforms the recommended approach for running Delve is to use
110+
Docker and `docker-compose`. The repository includes a
111+
`docker-compose.yaml` that defines services for the web server, background
112+
worker, and a PostgreSQL database. These containers replace the need for a
113+
separate supervisor service by handling start-up and restart logic for you.
114+
115+
To get started, copy the provided `.env.example` file to `.env` and adjust the
116+
settings for your environment. Then launch the stack:
117+
118+
```bash
119+
cp .env.example .env
120+
docker compose up -d
121+
```
122+
123+
`docker-compose` will orchestrate the containers and keep them running, making
124+
it an easy way to deploy Delve on Linux and macOS without manually configuring
125+
init systems like Systemd.
110126

111127

112128
[Previous: Introduction](/doc/admin/Introduction.md) | [Next: Bootstrap Guide](/doc/admin/Bootstrap_Guide.md)

doc/admin/Performance_Tuning.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ class MyCustomModel(models.Model):
4545
datetime_field = models.DateTimeField(db_index=True)
4646
```
4747

48+
### BRIN Indexes in PostgreSQL
49+
For very large tables in PostgreSQL, a [BRIN index](https://www.postgresql.org/docs/current/brin-intro.html)
50+
can dramatically reduce index size while still allowing efficient scans of
51+
time-ordered data. Delve stores event timestamps in the `created` field of the
52+
`events.Event` model, making it a good candidate for a BRIN index:
53+
54+
```sql
55+
CREATE INDEX CONCURRENTLY events_event_created_brin
56+
ON events_event USING BRIN (created);
57+
```
58+
59+
You can also create this index via a Django migration using
60+
`django.contrib.postgres.indexes.BrinIndex`. BRIN indexes are especially useful
61+
when events are inserted roughly in chronological order, which is typical for
62+
log data.
63+
4864
## Caching Strategies
4965
Caching can help reduce the load on your database and improve response times. Django provides several caching backends, including in-memory caching, file-based caching, and more.
5066

doc/user/Getting_Started.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,23 @@ Delve is a versatile and powerful platform for ingesting, transforming, and sear
2929
Delve is built around several core concepts that enable its powerful functionality:
3030

3131
### Events
32-
Events are the basic unit of data in Delve. They are stored in a database and consist of indexed fields such as `created`, `index`, `source`, and `host`. Additionally, events contain a JSON field called `extracted_fields` for storing information extracted from the event.
32+
Events are the basic unit of data in Delve. They are stored in a database and
33+
consist of indexed fields such as `created`, `index`, `source`, and `host`.
34+
Additionally, events contain a JSON field called `extracted_fields` for storing
35+
information extracted from the event.
3336

34-
Events can be created through the Delve REST API or via queries using search commands, either interactively or on a scheduled basis.
37+
Events can be created through the Delve REST API or via queries using search
38+
commands, either interactively or on a scheduled basis. If you are writing code
39+
against Delve itself, you may also create `Event` instances directly using the
40+
Django ORM.
3541

3642
### Queries
3743
Queries are used to retrieve, transform, and store data. They can be ephemeral or persisted in the database. A query's `text` field defines the pipeline through which events are processed using search commands.
3844

39-
Queries use a pipeline syntax where commands are chained together with the `|` operator, similar to command-line shells. For example:
45+
Queries use a pipeline syntax where commands are chained together with the `|`
46+
operator, similar to command-line shells. All whitespace in a query is collapsed
47+
so breaking a pipeline across multiple lines is perfectly fine and can aid
48+
readability. For example:
4049

4150
```bash
4251
search --last-15-minutes index=default
@@ -54,16 +63,30 @@ Ingestion is the process of importing data into Delve. This can be done through
5463
- **Searches**: Use interactive or scheduled queries to ingest data.
5564
5665
### Field Extraction and Preprocessing
57-
Field extraction identifies and extracts specific fields from data. Delve supports:
58-
- **Index-time Extractions**: Applied during data ingestion and persisted in the database.
59-
- **Search-time Extractions**: Dynamically extract fields during a search (can be persisted to the database or ephemeral).
60-
- **Preprocessing**: Take action (email, log, etc.) on certain events during ingestion.
66+
Field extraction identifies and extracts specific fields from data. Delve
67+
supports:
68+
- **Index-time Extractions**: Applied during data ingestion and persisted in the
69+
database. Update `DELVE_EXTRACTION_MAP` in `settings.py` to map sourcetypes to
70+
the appropriate extraction functions.
71+
- **Search-time Extractions**: Dynamically extract fields during a search (can
72+
be persisted to the database or ephemeral). The `qs_update` search command can
73+
be used to update events at search time after new fields are extracted.
74+
- **Preprocessing**: Take action (email, log, etc.) on certain events during
75+
ingestion. Register processor functions in `DELVE_PROCESSOR_MAP` in
76+
`settings.py` based on the event sourcetype.
6177
6278
### Search
63-
Search functionality allows querying and filtering data, as well as performing transformations, visualizations, and more. Delve supports custom search commands written in Python, which can be registered in the configuration.
79+
Search functionality allows querying and filtering data, as well as performing
80+
transformations, visualizations, and more. Delve supports custom search
81+
commands written in Python, which can be registered in the configuration. The
82+
`DELVE_SEARCH_COMMANDS` setting in `settings.py` can be updated to add or remove
83+
available search commands.
6484
6585
### Custom Apps
66-
Delve enables the creation of custom apps to group related data and code. These apps can include custom search commands, dashboards, REST API endpoints, and more.
86+
Delve enables the creation of custom apps to group related data and code. These
87+
apps can include custom search commands, dashboards, REST API endpoints, and
88+
more. Custom apps are added to the `INSTALLED_APPS` setting in `settings.py` so
89+
that Django knows to load them.
6790
6891
### Alerts
6992
Delve provides search-based and processor-based alerts:

doc/user/Searching_Filtering_and_More.md

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ Queryset transformation commands act on Django Querysets (such as the output of
2525

2626
## Generic Transformations
2727

28-
Generic transformation commands modify data from a source command in some way. These commands are designed to be versatile and work well with diverse sets of data, although they may be slower than their `qs_` counterparts.
28+
Generic transformation commands modify data from a source command in some way.
29+
While Queryset Transformations accept and return Django `QuerySet` objects,
30+
Generic Transformations are designed to accept and return arbitrary Python data
31+
structures (`int`, `str`, `list`, `dict`, `tuple`, etc.). A list of dictionaries
32+
representing rows is a common pattern. These commands are versatile and work
33+
well with diverse sets of data, although they may be slower than their `qs_`
34+
counterparts.
2935

3036
### Example Commands
3137

@@ -133,10 +139,17 @@ search --index {{ index }} text__icontains="{{ keyword }}"
133139
134140
In this example, `{{ index }}` and `{{ keyword }}` are Jinja2 template variables that will be replaced with their corresponding values from the context.
135141
136-
This can be useful for including different sets of arguments to the same search command to get different results or behavior. It can also be used with the `query_table` and `query_chart` templatetags which accept Django Form instances for use in dashboards and control panels.
142+
This can be useful for including different sets of arguments to the same search
143+
command to get different results or behavior. Combined with the `query_table`
144+
and `query_chart` templatetags, a Django `Form` instance can be rendered in a
145+
dashboard to collect user input and feed values directly into a query. This
146+
combination of forms, template tags, and Jinja2 templating makes it easy to
147+
build powerful interactive dashboards and control panels.
137148
138149
## send_email Command
139-
The `send_email` command allows you to send email notifications based on the result set. This command is configured using Django's SMTP settings. For example:
150+
The `send_email` command allows you to send email notifications based on the
151+
result set. This command is configured using Django's SMTP settings and only
152+
sends an email when the result set contains at least one event. For example:
140153
141154
```bash
142155
search --index default text__icontains="error" | send_email to="team@example.com" subject="Error Alert"
@@ -175,37 +188,37 @@ make_events --save
175188
```
176189
177190
## Custom Search Commands
178-
Delve allows you to create custom search commands in Python and register them in `settings.py` under `DELVE_SEARCH_COMMANDS`. This provides powerful and flexible ways to manipulate the result set.
191+
To create a custom search command, first build an `argparse.ArgumentParser` to
192+
describe any arguments the command accepts. Then write a function that operates
193+
on the events and wrap it with the
194+
`events.search_commands.decorators.search_command` decorator, passing the parser
195+
instance. The decorator parses the arguments and supplies them to your
196+
function.
179197
180198
### Example Custom Command
181-
Here is an example of a custom search command:
182199
183200
```python
184-
# filepath: /delve/search_commands/custom_command.py
185-
def custom_command(events, **kwargs):
186-
# Custom logic to process events
187-
for event in events:
188-
event['custom_field'] = 'custom_value'
189-
return events
190-
```
201+
# filepath: /delve/search_commands/shout.py
202+
from argparse import ArgumentParser
203+
from events.search_commands.decorators import search_command
191204
192-
Alternatively, you could write it as a generator which could possibly improve memory usage:
205+
parser = ArgumentParser(prog='shout')
206+
parser.add_argument('--field', required=True)
193207
194-
```python
195-
# filepath: /delve/search_commands/custom_command.py
196-
def custom_command(events, **kwargs):
197-
# Custom logic to process events
208+
@search_command(parser)
209+
def shout(events, field):
198210
for event in events:
199-
event['custom_field'] = 'custom_value'
211+
event[field] = event[field].upper()
200212
yield event
201213
```
202-
To register the custom command, add it to `settings.py`:
214+
215+
Register the custom command in `settings.py`:
203216
204217
```python
205218
# filepath: /delve/settings.py
206219
DELVE_SEARCH_COMMANDS = {
207220
...
208-
'custom_command': 'delve.search_commands.custom_command.custom_command',
221+
'shout': 'delve.search_commands.shout.shout',
209222
...
210223
}
211224
```
@@ -238,6 +251,9 @@ There are some special functions that are particularly useful for searching, tra
238251
```python
239252
qs_annotate transformed_key=KT('json_field__key__1__foobar')
240253
```
254+
- `Func`: The base class for database functions from `django.db.models`. Use
255+
this when calling functions like `Lower`, `Upper`, `Length`, `Trim`, `Cast`,
256+
`Coalesce`, `Concat`, or `Now`.
241257
242258
#### Available Functions
243259

0 commit comments

Comments
 (0)