-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework metric formatting in tests to use more of the exporter code
- Loading branch information
Showing
5 changed files
with
62 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
from prometheus_es_exporter import (format_metric_name, | ||
format_label_key, | ||
format_label_value) | ||
from prometheus_es_exporter import group_metrics | ||
|
||
|
||
def format_label(key, value_list): | ||
return format_label_key(key) + '="' + format_label_value(value_list) + '"' | ||
def format_label(key, value): | ||
return key + '="' + value + '"' | ||
|
||
|
||
def format_metric(name_list, label_dict): | ||
name = format_metric_name(name_list) | ||
def format_metrics(metric_name, label_keys, value_dict): | ||
metrics = {} | ||
|
||
if len(label_dict) > 0: | ||
sorted_keys = sorted(label_dict.keys()) | ||
labels = '{' | ||
labels += ','.join([format_label(k, label_dict[k]) for k in sorted_keys]) | ||
labels += '}' | ||
else: | ||
labels = '' | ||
for label_values, value in value_dict.items(): | ||
if len(label_keys) > 0: | ||
# sorted_keys = sorted(label_keys) | ||
labels = '{' | ||
labels += ','.join([format_label(label_keys[i], label_values[i]) | ||
for i in range(len(label_keys))]) | ||
labels += '}' | ||
else: | ||
labels = '' | ||
|
||
return name + labels | ||
metrics[metric_name + labels] = value | ||
|
||
return metrics | ||
|
||
|
||
# Converts the parse_response() result into a psuedo-prometheus format | ||
# that is useful for comparing results in tests. | ||
# Uses the 'grop_metrics()' function used by the exporter, so effectively | ||
# tests that function. | ||
def convert_result(result): | ||
metric_dict = group_metrics(result) | ||
return { | ||
format_metric(name_list, label_dict): value | ||
for (name_list, label_dict, value) in result | ||
metric: value | ||
for metric_name, (label_keys, value_dict) in metric_dict.items() | ||
for metric, value in format_metrics(metric_name, label_keys, value_dict).items() | ||
} |