-
Notifications
You must be signed in to change notification settings - Fork 0
Add query to calculate cost of PV change with CloudCost exporter metrics #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,31 @@ avg by (spot) (node_ram_hourly_cost{cluster="%s"} | |
| cloudcost_gcp_gke_instance_memory_usd_per_gib_hour{cluster_name="%s"} | ||
| ) | ||
| ` | ||
| queryPersistentVolumeCost = "avg_over_time(avg(pv_hourly_cost{cluster=\"%s\"})[24h:1m])" | ||
| queryPersistentVolumeCost = ` | ||
| avg_over_time( | ||
| avg( | ||
| pv_hourly_cost{cluster="%s"} | ||
| )[24h:1m] | ||
| )` | ||
| cloudcostQueryPersistentVolumeCost = ` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason to use 24h for opencost vs instant query for cloudcost-exporter metrics?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question! During the hackathon, I had arbitrarily picked a 24h lookup window. When testing out the new queries, there was a negligible difference between using a lookback vs instant query. The resulting values were ~$.00001 different. I don't think that difference is worth the computational increase of issuing the queries with a 24h look back.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't really link to the explore's as they would surface internal metrics. If you want, I can share the explores in slack There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the details, no need to hard proof them :) 👍🏼 |
||
| avg( | ||
| cloudcost_aws_ec2_persistent_volume_usd_per_hour{persistentvolume!="", state="in-use"} | ||
| / on (persistentvolume) group_left() ( | ||
| kube_persistentvolume_capacity_bytes{cluster="%s"} / 1e9 | ||
| ) | ||
| ) | ||
| or | ||
| avg( | ||
| cloudcost_gcp_gke_persistent_volume_usd_per_hour{persistentvolume!="", use_status="in-use", cluster_name="%s"} | ||
| / on (persistentvolume) group_left() ( | ||
| kube_persistentvolume_capacity_bytes{cluster="%s"} / 1e9 | ||
| ) | ||
| ) | ||
| or | ||
| avg( | ||
| pv_hourly_cost{cluster="%s"} | ||
| ) | ||
| ` | ||
|
|
||
| queryAverageNodeCount = ` | ||
| avg_over_time( | ||
|
|
@@ -212,6 +236,10 @@ func (c *Client) GetNodeCount(ctx context.Context, cluster string) (int, error) | |
| // GetCostForPersistentVolume returns the average cost per persistent volume for a given cluster | ||
| func (c *Client) GetCostForPersistentVolume(ctx context.Context, cluster string) (Cost, error) { | ||
| query := fmt.Sprintf(queryPersistentVolumeCost, cluster) | ||
| if c.useCloudCostExporterMetrics { | ||
| slog.Info("GetCostForPersistentVolume", "cluster", cluster, "message", "using cloudcost exporter metrics") | ||
| query = fmt.Sprintf(cloudcostQueryPersistentVolumeCost, cluster, cluster, cluster, cluster) | ||
| } | ||
| results, err := c.query(ctx, query) | ||
| if err != nil { | ||
| return Cost{}, err | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| { | ||
| "apiVersion": "apps/v1", | ||
| "kind": "StatefulSet", | ||
| "metadata": { | ||
| "creationTimestamp": "2022-10-05T20:38:31Z", | ||
| "generation": 17, | ||
| "labels": { | ||
| "kustomize.toolkit.fluxcd.io/name": "kube-manifests-opencost", | ||
| "kustomize.toolkit.fluxcd.io/namespace": "opencost", | ||
| "tanka.dev/environment": "85ead74422d749cb54711e74c81bc5d6ed6da54e92b5fa69" | ||
| }, | ||
| "name": "opencost", | ||
| "namespace": "opencost", | ||
| "resourceVersion": "2386985939", | ||
| "uid": "56495ef8-2650-46e8-9528-28759cf47151" | ||
| }, | ||
| "spec": { | ||
| "podManagementPolicy": "OrderedReady", | ||
| "replicas": 1, | ||
| "revisionHistoryLimit": 10, | ||
| "selector": { | ||
| "matchLabels": { | ||
| "name": "opencost" | ||
| } | ||
| }, | ||
| "serviceName": "opencost", | ||
| "template": { | ||
| "metadata": { | ||
| "creationTimestamp": null, | ||
| "labels": { | ||
| "name": "opencost" | ||
| } | ||
| }, | ||
| "spec": { | ||
| "affinity": { | ||
| "nodeAffinity": { | ||
| "preferredDuringSchedulingIgnoredDuringExecution": [ | ||
| { | ||
| "preference": { | ||
| "matchExpressions": [ | ||
| { | ||
| "key": "cloud.google.com/gke-spot", | ||
| "operator": "In", | ||
| "values": [ | ||
| "true" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "weight": 100 | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "containers": [ | ||
| { | ||
| "env": [ | ||
| ], | ||
| "image": "quay.io/kubecost1/kubecost-cost-model:prod-1.100.0", | ||
| "imagePullPolicy": "IfNotPresent", | ||
| "name": "opencost", | ||
| "ports": [ | ||
| { | ||
| "containerPort": 9003, | ||
| "name": "http-metrics", | ||
| "protocol": "TCP" | ||
| } | ||
| ], | ||
| "resources": { | ||
| "limits": { | ||
| "cpu": "4", | ||
| "memory": "8Gi" | ||
| }, | ||
| "requests": { | ||
| "cpu": "1", | ||
| "memory": "4Gi" | ||
| } | ||
| }, | ||
| "terminationMessagePath": "/dev/termination-log", | ||
| "terminationMessagePolicy": "File", | ||
| "volumeMounts": [ | ||
| { | ||
| "mountPath": "/var/configs", | ||
| "name": "opencost-data" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "dnsPolicy": "ClusterFirst", | ||
| "restartPolicy": "Always", | ||
| "schedulerName": "default-scheduler", | ||
| "securityContext": { | ||
| "fsGroup": 10001 | ||
| }, | ||
| "serviceAccount": "opencost", | ||
| "serviceAccountName": "opencost", | ||
| "terminationGracePeriodSeconds": 30, | ||
| "tolerations": [ | ||
| { | ||
| "effect": "NoSchedule", | ||
| "key": "type", | ||
| "operator": "Equal", | ||
| "value": "spot-node" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "updateStrategy": { | ||
| "type": "RollingUpdate" | ||
| }, | ||
| "volumeClaimTemplates": [ | ||
| { | ||
| "apiVersion": "v1", | ||
| "kind": "PersistentVolumeClaim", | ||
| "metadata": { | ||
| "creationTimestamp": null, | ||
| "name": "opencost-data" | ||
| }, | ||
| "spec": { | ||
| "accessModes": [ | ||
| "ReadWriteOnce" | ||
| ], | ||
| "resources": { | ||
| "requests": { | ||
| "storage": "320Gi" | ||
| } | ||
| }, | ||
| "volumeMode": "Filesystem" | ||
| }, | ||
| "status": { | ||
| "phase": "Pending" | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| "status": { | ||
| "availableReplicas": 1, | ||
| "collisionCount": 0, | ||
| "currentReplicas": 1, | ||
| "currentRevision": "opencost-6666f8bdb7", | ||
| "observedGeneration": 17, | ||
| "readyReplicas": 1, | ||
| "replicas": 1, | ||
| "updateRevision": "opencost-6666f8bdb7", | ||
| "updatedReplicas": 1 | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.