-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added resolution AVG to the measurements table * (feature): Added modular importer for metrics instead of inline in runner * Added more measurement test data * (tests): For phase stats and metrics importer * Rework metric provider processing mechanism and removed storing to DB / run_id run_id is now added in segmented helper metric_importer. Run ID is a concept the metric providers should not be aware of and is thus handled now externally. Furthermore the processing mechanism in the providers does now not allow overloading of externally callable functions in read_metrics(). New private sub functions are created that go through different steps of reading, parsing, validation and adding data. * Added tests * (improvement): Added all powermetrics metrics to phase_stats to remove warnings * (improvement): Close StringIO buffer to prevent leaks if long runtime * (consistency):containers is always required for function * (improvement): _check_empty introduced to have no magic assumptions about if provider can or cannot return empty rows * (style): Typos and indents * (fix): Tests where missing assert * (improvement): Reading twice reduced to one in test helper * (Tests): Fix Tests * (fix): Duplicate name in phase_stats without functionality * (style): Namings and typos * Changed powermetrics file to non time underflow * (fix): Removed email column from tests also
- Loading branch information
Showing
47 changed files
with
246,353 additions
and
327 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from io import StringIO | ||
|
||
from lib.db import DB | ||
from metric_providers.network.connections.tcpdump.system.provider import generate_stats_string | ||
|
||
def import_measurements_new(df, metric_name, run_id): | ||
|
||
df['measurement_metric_id'] = None # prepare | ||
detail_names = df[['detail_name', 'unit']].drop_duplicates() | ||
|
||
for _, row in detail_names.iterrows(): | ||
measurement_metric_id = DB().fetch_one(''' | ||
INSERT INTO measurement_metrics (run_id, metric, detail_name, unit) | ||
VALUES (%s, %s, %s, %s) | ||
RETURNING id | ||
''', params=(run_id, metric_name, row['detail_name'], row['unit']))[0] | ||
df.loc[(df['detail_name'] == row['detail_name']) & (df['unit'] == row['unit']), 'measurement_metric_id'] = measurement_metric_id | ||
|
||
f = StringIO(df[['measurement_metric_id', 'value', 'time']] | ||
.to_csv(index=False, header=False)) | ||
DB().copy_from(file=f, table='measurement_values', columns=['measurement_metric_id', 'value', 'time'], sep=',') | ||
f.close() | ||
|
||
def import_measurements(df, metric_name, run_id, containers=None): | ||
|
||
if metric_name == 'network_connections_proxy_container_dockerproxy': | ||
|
||
df['run_id'] = run_id | ||
f = StringIO(df.to_csv(index=False, header=False)) | ||
DB().copy_from(file=f, table='network_intercepts', columns=df.columns, sep=',') | ||
f.close() | ||
|
||
elif metric_name == 'network_connections_tcpdump_system': | ||
DB().query(""" | ||
UPDATE runs | ||
SET logs= COALESCE(logs, '') || %s -- append | ||
WHERE id = %s | ||
""", params=(generate_stats_string(df), run_id)) | ||
|
||
else: | ||
|
||
if 'container_id' in df.columns: | ||
df = map_container_id_to_detail_name(df, containers) | ||
|
||
df['run_id'] = run_id | ||
|
||
f = StringIO(df.to_csv(index=False, header=False)) | ||
DB().copy_from(file=f, table='measurements', columns=df.columns, sep=',') | ||
f.close() | ||
|
||
def map_container_id_to_detail_name(df, containers): | ||
df['detail_name'] = df.container_id | ||
for container_id in containers: | ||
df.loc[df.detail_name == container_id, 'detail_name'] = containers[container_id]['name'] | ||
df = df.drop('container_id', axis=1) | ||
|
||
return df |
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
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
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
Oops, something went wrong.