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

feat: add support for OpenSearch backend #348

Merged
merged 7 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 10 additions & 10 deletions docs/providers/opensearch.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# Elasticsearch
# OpenSearh
maximepln marked this conversation as resolved.
Show resolved Hide resolved

## Backend

Using the `opensearch` backend class, you can query any metrics available in Opensearch to create an SLO.
Using the `OpenSearch` backend class, you can query any metrics available in OpenSearchBackend to create an SLO.
maximepln marked this conversation as resolved.
Show resolved Hide resolved

```yaml
backends:
opensearch:
open_search:
url: ${OPENSEARCH_URL}
```

Note that `url` can be either a single string (when connecting to a single node) or a list of strings (when connecting to multiple nodes):

```yaml
backends:
opensearch:
open_search:
url: https://localhost:9200
```

```yaml
backends:
opensearch:
open_search:
url:
- https://localhost:9200
- https://localhost:9201
```

The following method is available to compute SLOs with the `opensearch` backend:
The following method is available to compute SLOs with the `OpenSearch` backend:
maximepln marked this conversation as resolved.
Show resolved Hide resolved

* `good_bad_ratio` method is used to compute the ratio between two metrics:

Expand All @@ -38,7 +38,7 @@ This method is often used for availability SLOs, but can be used for other purpo
**SLO example:**

```yaml
backend: opensearch
backend: open_search
method: good_bad_ratio
service_level_indicator:
index: my-index
Expand All @@ -57,15 +57,15 @@ This method is often used for availability SLOs, but can be used for other purpo

Additional info:

* `date_field`: Has to be a valid Opensearch `timestamp` type
* `date_field`: Has to be a valid OpenSearch `timestamp` type

**→ [Full SLO config](../../samples/opensearch/slo_opensearch_latency_sli.yaml)**

You can also use the `filter_bad` field which identifies bad events instead of the `filter_valid` field which identifies all valid events.

The Lucene query entered in either the `query_good`, `query_bad` or `query_valid` fields will be combined (using the `bool` operator) into a larger query that filters results on the `window` specified in your Error Budget Policy steps.

The full `Opensearh` query body for the `query_bad` above will therefore look like:
The full `OpenSearch` query body for the `query_bad` above will therefore look like:

```json
{
Expand Down Expand Up @@ -94,4 +94,4 @@ The full `Opensearh` query body for the `query_bad` above will therefore look li

### Examples

Complete SLO samples using the `opensearch` backend are available in [samples/elasticsearch](../../samples/opensearch). Check them out!
Complete SLO samples using the `OpenSearchBackend` backend are available in [samples/opensearch](../../samples/opensearch). Check them out!
2 changes: 1 addition & 1 deletion samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ backends:
port: ${SPLUNK_PORT}
user: ${SPLUNK_USER}
password: ${SPLUNK_PWD}
opensearch:
open_search:
url: ${OPENSEARCH_URL}

exporters:
Expand Down
4 changes: 2 additions & 2 deletions samples/opensearch/slo_opensearch_availability_sli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ metadata:
slo_name: availability
spec:
description: 99% of the element are valid
backend: opensearch
backend: open_search
method: good_bad_ratio
exporters: []
service_level_indicator:
index: my-index
index: "gravitee-request-*"
date_field: '@timestamp'
query_good:
must:
Expand Down
4 changes: 2 additions & 2 deletions samples/opensearch/slo_opensearch_latency_sli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ metadata:
slo_name: latency
spec:
description: 99% of the element are valid
backend: opensearch
backend: open_search
method: good_bad_ratio
exporters: []
service_level_indicator:
index: my-index
index: "gravitee-request-*"
date_field: '@timestamp'
query_good:
must:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
`opensearch.py`
`open_search.py`
Opensearch backend implementation.
"""

Expand All @@ -14,7 +14,7 @@


# pylint: disable=duplicate-code
class OpensearchBackend:
class OpenSearchBackend:
"""Backend for querying metrics from OpenSearch.

Args:
Expand Down Expand Up @@ -141,4 +141,4 @@ def build_query(query, window, date_field):
return body


OS = OpensearchBackend
OS = OpenSearchBackend
12 changes: 6 additions & 6 deletions tests/unit/backends/test_opensearch.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest

from slo_generator.backends.opensearch import OpensearchBackend
from slo_generator.backends.open_search import OpenSearchBackend


class TestOpensearchBackend(unittest.TestCase):
class TestOpenSearchBackend(unittest.TestCase):
assert 1 == 1

def test_build_query_with_empty_query(self):
assert OpensearchBackend.build_query(None, 3600, "date") is None
assert OpenSearchBackend.build_query(None, 3600, "date") is None

def test_build_query_with_simple_query_and_no_filter(self):
query: dict = {
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_build_query_with_simple_query_and_no_filter(self):
"track_total_hits": True,
}

assert OpensearchBackend.build_query(query, 3600, "date") == enriched_query
assert OpenSearchBackend.build_query(query, 3600, "date") == enriched_query

def test_build_query_with_simple_query_and_simple_filter(self):
query: dict = {
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_build_query_with_simple_query_and_simple_filter(self):
"track_total_hits": True,
}

assert OpensearchBackend.build_query(query, 3600, "date") == enriched_query
assert OpenSearchBackend.build_query(query, 3600, "date") == enriched_query

def test_build_query_with_simple_query_and_existing_filter_with_range(self):
query: dict = {
Expand Down Expand Up @@ -119,4 +119,4 @@ def test_build_query_with_simple_query_and_existing_filter_with_range(self):
"track_total_hits": True,
}

assert OpensearchBackend.build_query(query, 3600, "date") == enriched_query
assert OpenSearchBackend.build_query(query, 3600, "date") == enriched_query