Skip to content

Commit

Permalink
fix: add keep files
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangrewe-bosch committed Jan 26, 2024
1 parent a35cb9a commit cc0569c
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 95 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ specified:
```text
graphite {
#light = false
host = "10.1.1.5" # AKS node IP
host = "10.1.1.5" # Apollo node IP
port = 32766 # GraphiteExporter
protocol = "tcp"
rootPathPrefix = "gatling"
Expand Down Expand Up @@ -290,14 +290,16 @@ To add or remove test-cases the following steps must be peformed:
A Simulation class contains multiple scenario(s),

- Define scenario(s) which contain(s) group(s): The scenario name is not
relevant and only used for logical separation. A group divides one or multiple
requests for which the *response times* and *cAdvisor charts* are created.
relevant and only used for logical separation. A *group* combines one or
multiple requests for which the *response times* and *cAdvisor charts* are
created.
- The *generate_x\_.py* scripts automatically create for each *group* the
corresponding charts.
- If *groups* are created or deleted, the mkdocs report needs to be updated
manually.
- Update nav.yaml to include or exclude the *group*
- Update the file in reports/(amphora|castor|ephemeral)
- Naming convention for groups: `{request_name}_{test_objective}`, e.g.
createSecret_10000
- After a run of caliper the python scripts located under `/scripts` will
generate the cAdvisor and gatling respones times charts, as well as the
markdown files for the report.

## Namesake

Expand Down
Binary file not shown.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
31 changes: 31 additions & 0 deletions scripts/python/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mkdocs:
charts:
amphora_simulation: "mkdocs/docs/images/charts/amphorasimulation"
ephemeral_simulation: "mkdocs/docs/images/charts/ephemeralsimulation"
report: "mkdocs/docs/report"

simulation:
time_delta: 5
groups:
amphora:
createSecret: 'caliper{simulation="amphorasimulation", group=~"createSecret_.*", metric="percentiles99", scope="ok"}'
getSecret: 'caliper{simulation="amphorasimulation", group=~"getSecret_.*", metric="percentiles99", scope="ok"}'
deleteSecret: 'caliper{simulation="amphorasimulation", group=~"deleteSecret_.*", metric="percentiles99", scope="ok"}'
ephemeral:
execute: 'caliper{simulation="ephemeralsimulation", group=~"execute_.*", metric="percentiles99", scope="ok"}'

cAdvisor:
metric_names:
- 'container_memory_working_set_bytes'
- 'container_cpu_usage_seconds_total'
- 'container_fs_writes_bytes_total'
- 'container_fs_reads_bytes_total'
- 'container_network_receive_bytes_total'
- 'container_network_transmit_bytes_total'
metric_templates:
- 'container_memory_working_set_bytes{{container="{container}", pod=~"{pod}.*", service="kubelet"}}'
- 'irate(container_cpu_usage_seconds_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}[5m])'
- 'container_fs_writes_bytes_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}'
- 'container_fs_reads_bytes_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}'
- 'container_network_receive_bytes_total{{pod=~"{pod}.*", service="kubelet"}}'
- 'container_network_transmit_bytes_total{{pod=~"{pod}.*", service="kubelet"}}'
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import logging.config
import os
from datetime import datetime, timedelta, timezone

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
import yaml
from prometheus_api_client import PrometheusConnect, MetricRangeDataFrame

# Path to the MkDocs folder
home_dir = os.environ['HOME']
AMPHORA_CHART_PATH = os.path.join(home_dir, 'caliper', 'mkdocs', 'docs', 'images', 'charts', 'amphorasimulation')
EPHEMERAL_CHART_PATH = os.path.join(home_dir, 'caliper', 'mkdocs', 'docs', 'images', 'charts', 'ephemeralsimulation')
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('generate_cAdvisor_charts')

# config file
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)

# Prometheus Server Address
APOLLO_NODE_IP = os.environ['APOLLO_NODE_IP']
STARBUCK_NODE_IP = os.environ['STARBUCK_NODE_IP']
PROMETHEUS_SERVER_PORT = os.environ['PROMETHEUS_SERVER_PORT']
Expand All @@ -21,46 +25,26 @@
STARBUCK_PROMETHEUS_CLIENT = PrometheusConnect(url=f"http://{STARBUCK_NODE_IP}:{PROMETHEUS_SERVER_PORT}",
disable_ssl=True)

HOME_DIR = HOME_DIR = os.getcwd() # os.environ['HOME'] # TODO change to home_env

END_TIME = datetime.now(timezone.utc) # Prometheus uses UTC
START_TIME = END_TIME - timedelta(hours=5)

"""
Graphite and InfluxDB can’t store distributions but only numbers.
As a result, only one-second-resolution non-aggregated response time stats are correct.
That means all statistics for a single request hold the same value which is the response time but gatling
still exports all statistics (min, max, mean, ...), to reduce the size of the dataset only one metric
is fetched, e.g. percentiles99
"""
AMPHORA_SIMULATION_GROUPS = 'caliper{simulation="amphorasimulation", metric="percentiles99", scope="ok"}'
EPHEMERAL_SIMULATION_GROUPS = 'caliper{simulation="ephemeralsimulation", metric="percentiles99", scope="ok"}'

# The metric name is part of the file name
CADVISOR_METRICS = [
'container_memory_working_set_bytes',
'container_cpu_usage_seconds_total',
'container_fs_writes_bytes_total',
'container_fs_reads_bytes_total',
'container_network_receive_bytes_total',
'container_network_transmit_bytes_total']

CADVISOR_METRICS_TEMPLATE = [
# container_memory_working_set_bytes
'container_memory_working_set_bytes{{container="{container}", pod=~"{pod}.*", service="kubelet"}}',
# container_cpu_usage_seconds_total
'irate(container_cpu_usage_seconds_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}[5m])',
# container_fs_writes_bytes_total
'container_fs_writes_bytes_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}',
# container_fs_reads_bytes_total
'container_fs_reads_bytes_total{{container="{container}", pod=~"{pod}.*", service="kubelet"}}',
# container_network_receive_bytes_total
'container_network_receive_bytes_total{{pod=~"{pod}.*", service="kubelet"}}',
# container_network_transmit_bytes_total
'container_network_transmit_bytes_total{{pod=~"{pod}.*", service="kubelet"}}']


def generate_cadvisor_metrics(container, pod):
START_TIME = END_TIME - timedelta(hours=config['simulation']['time_delta'])

CADVISOR_METRICS = config['cadvisor_metrics']
CADVISOR_METRICS_TEMPLATE = config['cadvisor_metrics_template']

AMPHORA_CHART_PATH = os.path.join(HOME_DIR, config['mkdocs']['chart_paths']['amphora_simulation'])
EPHEMERAL_CHART_PATH = os.path.join(HOME_DIR, config['mkdocs']['chart_paths']['ephemeral_simulation'])

AMPHORA_SIMULATION_CREATE_SECRET_GROUPS = config['simulation_groups']['amphora']['createSecret']
AMPHORA_SIMULATION_GET_SECRET_GROUPS = config['simulation_groups']['amphora']['getSecret']
AMPHORA_SIMULATION_DELETE_SECRET_GROUPS = config['simulation_groups']['amphora']['deleteSecret']
EPHEMERAL_SIMULATION_GROUPS = config['simulation_groups']['ephemeral']['execute']
AMPHORA_SIMULATION_GROUPS = pd.concat([AMPHORA_SIMULATION_CREATE_SECRET_GROUPS, AMPHORA_SIMULATION_GET_SECRET_GROUPS,
AMPHORA_SIMULATION_DELETE_SECRET_GROUPS], ignore_index=False)


def generate_cAdvisor_metrics(container, pod):
all_metrics = []

metric = [metric_query.format(container=container, pod=pod)
Expand All @@ -70,9 +54,9 @@ def generate_cadvisor_metrics(container, pod):
return all_metrics


AMPHORA_CADVISOR_METRICS = generate_cadvisor_metrics(container="amphora", pod="cs-amphora")
CASTOR_CADVISOR_METRICS = generate_cadvisor_metrics(container="castor", pod="cs-castor")
EPHEMERAL_CADVISOR_METRICS = generate_cadvisor_metrics(container="ephemeral-ephemeral", pod="ephemeral")
AMPHORA_CADVISOR_METRICS = generate_cAdvisor_metrics(container="amphora", pod="cs-amphora")
CASTOR_CADVISOR_METRICS = generate_cAdvisor_metrics(container="castor", pod="cs-castor")
EPHEMERAL_CADVISOR_METRICS = generate_cAdvisor_metrics(container="ephemeral-ephemeral", pod="ephemeral")

amphora_simulation_groups_dict = APOLLO_PROMETHEUS_CLIENT.custom_query_range(query=AMPHORA_SIMULATION_GROUPS,
start_time=START_TIME,
Expand All @@ -82,31 +66,33 @@ def generate_cadvisor_metrics(container, pod):
start_time=START_TIME,
end_time=END_TIME, step='15s')
# Time ranges per group
amphora_simulation_groups_df = MetricRangeDataFrame(amphora_simulation_groups_dict)
amphora_simulation_groups_df["timestamp"] = amphora_simulation_groups_df.index
if len(amphora_simulation_groups_dict) > 0:
amphora_simulation_groups_df = MetricRangeDataFrame(amphora_simulation_groups_dict)
amphora_simulation_groups_df["timestamp"] = amphora_simulation_groups_df.index

# ephemeral_simulation_groups_df = MetricRangeDataFrame(ephemeral_simulation_groups_dict)
# ephemeral_simulation_groups_df["timestamp"] = amphora_simulation_groups_df.index
if len(ephemeral_simulation_groups_dict) > 0:
ephemeral_simulation_groups_df = MetricRangeDataFrame(ephemeral_simulation_groups_dict)
ephemeral_simulation_groups_df["timestamp"] = amphora_simulation_groups_df.index

amphora_simulation_groups_start_times = amphora_simulation_groups_df.groupby("group")['timestamp'].min()
amphora_simulation_groups_end_times = amphora_simulation_groups_df.groupby("group")['timestamp'].max()

# ephemeral_simulation_groups_start_times = ephemeral_simulation_groups_df.groupby("group")['timestamp'].min()
# ephemeral_simulation_groups_end_times = ephemeral_simulation_groups_df.groupby("group")['timestamp'].max()
ephemeral_simulation_groups_start_times = ephemeral_simulation_groups_df.groupby("group")['timestamp'].min()
ephemeral_simulation_groups_end_times = ephemeral_simulation_groups_df.groupby("group")['timestamp'].max()


def create_charts_for_groups(groups, cadvisor_metrics_names, cadvisor_metrics_promQL, simulation_groups_start_times,
simulation_groups_end_times, dir, service_name):
def generate_cAdvisor_charts(groups, cadvisor_metrics_names, cadvisor_metrics_promQL, simulation_groups_start_times,
simulation_groups_end_times, chart_path, service):
"""
Plots metrics for specified groups and metrics.
Generates charts for specified groups and metrics.
:param groups: Series containing group names.
:param cadvisor_metrics_names: List with metric names.
:param cadvisor_metrics_promQL: List with corresponding PromQL queries.
:param simulation_groups_start_time: OBJECT with start times per group for a simulation
:param simulation_groups_end_time: OBJECT with end time per group for a simulation
:param dir: directory to store charts
:param service_name: Name of the service.
:param simulation_groups_start_time: start times per group for a simulation.
:param simulation_groups_end_time: end time per group for a simulation.
:param chart_path: directory to store charts.
:param service: Name of the service.
"""
for group in groups:
for metric_name, promQL in zip(cadvisor_metrics_names, cadvisor_metrics_promQL):
Expand Down Expand Up @@ -161,44 +147,44 @@ def create_charts_for_groups(groups, cadvisor_metrics_names, cadvisor_metrics_pr
plt.subplots_adjust(left=0.1)

# Save the chart to the specified path
file_name = f"{service_name}_{group}_{metric_name}"
file_path = os.path.join(dir, service_name, file_name)
file_name = f"{service}_{group}_{metric_name}"
file_path = os.path.join(chart_path, service, file_name)
plt.savefig(file_path)
plt.close()


# Create charts for the amphora service from the amphorasimulation
create_charts_for_groups(groups=amphora_simulation_groups_df['group'].drop_duplicates(),
generate_cAdvisor_charts(groups=amphora_simulation_groups_df['group'].drop_duplicates(),
cadvisor_metrics_names=CADVISOR_METRICS,
cadvisor_metrics_promQL=AMPHORA_CADVISOR_METRICS,
simulation_groups_start_times=amphora_simulation_groups_start_times,
simulation_groups_end_times=amphora_simulation_groups_start_times,
dir=AMPHORA_CHART_PATH,
service_name="amphora")
chart_path=AMPHORA_CHART_PATH,
service="amphora")

# Create charts for the castor service from the amphorasimulation
create_charts_for_groups(groups=amphora_simulation_groups_df['group'].drop_duplicates(),
generate_cAdvisor_charts(groups=amphora_simulation_groups_df['group'].drop_duplicates(),
cadvisor_metrics_names=CADVISOR_METRICS,
cadvisor_metrics_promQL=CASTOR_CADVISOR_METRICS,
simulation_groups_start_times=amphora_simulation_groups_start_times,
simulation_groups_end_times=amphora_simulation_groups_start_times,
dir=AMPHORA_CHART_PATH,
service_name="castor")
chart_path=AMPHORA_CHART_PATH,
service="castor")

# Create charts for the castor service from the amphorasimulation
# create_charts_for_groups(groups=ephemeral_simulation_groups_df['group'].drop_duplicates(),
# cadvisor_metrics_names=CADVISOR_METRICS,
# cadvisor_metrics_promQL=EPHEMERAL_CADVISOR_METRICS,
# simulation_groups_start_times=ephemeral_simulation_groups_start_times,
# simulation_groups_end_times=ephemeral_simulation_groups_start_times,
# path=EPHEMERAL_CHART_PATH,
# service_name="ephemeral")

# Create charts for the castor service from the amphorasimulation
# create_charts_for_groups(groups=ephemeral_simulation_groups_df['group'].drop_duplicates(),
# cadvisor_metrics_names=CADVISOR_METRICS,
# cadvisor_metrics_promQL=CASTOR_CADVISOR_METRICS,
# simulation_groups_start_times=ephemeral_simulation_groups_start_times,
# simulation_groups_end_times=ephemeral_simulation_groups_start_times,
# path=EPHEMERAL_CHART_PATH,
# service_name="castor")
# Create charts for the castor service from the ephemeralsimulation
generate_cAdvisor_charts(groups=ephemeral_simulation_groups_df['group'].drop_duplicates(),
cadvisor_metrics_names=CADVISOR_METRICS,
cadvisor_metrics_promQL=EPHEMERAL_CADVISOR_METRICS,
simulation_groups_start_times=ephemeral_simulation_groups_start_times,
simulation_groups_end_times=ephemeral_simulation_groups_start_times,
path=EPHEMERAL_CHART_PATH,
service_name="ephemeral")

# Create charts for the castor service from the ephemeralsimulation
generate_cAdvisor_charts(groups=ephemeral_simulation_groups_df['group'].drop_duplicates(),
cadvisor_metrics_names=CADVISOR_METRICS,
cadvisor_metrics_promQL=CASTOR_CADVISOR_METRICS,
simulation_groups_start_times=ephemeral_simulation_groups_start_times,
simulation_groups_end_times=ephemeral_simulation_groups_start_times,
path=EPHEMERAL_CHART_PATH,
service_name="castor")
Loading

0 comments on commit cc0569c

Please sign in to comment.