Skip to content

Commit

Permalink
Test metric tag column feature (#16001)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang authored Oct 12, 2023
1 parent fd04569 commit d1bb5ca
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions snmp/tests/compose/data/features.snmprec
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1.3.6.1.2.1.1.1.0|4|Fake features test device
1.3.6.1.2.1.1.2.0|6|1.2.3.20231012
1.3.6.1.2.1.1.5.0|4|features.device.name
1.3.6.1.2.1.2.2.1.14.10|65|99
1.3.6.1.2.1.31.1.1.1.1.10|4|If1
1.3.6.1.2.1.31.1.1.1.18.10|4|If1Alias
30 changes: 30 additions & 0 deletions snmp/tests/fixtures/user_profiles/features.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This profile is used to test features.
# Especially deprecated features since they are not used anymore in our default profiles,
# but we need to keep backward compatibility.

extends:
- _base.yaml

sysobjectid: 1.2.3.20231012

metrics:
- MIB: IF-MIB
table:
OID: 1.3.6.1.2.1.2.2
name: ifTable
symbols:
- OID: 1.3.6.1.2.1.2.2.1.14
name: ifInErrors
metric_tags:
# TEST CASE deprecated `column` syntax
- column:
OID: 1.3.6.1.2.1.31.1.1.1.1
name: ifName
table: ifXTable
tag: tag_using_deprecated_column_syntax
# TEST CASE `symbol` syntax
- symbol:
OID: 1.3.6.1.2.1.31.1.1.1.18
name: ifAlias
table: ifXTable
tag: tag_using_symbol_syntax
60 changes: 60 additions & 0 deletions snmp/tests/test_e2e_core_profiles/test_profile_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# (C) Datadog, Inc. 2023-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

import pytest

from .. import common
from ..test_e2e_core_metadata import assert_device_metadata
from .utils import (
assert_common_metrics,
create_e2e_core_test_config,
get_device_ip_from_config,
)

pytestmark = [pytest.mark.e2e, common.py3_plus_only, common.snmp_integration_only]


def test_e2e_features(dd_agent_check):
profile = 'features'
config = create_e2e_core_test_config(profile)
aggregator = common.dd_agent_check_wrapper(dd_agent_check, config, rate=True)

ip_address = get_device_ip_from_config(config)
common_tags = [
'snmp_profile:features',
'snmp_host:features.device.name',
'device_namespace:default',
'snmp_device:' + ip_address,
]

# --- TEST EXTENDED METRICS ---

# --- TEST METRICS ---
assert_common_metrics(aggregator, common_tags)

tag_rows = [
[
'tag_using_deprecated_column_syntax:If1',
'tag_using_symbol_syntax:If1Alias',
],
]
for tag_row in tag_rows:
aggregator.assert_metric('snmp.ifInErrors', metric_type=aggregator.GAUGE, tags=common_tags + tag_row)

# --- TEST METADATA ---
device = {
'description': 'Fake features test device',
'id': 'default:' + ip_address,
'id_tags': ['device_namespace:default', 'snmp_device:' + ip_address],
'ip_address': '' + ip_address,
'name': 'features.device.name',
'profile': 'features',
'status': 1,
'sys_object_id': '1.2.3.20231012',
}
device['tags'] = common_tags
assert_device_metadata(aggregator, device)

# --- CHECK COVERAGE ---
aggregator.assert_all_metrics_covered()

0 comments on commit d1bb5ca

Please sign in to comment.