Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change prometheus query handling #157

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions breeder/linux_network_stack/effectuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def run_reconnaissance():
retry=urllib3.util.retry.Retry(total=3, raise_on_status=True, backoff_factor=0.5),
disable_ssl=True)

start_time = parse_datetime("2m")
end_time = parse_datetime("now")
chunk_size = timedelta(minutes=1)

metric_data = dict()
for objective in config.get('objectives'):
recon_service_type = objective.get('reconaissance').get('service')
Expand All @@ -64,8 +60,25 @@ def run_reconnaissance():
query_name = objective.get('name')

query_result = prom_conn.custom_query(recon_query)
metric_value = query_result[0]
metric_data[query_name] = metric_value.get('value')[1]

if query_result.get('resultType') != 'scalar':
raise Exception("Custom Query must be of result type scalar.")

# Example format of result processed
# "data": {
# "resultType": "scalar",
# "result": [
# 1703619892.31, << TS
# "0.401370548" << Value
# ]
# }

value = metric_value.get('result')[1]

if value == "NaN":
raise Exception("Scalar reduction of custom query probably ailing, only returning NaN.")

metric_data[query_name] = value
else:
raise Exception("Reconnaisance service type {recon_service_type} not supported yet.")

Expand Down
4 changes: 2 additions & 2 deletions examples/network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ breeder:
direction: minimize
reconaissance:
service: prometheus
query: "quantile(0.5, tcp_rtt)" # median
query: "scalar(quantile(0.5, tcp_rtt))" # median
- name: "tcp_delivery_rate_bytes"
direction: maximize
reconaissance:
service: prometheus
query: "quantile(0.5, tcp_delivery_rate_bytes)" # median
query: "scalar(quantile(0.5, tcp_delivery_rate_bytes))" # median
effectuation:
targets:
- user: godon_robot
Expand Down
Loading