diff --git a/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.json b/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.json new file mode 100644 index 000000000..88e340b9b --- /dev/null +++ b/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.json @@ -0,0 +1,47 @@ +{ + "apiVersion": "recommender.com/v1", + "kind": "KruizeMetadataProfile", + "metadata": { + "name": "cluster-metadata-local-monitoring" + }, + "profile_version": 1, + "k8s_type": "openshift", + "query_variables": [ + { + "name": "namespacesAcrossCluster", + "datasource": "prometheus", + "value_type": "double", + "kubernetes_object": "container", + "aggregation_functions": [ + { + "function": "sum", + "query": "sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=\"\"}[$MEASUREMENT_DURATION_IN_MIN$m]))" + } + ] + }, + { + "name": "workloadsAcrossCluster", + "datasource": "prometheus", + "value_type": "double", + "kubernetes_object": "container", + "aggregation_functions": [ + { + "function": "sum", + "query": "sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=\"\"}[$MEASUREMENT_DURATION_IN_MIN$m]))" + } + ] + }, + { + "name": "containersAcrossCluster", + "datasource": "prometheus", + "value_type": "double", + "kubernetes_object": "container", + "aggregation_functions": [ + { + "function": "sum", + "query": "sum by (container, image, workload, workload_type, namespace) (avg_over_time(kube_pod_container_info{container!=\"\"}[$MEASUREMENT_DURATION_IN_MIN$m]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=\"\"}[$MEASUREMENT_DURATION_IN_MIN$m]))" + } + ] + } + ] +} \ No newline at end of file diff --git a/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.yaml b/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.yaml new file mode 100644 index 000000000..9015d8507 --- /dev/null +++ b/manifests/autotune/metadata-profiles/cluster_metadata_local_monitoring.yaml @@ -0,0 +1,31 @@ +apiVersion: "recommender.com/v1" +kind: "KruizeMetadataProfile" +metadata: + name: "cluster-metadata-local-monitoring" +profile_version: 1.0 +k8s_type: openshift +query_variables: + +- name: namespacesAcrossCluster + datasource: prometheus + value_type: "double" + kubernetes_object: "namespace" + aggregation_functions: + - function: sum + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))' + +- name: workloadsAcrossCluster + datasource: prometheus + value_type: "double" + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))' + +- name: containersAcrossCluster + datasource: prometheus + value_type: "double" + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (container, image, workload, workload_type, namespace) (avg_over_time(kube_pod_container_info{container!=""}[$MEASUREMENT_DURATION_IN_MIN$d]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))' \ No newline at end of file diff --git a/manifests/autotune/metadata-profiles/kruize-metadata-profile-crd.yaml b/manifests/autotune/metadata-profiles/kruize-metadata-profile-crd.yaml new file mode 100644 index 000000000..4a8ce5697 --- /dev/null +++ b/manifests/autotune/metadata-profiles/kruize-metadata-profile-crd.yaml @@ -0,0 +1,85 @@ +apiVersion: "recommender.com/v1" +kind: CustomResourceDefinition +metadata: + #name must match the spec fields below, and be in the form: . + name: kruizemetadataprofiles.recommender.com +spec: + # group name to use for REST API: /apis// + group: "recommender.com" + names: + plural: kruizemetadataprofiles + singular: kruizemetadataprofile + #types can be identified with this tag + kind: KruizeMetadataProfile + scope: Namespaced + versions: + - name: v1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/ + community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/ + community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + profile_version: + description: 'Version of the profile' + type: number + k8s_type: + description: 'minikube or openshift' + type: string + query_variables: + description: 'Query variables to be used' + type: array + items: + type: object + properties: + name: + description: 'name of the variable' + type: string + datasource: + description: 'datasource of the query' + type: string + value_type: + description: 'can be double or integer' + type: string + kubernetes_object: + description: 'k8s object that this query is tied to: "deployment", "pod", "namespace" or "container"' + type: string + query: + description: 'one of the query or aggregation_functions is mandatory' + type: string + aggregation_functions: + description: 'one of the query or aggregation_functions is mandatory' + type: array + items: + type: object + properties: + function: + description: 'aggregate functions associated with this variable' + type: string + query: + description: 'query' + type: string + version: + description: 'Any specific version that this query is tied to' + type: string + required: + - function + - query + required: + - name + - datasource + - value_type + required: + - query_variables \ No newline at end of file diff --git a/manifests/autotune/metadata-profiles/kruize-metadata-profile-supported-queries.yaml b/manifests/autotune/metadata-profiles/kruize-metadata-profile-supported-queries.yaml new file mode 100644 index 000000000..a652b3801 --- /dev/null +++ b/manifests/autotune/metadata-profiles/kruize-metadata-profile-supported-queries.yaml @@ -0,0 +1,87 @@ +apiVersion: "recommender.com/v1" +kind: "KruizeMetadataProfile" +metadata: + name: "cluster-metadata-local-monitoring" +profile_version: 1.0 +k8s_type: openshift +query_variables: + +# list of namespaces across cluster +- name: 'namespacesAcrossCluster' + datasource: prometheus + kubernetes_object: "container" # or namespace + aggregation_functions: + - function: sum + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[15d]))' + + +# list of namespaces for specified org_id and cluster_id +- name: 'namespacesForOrgAndClusterId' + datasource: prometheus + kubernetes_object: "container" # or namespace + aggregation_functions: + - function: sum + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!="", org_id="$org_id$", cluster_id="$cluster_id$"}[15d]))' + + +# list of namespaces for user specified custom label +- name: 'namespacesForAdditionalLabel' # or 'namespacesForCustomLabel' + datasource: prometheus + kubernetes_object: "container" # or namespace + aggregation_functions: + - function: sum + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[15d]))' + + +# list of all the workloads across cluster +- name: 'workloadsAcrossCluster' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=""}[15d]))' + + +# list of workloads for specified org_id and cluster_id +- name: 'workloadsForOrgAndClusterId' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!="", org_id="$org_id$", cluster_id="$cluster_id$"}[15d]))' + + +# list of workloads for user specified custom label +- name: 'workloadsForAdditionalLabel' # or 'workloadsForCustomLabel' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!="" ADDITIONAL_LABEL}[15d]))' + + +# list of all the containers across cluster +- name: 'containersAcrossCluster' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (container, image, workload, workload_type, namespace) (avg_over_time(kube_pod_container_info{container!=""}[15d]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=""}[15d]))' + + +# list of containers for specified org_id and cluster_id +- name: 'containersForOrgAndClusterId' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (container, image, workload, workload_type, namespace) (avg_over_time(kube_pod_container_info{container!="", org_id="$org_id$", cluster_id="$cluster_id$"}[15d]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!="", org_id="$org_id$", cluster_id="$cluster_id$"}[15d]))' + + +# list of containers for user specified custom label +- name: 'containersForAdditionalLabel' # or 'containersForCustomLabel' + datasource: prometheus + kubernetes_object: "container" + aggregation_functions: + - function: sum + query: 'sum by (container, image, workload, workload_type, namespace) (avg_over_time(kube_pod_container_info{container!="" ADDITIONAL_LABEL}[15d]) * on (pod, namespace) group_left(workload, workload_type) avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!="" ADDITIONAL_LABEL}[15d]))' \ No newline at end of file diff --git a/manifests/autotune/metadata-profiles/metadata-profile-template.yaml b/manifests/autotune/metadata-profiles/metadata-profile-template.yaml new file mode 100644 index 000000000..752800349 --- /dev/null +++ b/manifests/autotune/metadata-profiles/metadata-profile-template.yaml @@ -0,0 +1,62 @@ +apiVersion: "recommender.com/v1" +kind: "KruizeMetadataProfile" +metadata: + name: "add_name_here" + +# Version of the profile. +# This helps when queries change often +profile_version: 1.0 + +# Is this for a specific kubernetes type? +# OPTIONAL. +# If not present, assumed to be used universally. +# If specified, it should have a corresponding config in +# manifests/configmaps dir (i.e. supported target by Kruize) +# Eg. manifests/configmaps/openshift-config.yaml +k8s_type: openshift + +# Describe the query variables to be used +# MANDATORY +query_variables: + +# name of the variable +# MANDATORY +- name: namespacesAcrossCluster + # datasource of the query + # MANDATORY + datasource: prometheus + # value_type. Supported are "double" or "integer". + # MANDATORY + value_type: "double" + + # Any k8s object that this query is tied to + # eg. "deployment", "pod", "container" + # OPTIONAL + kubernetes_object: "namespace" + + # One of query or aggregation_functions mandatory + # Both can be present together + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))' + + # aggregate functions associated with this variable + # Eg. "avg", "sum", "max", "min" + aggregation_functions: + # MANDATORY + - function: sum + # query + # MANDATORY + query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))' + + # Any specific versions that this query is tied to + # OPTIONAL + version: ">4.9" + +# list of all the workloads present in the cluster +- name: workloadsAcrossCluster + datasource: prometheus + value_type: "double" + kubernetes_object: "container" + # sum of the pod ownership metrics, grouped by namespace, workload, and workload_type, filtering out empty workloads. + aggregation_functions: + - function: sum + query: 'sum by (namespace, workload, workload_type) (avg_over_time(namespace_workload_pod:kube_pod_owner:relabel{workload!=""}[$MEASUREMENT_DURATION_IN_MIN$d]))'