Skip to content

Commit ee98200

Browse files
committed
some more refactor
1 parent 1e9cf5f commit ee98200

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

temporal/scripts/generate_metadata.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def append_metric_metadata(metric_name, metric_type='count', unit_name=None):
9797
for temporal_name, dd_metric in METRIC_MAP.items():
9898
if isinstance(dd_metric, dict) and dd_metric.get('type') == 'native_dynamic':
9999
# Native dynamic metrics have its type defined at run time, and usually added manually, see https://github.com/DataDog/integrations-core/pull/18050
100-
existing_dd_metric, existed_dd_metric = check_existing_metric(
100+
existing_dd_metric = check_existing_metric(
101101
dd_metric.get('name'), previous_metadata, added_dd_metrics
102102
)
103-
if existed_dd_metric:
103+
if bool(existing_dd_metric):
104104
print(
105105
f"INFO: dynamic metric `{dd_metric}` is reserved because it's present "
106106
"in the current metadata.csv file"
@@ -113,15 +113,14 @@ def append_metric_metadata(metric_name, metric_type='count', unit_name=None):
113113
)
114114
continue
115115

116-
try:
117-
temporal_type = temporal_metric_types[temporal_name]
118-
except KeyError:
116+
temporal_type = temporal_metric_types.get(temporal_name)
117+
if temporal_type is None:
119118
# If metrics does not exist in this Temporal version, try to search metric in
120119
# the current metadata file and preserve it if it's already exist
121-
existing_dd_metric, existed_dd_metric = check_existing_metric(
120+
existing_dd_metric = check_existing_metric(
122121
dd_metric, previous_metadata, added_dd_metrics
123122
)
124-
if existed_dd_metric:
123+
if bool(existing_dd_metric):
125124
metadata.extend(existing_dd_metric)
126125
else:
127126
print(
@@ -189,7 +188,7 @@ def extract_metric_defs(go_code: str) -> dict:
189188
return results
190189

191190

192-
def check_existing_metric(name: str, previous_metadata: dict, added_dd_metrics: set) -> tuple[list, bool]:
191+
def check_existing_metric(name: str, previous_metadata: dict, added_dd_metrics: set) -> list:
193192
"""
194193
Check if a metric exists in the previous metadata and add it to the current metadata if found.
195194
@@ -201,16 +200,14 @@ def check_existing_metric(name: str, previous_metadata: dict, added_dd_metrics:
201200
tuple: (metadata list with any existing metrics added, boolean indicating if metric exists)
202201
"""
203202
pattern = re.compile(rf"^temporal\.server\.{re.escape(name)}(?:\.[a-z]+)*$")
204-
exist = False
205203
result = []
206204
for dd_metric in previous_metadata:
207205
if pattern.match(dd_metric) and dd_metric not in added_dd_metrics:
208206
# A metric were supported in the previous temporal version, but dropped in the current temporal version
209207
result.append(previous_metadata.get(dd_metric))
210208
print(f"INFO: {dd_metric} is reserved because it exists in the current metatadata.csv file")
211-
exist = True
212209
added_dd_metrics.add(dd_metric)
213-
return result, exist
210+
return result
214211

215212

216213
def fetch_temporal_metrics(tag: str) -> str:

0 commit comments

Comments
 (0)