Skip to content

Commit

Permalink
Add Zenoh router 1.0 version support (#2517)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc authored Nov 25, 2024
1 parent 2b69cea commit e275852
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
7 changes: 7 additions & 0 deletions zenoh_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG - Zenoh router

## 1.1.0 / 2024-10-21

***Added:***

* Added support for Zenoh router version 1.0.
* Added partial support (session information only) for routers without the stats feature enabled.

## 1.0.0 / 2023-12-16

***Added***:
Expand Down
13 changes: 13 additions & 0 deletions zenoh_router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ For Agent v7.21+ / v6.21+, follow the instructions below to install Zenoh router
datadog-agent integration install -t datadog-zenoh_router==<INTEGRATION_VERSION>
```

Note:
- The datadog-zenoh_router integration version 1.0.0 is compatible with Zenoh router versions below 1.0.
- For Zenoh router versions above or equal 1.0, integration version 1.1.0 should be used.

### Installation from the source code

To install the Zenoh router check on your host:
Expand All @@ -38,6 +42,14 @@ To install the Zenoh router check on your host:

1. Make sure that the [Zenoh REST API plugin][2] is enabled.

Note:
- The default Zenoh router provides only session information.
- To access full statistics, this feature needs to be enabled at Zenoh router build time using the stats feature. For example:
```shell
cargo build --features stats
```
Alternatively, you can use routers from the [Zetta Platform][12]

2. Edit the `zenoh_router.d/conf.yaml` file in the `conf.d/` folder at the root of your [Agent's configuration directory][10] to start collecting your Zenoh router [metrics](#metrics).
See the [sample zenoh_router.d/conf.yaml][4] for all available configuration options.

Expand Down Expand Up @@ -77,3 +89,4 @@ Need help? Contact [Datadog support][9].
[9]: https://docs.datadoghq.com/help/
[10]: https://docs.datadoghq.com/agent/guide/agent-configuration-files/#agent-configuration-directory
[11]: https://docs.datadoghq.com/developers/integrations/python/
[12]: https://www.zettascale.tech/zetta/
2 changes: 1 addition & 1 deletion zenoh_router/datadog_checks/zenoh_router/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.1.0'
21 changes: 15 additions & 6 deletions zenoh_router/datadog_checks/zenoh_router/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3

import re
import time
from collections import defaultdict

Expand All @@ -9,8 +10,8 @@
class ZenohRouterCheck(AgentCheck):
__NAMESPACE__ = 'zenoh.router'

__PREFIX = '@/router/'
__RID_LEN = 32
__URI = '/@/*/router?_stats=true'
__RID_PATTERN = r'@/([a-f0-9]{32})/router'

def __init__(self, name, init_config, instances):
super(ZenohRouterCheck, self).__init__(name, init_config, instances)
Expand Down Expand Up @@ -67,20 +68,28 @@ def __process_peers(self, value, tags):
tags['whatami'] = k
self.count('sessions', v, tags=self.__map_to_ddtags(tags))

def __extract_rid(self, text):
match = re.search(self.__RID_PATTERN, text)
if match:
return match.group(1)
return None

def check(self, instance):
url = instance.get('url')
try:
response = self.http.get(url + '/' + self.__PREFIX + '*?_stats=true')
response = self.http.get(url + self.__URI)
response.raise_for_status()
data = response.json()

for item in data:
k = item['key'][len(self.__PREFIX) :]
rid = k[: self.__RID_LEN]
rid = self.__extract_rid(item['key'])
if rid is None:
continue
value = item['value']
gtags = self.__tags_by_config(value)
self.__process_stats(value['stats'], gtags.copy(), rid)
self.__process_peers(value['sessions'], gtags.copy())
if 'stats' in value:
self.__process_stats(value['stats'], gtags.copy(), rid)

self.service_check('can_connect', AgentCheck.OK)

Expand Down
2 changes: 1 addition & 1 deletion zenoh_router/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_check(dd_run_check, aggregator, instance, mock_http_response):
STATS_RESPONSE = '''
[
{
"key": "@/router/9bafaff963b9465d80552419bf397add",
"key": "@/9bafaff963b9465d80552419bf397add/router",
"value": {
"locators": [
"tcp/172.10.0.2:7449",
Expand Down

0 comments on commit e275852

Please sign in to comment.