Skip to content

Commit

Permalink
Merge pull request kruize#1291 from shreyabiradar07/datasource-manife…
Browse files Browse the repository at this point in the history
…st-test

Refactor and include datasource manifest test
  • Loading branch information
chandrams authored Sep 16, 2024
2 parents a0cfc02 + e103b37 commit dd74ca2
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 899 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.cpu\", type=\"hard\"})",
"version": ""
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.cpu\", type=\"hard\"})"
}
]
},
Expand All @@ -262,8 +261,7 @@
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.cpu\", type=\"hard\"})",
"version": ""
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.cpu\", type=\"hard\"})"
}
]
},
Expand All @@ -275,8 +273,7 @@
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.memory\", type=\"hard\"})",
"version": ""
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"requests.memory\", type=\"hard\"})"
}
]
},
Expand All @@ -288,8 +285,7 @@
"aggregation_functions": [
{
"function": "sum",
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.memory\", type=\"hard\"})",
"version": ""
"query": "sum by (namespace) (kube_resourcequota{namespace=\"$NAMESPACE$\", resource=\"limits.memory\", type=\"hard\"})"
}
]
},
Expand All @@ -301,18 +297,15 @@
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "min_over_time(sum by(namespace) (node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -324,18 +317,15 @@
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "min_over_time(sum by(namespace) (rate(container_cpu_cfs_throttled_seconds_total{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''}[5m]))[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -347,18 +337,15 @@
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "min_over_time(sum by(namespace) (container_memory_working_set_bytes{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -370,18 +357,15 @@
"aggregation_functions": [
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "max",
"query": "max_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "min",
"query": "min_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "min_over_time(sum by(namespace) (container_memory_rss{namespace=\"$NAMESPACE$\", container!='', container!='POD', pod!=''})[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -393,13 +377,11 @@
"aggregation_functions": [
{
"function": "max",
"query": "max_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) ((kube_pod_info{namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -411,13 +393,11 @@
"aggregation_functions": [
{
"function": "max",
"query": "max_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "max_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])"
},
{
"function": "avg",
"query": "avg_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])",
"version": ""
"query": "avg_over_time(sum by(namespace) ((kube_pod_status_phase{phase=\"Running\", namespace=\"$NAMESPACE$\"}))[$MEASUREMENT_DURATION_IN_MIN$m:])"
}
]
},
Expand All @@ -429,8 +409,7 @@
"aggregation_functions": [
{
"function": "max",
"query": "max(last_over_time(timestamp((sum by (namespace) (container_cpu_usage_seconds_total{namespace=\"$NAMESPACE$\"})) > 0 )[15d:]))",
"version": ""
"query": "max(last_over_time(timestamp((sum by (namespace) (container_cpu_usage_seconds_total{namespace=\"$NAMESPACE$\"})) > 0 )[15d:]))"
}
]
}
Expand Down
48 changes: 48 additions & 0 deletions tests/scripts/common/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,31 @@ function create_performance_profile() {
fi
}

function create_metric_profile() {
metric_profile_json=$1

echo "Forming the curl command to create the metric profile ..."
form_curl_cmd

curl_cmd="${curl_cmd}/createMetricProfile -d @${metric_profile_json}"

echo "curl_cmd = ${curl_cmd}"

status_json=$($curl_cmd)
echo "create metric profile status = ${status_json}"

echo ""
echo "Command used to create the metric profile = ${curl_cmd}"
echo ""

metric_profile_status=$(echo ${status_json} | jq '.status')
echo "create metric profile status = ${metric_profile_status}"
if [ "${metric_profile_status}" != \"SUCCESS\" ]; then
echo "Failed! Create metric profile failed. Status - ${metric_profile_status}"
exit 1
fi
}

#
# "local" flag is turned off by default for now. This needs to be set to true.
#
Expand All @@ -1876,3 +1901,26 @@ function kruize_local_patch() {
sed -i 's/"local": "false"/"local": "true"/' ${KRUIZE_CRC_DEPLOY_MANIFEST_OPENSHIFT}
fi
}

#
# Modify "serviceName" and "namespace" datasource manifest fields based on input parameters
#
function kruize_local_datasource_manifest_patch() {
CRC_DIR="./manifests/crc/default-db-included-installation"
KRUIZE_CRC_DEPLOY_MANIFEST_OPENSHIFT="${CRC_DIR}/openshift/kruize-crc-openshift.yaml"
KRUIZE_CRC_DEPLOY_MANIFEST_MINIKUBE="${CRC_DIR}/minikube/kruize-crc-minikube.yaml"

if [ ${cluster_type} == "minikube" ]; then
if [[ ! -z "${servicename}" && ! -z "${datasource_namespace}" ]]; then
sed -i 's/"serviceName": "[^"]*"/"serviceName": "'${servicename}'"/' ${KRUIZE_CRC_DEPLOY_MANIFEST_MINIKUBE}
sed -i 's/"namespace": "[^"]*"/"namespace": "'${datasource_namespace}'"/' ${KRUIZE_CRC_DEPLOY_MANIFEST_MINIKUBE}
sed -i 's/"url": ".*"/"url": ""/' ${KRUIZE_CRC_DEPLOY_MANIFEST_MINIKUBE}
fi
elif [ ${cluster_type} == "openshift" ]; then
if [[ ! -z "${servicename}" && ! -z "${datasource_namespace}" ]]; then
sed -i 's/"serviceName": "[^"]*"/"serviceName": "'${servicename}'"/' ${KRUIZE_CRC_DEPLOY_MANIFEST_OPENSHIFT}
sed -i 's/"namespace": "[^"]*"/"namespace": "'${datasource_namespace}'"/' ${KRUIZE_CRC_DEPLOY_MANIFEST_OPENSHIFT}
sed -i 's/"url": ".*"/"url": ""/' ${KRUIZE_CRC_DEPLOY_MANIFEST_OPENSHIFT}
fi
fi
}
8 changes: 7 additions & 1 deletion tests/scripts/functional_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ do
testcase=*)
testcase=${OPTARG#*=}
;;
servicename=*)
servicename=${OPTARG#*=}
;;
datasource_namespace=*)
datasource_namespace=${OPTARG#*=}
;;
resultsdir=*)
resultsdir=${OPTARG#*=}
;;
Expand Down Expand Up @@ -86,7 +92,7 @@ mkdir -p "${RESULTS}"

SETUP_LOG="${TEST_DIR}/setup.log"

if [ ! $testsuite == "remote_monitoring_tests" ]; then
if [ "$testsuite" != "remote_monitoring_tests" ] && [ "$testsuite" != "local_monitoring_tests" ]; then
CONFIGMAP="${RESULTS}/test_configmap"
mkdir ${CONFIGMAP}

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/helpers/kruize.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def form_kruize_url(cluster_type, SERVER_IP=None):

subprocess.run(['oc expose svc/kruize -n openshift-tuning'], shell=True, stdout=subprocess.PIPE)
ip = subprocess.run(
['oc status -n openshift-tuning | grep "kruize" | grep port | cut -d " " -f1 | cut -d "/" -f3'], shell=True,
['oc status -n openshift-tuning | grep "kruize" | grep -v "kruize-ui" "kruize-db" | grep port | cut -d " " -f1 | cut -d "/" -f3'], shell=True,
stdout=subprocess.PIPE)
SERVER_IP = ip.stdout.decode('utf-8').strip('\n')
print("IP = ", SERVER_IP)
Expand Down
10 changes: 10 additions & 0 deletions tests/scripts/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import docker
from datetime import datetime, timedelta
from kubernetes import client, config
from pathlib import Path

SUCCESS_STATUS_CODE = 201
SUCCESS_200_STATUS_CODE = 200
Expand Down Expand Up @@ -1412,3 +1413,12 @@ def wait_for_container_to_complete(container_id):
)
exit_code = result.stdout.strip()
print(f"Container {container_id} has completed with exit code {exit_code}.")

def get_metric_profile_dir():
# Get the current directory
current_directory = Path(__file__).resolve().parent
# Navigate up 3 levels and build the path to the 'manifests/app/adreess' directory
base_dir = current_directory.parents[2] # (index 2 because it's zero-based)
metric_profile_dir = base_dir / 'manifests' / 'autotune' / 'performance-profiles'

return metric_profile_dir
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def main(argv):
namespace = "openshift-tuning"

# Create the metric profile
perf_profile_json_file = "../json_files/resource_optimization_openshift.json"
create_metric_profile(perf_profile_json_file)
metric_profile_dir = get_metric_profile_dir()
metric_profile_json_file = metric_profile_dir / 'resource_optimization_local_monitoring.json'
create_metric_profile(metric_profile_json_file)

list_reco_json_dir = results_dir + "/list_reco_jsons"
list_datasources_json_dir = results_dir + "/list_datasources_jsons"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

CURRENT_DIR="$(dirname "$(realpath "$0")")"
KRUIZE_REPO="${CURRENT_DIR}/../../../../"

METRIC_PROFILE_DIR="${LOCAL_MONITORING_TEST_DIR}/../../../manifests/autotune/performance-profiles"

# Source the common functions scripts
. ${CURRENT_DIR}/../../common/common_functions.sh
Expand All @@ -30,7 +30,7 @@ APP_NAME=kruize
CLUSTER_TYPE=minikube
NAMESPACE=monitoring

RESOURCE_OPTIMIZATION_JSON="../json_files/resource_optimization_openshift.json"
RESOURCE_OPTIMIZATION_JSON="${METRIC_PROFILE_DIR}/resource_optimization_local_monitoring.json"

target="crc"
KRUIZE_IMAGE="quay.io/kruize/autotune:mvp_demo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "v2.0",
"experiment_name": "monitor_tfb-db_benchmark",
"cluster_name": "default",
"performance_profile": "resource-optimization-openshift",
"performance_profile": "resource-optimization-local-monitoring",
"mode": "monitor",
"target_cluster": "local",
"datasource": "prometheus-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "v2.0",
"experiment_name": "monitor_tfb_benchmark",
"cluster_name": "default",
"performance_profile": "resource-optimization-openshift",
"performance_profile": "resource-optimization-local-monitoring",
"mode": "monitor",
"target_cluster": "local",
"datasource": "prometheus-1",
Expand Down
Loading

0 comments on commit dd74ca2

Please sign in to comment.