-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CRD, abstractions and DB table for metadata profile
- Loading branch information
1 parent
268063a
commit 33a8893
Showing
15 changed files
with
772 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
manifests/autotune/metadata-profiles/cluster-metadata-local-monitoring.json
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,44 @@ | ||
{ | ||
"apiVersion": "recommender.com/v1", | ||
"kind": "KruizeMetadataProfile", | ||
"metadata": { | ||
"name": "cluster-metadata-local-monitoring" | ||
}, | ||
"profile_version": 1, | ||
"k8s_type": "openshift", | ||
"query_variables": [ | ||
{ | ||
"name": "namespacesAcrossCluster", | ||
"datasource": "prometheus", | ||
"kubernetes_object": "container", | ||
"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", | ||
"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", | ||
"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]))" | ||
} | ||
] | ||
} | ||
] | ||
} |
78 changes: 78 additions & 0 deletions
78
manifests/autotune/metadata-profiles/kruize-metadata-profile-crd.yaml
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,78 @@ | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
#name must match the spec fields below, and be in the form: <plural>.<group> | ||
name: kruizemetadataprofiles.recommender.com | ||
spec: | ||
# group name to use for REST API: /apis/<group>/<version> | ||
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 metadata 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 | ||
kubernetes_object: | ||
description: 'k8s object that this query is tied to: "deployment", "pod" or "container"' | ||
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 | ||
versions: | ||
description: 'Any specific versions that this query is tied to' | ||
type: string | ||
required: | ||
- function | ||
- query | ||
required: | ||
- name | ||
- datasource | ||
required: | ||
- query_variables |
73 changes: 73 additions & 0 deletions
73
manifests/autotune/metadata-profiles/kruize-metadata-profile-example.yaml
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,73 @@ | ||
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 | ||
kubernetes_object: "container" # or namespace | ||
aggregation_functions: | ||
- function: sum | ||
query: 'sum by (namespace) (avg_over_time(kube_namespace_status_phase{namespace!=""}[15d]))' | ||
|
||
- 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]))' | ||
|
||
- 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]))' | ||
|
||
- 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]))' | ||
|
||
- 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]))' | ||
|
||
- 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]))' | ||
|
||
|
||
- 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]))' | ||
|
||
|
||
- 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]))' | ||
|
||
# or 'containersForCustomLabel' | ||
- name: 'containersForAdditionalLabel' | ||
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]))' |
28 changes: 28 additions & 0 deletions
28
manifests/autotune/metadata-profiles/kruize-metadata-profile.yaml
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,28 @@ | ||
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 | ||
kubernetes_object: "container" # or 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 | ||
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 | ||
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]))' |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/autotune/analyzer/metadataProfiles/MetadataProfile.java
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,79 @@ | ||
package com.autotune.analyzer.metadataProfiles; | ||
|
||
import com.autotune.common.data.metrics.Metric; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Container class for the MetadataProfile kubernetes kind, which is used to define | ||
* a metadata queries | ||
* | ||
* This class provides a direct representation of MetadataProfile CRD in JSON format, | ||
* corresponding to the structure of MetadataProfile YAML file. It includes mandatory fields | ||
* for API version, kind, metadata and additional custom fields - profile_version, k8s_type and query_variables | ||
*/ | ||
|
||
public class MetadataProfile { | ||
private String apiVersion; | ||
|
||
private String kind; | ||
|
||
private JsonNode metadata; | ||
|
||
private String name; | ||
|
||
private double profile_version; | ||
|
||
@SerializedName("k8s_type") | ||
private String k8s_type; | ||
|
||
@SerializedName("query_variables") | ||
private ArrayList<Metric> metrics; | ||
|
||
public MetadataProfile(String apiVersion, String kind, JsonNode metadata, | ||
double profile_version, String k8s_type, ArrayList<Metric> metrics) { | ||
|
||
this.apiVersion = apiVersion; | ||
this.kind = kind; | ||
this.metadata = metadata; | ||
this.profile_version = profile_version; | ||
this.k8s_type = k8s_type; | ||
this.metrics = metrics; | ||
} | ||
|
||
public JsonNode getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public double getProfile_version() { | ||
return profile_version; | ||
} | ||
|
||
public String getK8s_type() { | ||
return k8s_type; | ||
} | ||
|
||
public ArrayList<Metric> getQueryVariables() { | ||
return new ArrayList<>(metrics); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MetadataProfile{" + | ||
"apiVersion='" + apiVersion + '\'' + | ||
", kind='" + kind + '\'' + | ||
", metadata=" + metadata + | ||
", name='" + name + '\'' + | ||
", profile_version=" + profile_version + | ||
", k8s_type='" + k8s_type + '\'' + | ||
", query_variables=" + metrics + | ||
'}'; | ||
} | ||
|
||
} |
Oops, something went wrong.