Skip to content

Commit 6be54eb

Browse files
Merge pull request #121 from Dynatrace-James-Kitson/kitson
Stop using enum for metric units
2 parents 9c1467b + d711edf commit 6be54eb

File tree

4 files changed

+9
-69
lines changed

4 files changed

+9
-69
lines changed

dynatrace/environment_v2/metrics.py

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -141,65 +141,6 @@ class Transformation(Enum):
141141
SETUNIT = "setUnit"
142142

143143

144-
class Unit(Enum):
145-
BIT = "Bit"
146-
BITPERHOUR = "BitPerHour"
147-
BITPERMINUTE = "BitPerMinute"
148-
BITPERSECOND = "BitPerSecond"
149-
BYTE = "Byte"
150-
BYTEPERHOUR = "BytePerHour"
151-
BYTEPERMINUTE = "BytePerMinute"
152-
BYTEPERSECOND = "BytePerSecond"
153-
CORES = "Cores"
154-
COUNT = "Count"
155-
DAY = "Day"
156-
DECIBELMILLIWATT = "DecibelMilliWatt"
157-
GIBIBYTE = "GibiByte"
158-
GIGA = "Giga"
159-
GIGABYTE = "GigaByte"
160-
HOUR = "Hour"
161-
KIBIBYTE = "KibiByte"
162-
KIBIBYTEPERHOUR = "KibiBytePerHour"
163-
KIBIBYTEPERMINUTE = "KibiBytePerMinute"
164-
KIBIBYTEPERSECOND = "KibiBytePerSecond"
165-
KILO = "Kilo"
166-
KILOBYTE = "KiloByte"
167-
KILOBYTEPERHOUR = "KiloBytePerHour"
168-
KILOBYTEPERMINUTE = "KiloBytePerMinute"
169-
KILOBYTEPERSECOND = "KiloBytePerSecond"
170-
MSU = "MSU"
171-
MEBIBYTE = "MebiByte"
172-
MEBIBYTEPERHOUR = "MebiBytePerHour"
173-
MEBIBYTEPERMINUTE = "MebiBytePerMinute"
174-
MEBIBYTEPERSECOND = "MebiBytePerSecond"
175-
MEGA = "Mega"
176-
MEGABYTE = "MegaByte"
177-
MEGABYTEPERHOUR = "MegaBytePerHour"
178-
MEGABYTEPERMINUTE = "MegaBytePerMinute"
179-
MEGABYTEPERSECOND = "MegaBytePerSecond"
180-
MICROSECOND = "MicroSecond"
181-
MILLICORES = "MilliCores"
182-
MILLISECOND = "MilliSecond"
183-
MILLISECONDPERMINUTE = "MilliSecondPerMinute"
184-
MINUTE = "Minute"
185-
MONTH = "Month"
186-
NANOSECOND = "NanoSecond"
187-
NANOSECONDPERMINUTE = "NanoSecondPerMinute"
188-
NOTAPPLICABLE = "NotApplicable"
189-
PERHOUR = "PerHour"
190-
PERMINUTE = "PerMinute"
191-
PERSECOND = "PerSecond"
192-
PERCENT = "Percent"
193-
PIXEL = "Pixel"
194-
PROMILLE = "Promille"
195-
RATIO = "Ratio"
196-
SECOND = "Second"
197-
STATE = "State"
198-
UNSPECIFIED = "Unspecified"
199-
WEEK = "Week"
200-
YEAR = "Year"
201-
202-
203144
class MetricDescriptor(DynatraceObject):
204145
def _create_from_raw_data(self, raw_element):
205146

@@ -227,7 +168,7 @@ def _create_from_raw_data(self, raw_element):
227168
self.root_cause_relevant: Optional[bool] = raw_element.get("rootCauseRelevant")
228169
self.tags: Optional[List[str]] = raw_element.get("tags")
229170
self.transformations: Optional[List[Transformation]] = [Transformation(element) for element in raw_element.get("transformations", [])]
230-
self.unit: Optional[Unit] = Unit(raw_element.get("unit")) if raw_element.get("unit") else None
171+
self.unit: Optional[str] = raw_element.get("unit")
231172
self.warnings: Optional[List[str]] = raw_element.get("warnings")
232173

233174

dynatrace/environment_v2/problems.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from dynatrace.http_client import HttpClient
2424
from dynatrace.dynatrace_object import DynatraceObject
2525
from dynatrace.environment_v2.schemas import ManagementZone
26-
from dynatrace.environment_v2.metrics import Unit
2726
from dynatrace.environment_v2.monitored_entities import EntityStub
2827
from dynatrace.environment_v2.custom_tags import METag
2928
from dynatrace.configuration_v1.alerting_profiles import AlertingProfileStub
@@ -228,7 +227,7 @@ def _create_from_raw_data(self, raw_element: Dict[str, Any]):
228227
self.value_before_change_point: Optional[float] = raw_element.get("valueBeforeChangePoint")
229228
self.value_after_change_point: Optional[float] = raw_element.get("valueAfterChangePoint")
230229
self.end_time: Optional[datetime] = int64_to_datetime(raw_element.get("endTime"))
231-
self.unit: Optional[Unit] = Unit(raw_element.get("unit"))
230+
self.unit: Optional[str] = raw_element.get("unit")
232231

233232

234233
class MetricEvidence(Evidence):
@@ -237,7 +236,7 @@ def _create_from_raw_data(self, raw_element: Dict[str, Any]):
237236
self.value_before_change_point: Optional[float] = raw_element.get("valueBeforeChangePoint")
238237
self.value_after_change_point: Optional[float] = raw_element.get("valueAfterChangePoint")
239238
self.end_time: Optional[datetime] = int64_to_datetime(raw_element.get("endTime"))
240-
self.unit: Optional[Unit] = Unit(raw_element.get("unit"))
239+
self.unit: Optional[str] = raw_element.get("unit")
241240
self.metric_id: Optional[str] = raw_element.get("metricId")
242241

243242

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dt"
3-
version = "1.1.73"
3+
version = "1.2.0"
44
description = "Dynatrace API Python client"
55
readme = "README.md"
66
authors = ["David Lopes <[email protected]>"]

test/environment_v2/test_metrics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dynatrace import Dynatrace
22
import pytest
33

4-
from dynatrace.environment_v2.metrics import MetricDescriptor, Unit, AggregationType, Transformation, ValueType, MetricSeriesCollection
4+
from dynatrace.environment_v2.metrics import MetricDescriptor, AggregationType, Transformation, ValueType, MetricSeriesCollection
55
from dynatrace.pagination import PaginatedList
66
from dynatrace.utils import int64_to_datetime
77

@@ -14,7 +14,7 @@ def test_list(dt: Dynatrace):
1414
assert metric.metric_id == "builtin:apps.other.apdex.osAndGeo"
1515
assert metric.display_name == "Apdex (by OS, geolocation) [mobile, custom]"
1616
assert metric.description == ""
17-
assert metric.unit == Unit.NOTAPPLICABLE
17+
assert metric.unit == "NotApplicable"
1818
break
1919

2020

@@ -29,7 +29,7 @@ def test_list_fields(dt: Dynatrace):
2929
assert metric.metric_id == "builtin:apps.other.apdex.osAndGeo"
3030
assert metric.display_name == "Apdex (by OS, geolocation) [mobile, custom]"
3131
assert metric.description == ""
32-
assert metric.unit == Unit.NOTAPPLICABLE
32+
assert metric.unit == "NotApplicable"
3333
assert not metric.ddu_billable
3434
assert metric.created is None
3535
assert metric.last_written == int64_to_datetime(1620514220905)
@@ -60,7 +60,7 @@ def test_list_params(dt: Dynatrace):
6060
assert metric.metric_id == "builtin:host.cpu.idle"
6161
assert metric.display_name == "CPU idle"
6262
assert metric.description == ""
63-
assert metric.unit == Unit.PERCENT
63+
assert metric.unit == "Percent"
6464
assert not metric.ddu_billable
6565
assert metric.last_written == int64_to_datetime(1621030025348)
6666
assert metric.entity_type == ["HOST"]
@@ -77,7 +77,7 @@ def test_get(dt: Dynatrace):
7777
assert metric.metric_id == "builtin:host.cpu.idle"
7878
assert metric.display_name == "CPU idle"
7979
assert metric.description == ""
80-
assert metric.unit == Unit.PERCENT
80+
assert metric.unit == "Percent"
8181
assert not metric.ddu_billable
8282
assert metric.last_written == int64_to_datetime(1621030565348)
8383
assert metric.entity_type == ["HOST"]

0 commit comments

Comments
 (0)