|
|
@@ -3,6 +3,7 @@ package source
|
|
|
import (
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/opencost/opencost/core/pkg/log"
|
|
|
"github.com/opencost/opencost/core/pkg/util"
|
|
|
)
|
|
|
|
|
|
@@ -13,34 +14,49 @@ const (
|
|
|
RegionLabel = "region"
|
|
|
ClusterIDLabel = "cluster_id"
|
|
|
NamespaceLabel = "namespace"
|
|
|
+ NamespaceUIDLabel = "namespace_uid"
|
|
|
NodeLabel = "node"
|
|
|
+ NodeUIDLabel = "node_uid"
|
|
|
InstanceLabel = "instance"
|
|
|
InstanceTypeLabel = "instance_type"
|
|
|
ContainerLabel = "container"
|
|
|
PodLabel = "pod"
|
|
|
+ PodUIDLabel = "pod_uid"
|
|
|
PodNameLabel = "pod_name"
|
|
|
+ PodVolumeNameLabel = "pod_volume_name"
|
|
|
ProviderIDLabel = "provider_id"
|
|
|
DeviceLabel = "device"
|
|
|
PVCLabel = "persistentvolumeclaim"
|
|
|
+ PVCUIDLabel = "persistentvolumeclaim_uid"
|
|
|
PVLabel = "persistentvolume"
|
|
|
+ CSIVolumeHandleLabel = "csi_volume_handle"
|
|
|
StorageClassLabel = "storageclass"
|
|
|
VolumeNameLabel = "volumename"
|
|
|
+ PVUIDLabel = "persistentvolume_uid"
|
|
|
ServiceLabel = "service"
|
|
|
ServiceNameLabel = "service_name"
|
|
|
+ ServiceTypeLabel = "service_type"
|
|
|
IngressIPLabel = "ingress_ip"
|
|
|
+ LBIngressAddress = "lb_ingress_address"
|
|
|
ProvisionerNameLabel = "provisioner_name"
|
|
|
UIDLabel = "uid"
|
|
|
KubernetesNodeLabel = "kubernetes_node"
|
|
|
ModeLabel = "mode"
|
|
|
ModelNameLabel = "modelName"
|
|
|
+ HostNameLabel = "Hostname"
|
|
|
UUIDLabel = "UUID"
|
|
|
ResourceLabel = "resource"
|
|
|
DeploymentLabel = "deployment"
|
|
|
StatefulSetLabel = "statefulSet"
|
|
|
+ DaemonSetLabel = "daemonset"
|
|
|
+ JobLabel = "job"
|
|
|
+ CronJobLabel = "cronjob"
|
|
|
ReplicaSetLabel = "replicaset"
|
|
|
ResourceQuotaLabel = "resourcequota"
|
|
|
OwnerNameLabel = "owner_name"
|
|
|
OwnerKindLabel = "owner_kind"
|
|
|
+ OwnerUIDLabel = "owner_uid"
|
|
|
+ ControllerLabel = "controller"
|
|
|
UnitLabel = "unit"
|
|
|
InternetLabel = "internet"
|
|
|
SameZoneLabel = "same_zone"
|
|
|
@@ -52,6 +68,41 @@ const (
|
|
|
NoneLabelValue = "<none>"
|
|
|
)
|
|
|
|
|
|
+type UIDValueResult struct {
|
|
|
+ UID string
|
|
|
+ Value float64
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeUIDValueResult(result *QueryResult) *UIDValueResult {
|
|
|
+ return decodeValueResult(result, UIDLabel)
|
|
|
+}
|
|
|
+
|
|
|
+type NodeUIDValueResult UIDValueResult
|
|
|
+
|
|
|
+func DecodeNodeUIDValueResult(result *QueryResult) *NodeUIDValueResult {
|
|
|
+ return (*NodeUIDValueResult)(decodeValueResult(result, NodeUIDLabel))
|
|
|
+}
|
|
|
+
|
|
|
+type PVCUIDValueResult UIDValueResult
|
|
|
+
|
|
|
+func DecodePVCUIDValueResult(result *QueryResult) *PVCUIDValueResult {
|
|
|
+ return (*PVCUIDValueResult)(decodeValueResult(result, PVCUIDLabel))
|
|
|
+}
|
|
|
+
|
|
|
+func decodeValueResult(result *QueryResult, uidLabel string) *UIDValueResult {
|
|
|
+ uid, _ := result.GetString(uidLabel)
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding value for uid '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
+ return &UIDValueResult{
|
|
|
+ UID: uid,
|
|
|
+ Value: value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// UptimeResult represents the first and last recorded sample timestamp within the query window
|
|
|
type UptimeResult struct {
|
|
|
UID string
|
|
|
@@ -60,30 +111,7 @@ type UptimeResult struct {
|
|
|
}
|
|
|
|
|
|
func (res *UptimeResult) GetStartEnd(windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
|
|
|
- first := res.First
|
|
|
- last := res.Last
|
|
|
- // The only corner-case here is what to do if you only get one timestamp.
|
|
|
- // This dilemma still requires the use of the resolution, and can be
|
|
|
- // clamped using the window. In this case, we want to honor the existence
|
|
|
- // of the pod by giving "one resolution" worth of duration, half on each
|
|
|
- // side of the given timestamp.
|
|
|
- if first.Equal(last) {
|
|
|
- first = first.Add(-1 * resolution / time.Duration(2))
|
|
|
- last = last.Add(resolution / time.Duration(2))
|
|
|
- }
|
|
|
- if first.Before(windowStart) {
|
|
|
- first = windowStart
|
|
|
- }
|
|
|
- if last.After(windowEnd) {
|
|
|
- last = windowEnd
|
|
|
- }
|
|
|
- // prevent end times in the future
|
|
|
- now := time.Now().UTC()
|
|
|
- if last.After(now) {
|
|
|
- last = now
|
|
|
- }
|
|
|
-
|
|
|
- return first, last
|
|
|
+ return getStartEnd(res.First, res.Last, windowStart, windowEnd, resolution)
|
|
|
}
|
|
|
|
|
|
func DecodeUptimeResult(result *QueryResult) *UptimeResult {
|
|
|
@@ -98,14 +126,78 @@ func DecodeUptimeResult(result *QueryResult) *UptimeResult {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Container requires some special results because container name and pod UID is required to uniqly identify it
|
|
|
+
|
|
|
+type ContainerUptimeResult struct {
|
|
|
+ UptimeResult
|
|
|
+ Container string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeContainerUptimeResult(result *QueryResult) *ContainerUptimeResult {
|
|
|
+ container, _ := result.GetString(ContainerLabel)
|
|
|
+ ur := DecodeUptimeResult(result)
|
|
|
+ return &ContainerUptimeResult{
|
|
|
+ UptimeResult: *ur,
|
|
|
+ Container: container,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type ContainerResourceResult struct {
|
|
|
+ ResourceResult
|
|
|
+ Container string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeContainerResourceResult(result *QueryResult) *ContainerResourceResult {
|
|
|
+ container, _ := result.GetString(ContainerLabel)
|
|
|
+ rr := DecodeResourceResult(result)
|
|
|
+ return &ContainerResourceResult{
|
|
|
+ ResourceResult: *rr,
|
|
|
+ Container: container,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type LabelsResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Labels map[string]string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeLabelsResult(result *QueryResult) *LabelsResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ labels := result.GetLabels()
|
|
|
+
|
|
|
+ return &LabelsResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Labels: labels,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type AnnotationsResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Annotations map[string]string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeAnnotationsResult(result *QueryResult) *AnnotationsResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ annotations := result.GetAnnotations()
|
|
|
+
|
|
|
+ return &AnnotationsResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Annotations: annotations,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type PVResult struct {
|
|
|
- UID string
|
|
|
Cluster string
|
|
|
PersistentVolume string
|
|
|
}
|
|
|
|
|
|
type PVUsedAvgResult struct {
|
|
|
- UID string
|
|
|
Cluster string
|
|
|
Namespace string
|
|
|
PersistentVolumeClaim string
|
|
|
@@ -114,13 +206,11 @@ type PVUsedAvgResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodePVUsedAvgResult(result *QueryResult) *PVUsedAvgResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pvc, _ := result.GetString(PVCLabel)
|
|
|
|
|
|
return &PVUsedAvgResult{
|
|
|
- UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Namespace: namespace,
|
|
|
PersistentVolumeClaim: pvc,
|
|
|
@@ -150,7 +240,6 @@ func DecodePVActiveMinutesResult(result *QueryResult) *PVActiveMinutesResult {
|
|
|
}
|
|
|
|
|
|
type PVUsedMaxResult struct {
|
|
|
- UID string
|
|
|
Cluster string
|
|
|
Namespace string
|
|
|
PersistentVolumeClaim string
|
|
|
@@ -158,13 +247,11 @@ type PVUsedMaxResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodePVUsedMaxResult(result *QueryResult) *PVUsedMaxResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pvc, _ := result.GetString(PVCLabel)
|
|
|
|
|
|
return &PVUsedMaxResult{
|
|
|
- UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Namespace: namespace,
|
|
|
PersistentVolumeClaim: pvc,
|
|
|
@@ -173,7 +260,6 @@ func DecodePVUsedMaxResult(result *QueryResult) *PVUsedMaxResult {
|
|
|
}
|
|
|
|
|
|
type LocalStorageActiveMinutesResult struct {
|
|
|
- UID string
|
|
|
Cluster string
|
|
|
Node string
|
|
|
ProviderID string
|
|
|
@@ -182,7 +268,6 @@ type LocalStorageActiveMinutesResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodeLocalStorageActiveMinutesResult(result *QueryResult) *LocalStorageActiveMinutesResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
node, _ := result.GetNode()
|
|
|
if node == "" {
|
|
|
@@ -191,7 +276,6 @@ func DecodeLocalStorageActiveMinutesResult(result *QueryResult) *LocalStorageAct
|
|
|
providerId, _ := result.GetProviderID()
|
|
|
|
|
|
return &LocalStorageActiveMinutesResult{
|
|
|
- UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Node: node,
|
|
|
ProviderID: providerId,
|
|
|
@@ -315,6 +399,30 @@ func DecodeLocalStorageBytesResult(result *QueryResult) *LocalStorageBytesResult
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type NodeInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Node string
|
|
|
+ ProviderID string
|
|
|
+ InstanceType string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeNodeInfoResult(result *QueryResult) *NodeInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ node, _ := result.GetNode()
|
|
|
+ providerId, _ := result.GetProviderID()
|
|
|
+ instanceType, _ := result.GetInstanceType()
|
|
|
+
|
|
|
+ return &NodeInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Node: node,
|
|
|
+ ProviderID: providerId,
|
|
|
+ InstanceType: instanceType,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type NodeActiveMinutesResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
@@ -339,22 +447,28 @@ func DecodeNodeActiveMinutesResult(result *QueryResult) *NodeActiveMinutesResult
|
|
|
}
|
|
|
|
|
|
type NodeCPUCoresCapacityResult struct {
|
|
|
- UID string
|
|
|
- Cluster string
|
|
|
- Node string
|
|
|
- Data []*util.Vector
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Node string
|
|
|
+ CPUCores float64
|
|
|
}
|
|
|
|
|
|
func DecodeNodeCPUCoresCapacityResult(result *QueryResult) *NodeCPUCoresCapacityResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
node, _ := result.GetNode()
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding node CPU cores capacity result for node '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
|
|
|
return &NodeCPUCoresCapacityResult{
|
|
|
- UID: uid,
|
|
|
- Cluster: cluster,
|
|
|
- Node: node,
|
|
|
- Data: result.Values,
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Node: node,
|
|
|
+ CPUCores: value,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -365,22 +479,28 @@ func DecodeNodeCPUCoresAllocatableResult(result *QueryResult) *NodeCPUCoresAlloc
|
|
|
}
|
|
|
|
|
|
type NodeRAMBytesCapacityResult struct {
|
|
|
- UID string
|
|
|
- Cluster string
|
|
|
- Node string
|
|
|
- Data []*util.Vector
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Node string
|
|
|
+ RAMBytes float64
|
|
|
}
|
|
|
|
|
|
func DecodeNodeRAMBytesCapacityResult(result *QueryResult) *NodeRAMBytesCapacityResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
node, _ := result.GetNode()
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding node RAM bytes capacity result for node '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
|
|
|
return &NodeRAMBytesCapacityResult{
|
|
|
- UID: uid,
|
|
|
- Cluster: cluster,
|
|
|
- Node: node,
|
|
|
- Data: result.Values,
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Node: node,
|
|
|
+ RAMBytes: value,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -395,8 +515,7 @@ type NodeGPUCountResult struct {
|
|
|
Cluster string
|
|
|
Node string
|
|
|
ProviderID string
|
|
|
-
|
|
|
- Data []*util.Vector
|
|
|
+ GPUCount float64
|
|
|
}
|
|
|
|
|
|
func DecodeNodeGPUCountResult(result *QueryResult) *NodeGPUCountResult {
|
|
|
@@ -404,13 +523,19 @@ func DecodeNodeGPUCountResult(result *QueryResult) *NodeGPUCountResult {
|
|
|
cluster, _ := result.GetCluster()
|
|
|
node, _ := result.GetNode()
|
|
|
providerId, _ := result.GetProviderID()
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding node GPU count capacity result for node '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
|
|
|
return &NodeGPUCountResult{
|
|
|
UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Node: node,
|
|
|
ProviderID: providerId,
|
|
|
- Data: result.Values,
|
|
|
+ GPUCount: value,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -519,6 +644,33 @@ func DecodeLBPricePerHrResult(result *QueryResult) *LBPricePerHrResult {
|
|
|
return DecodeLBActiveMinutesResult(result)
|
|
|
}
|
|
|
|
|
|
+type ClusterInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Provider string
|
|
|
+ AccountID string
|
|
|
+ Provisioner string
|
|
|
+ Region string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeClusterInfoResult(result *QueryResult) *ClusterInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetString(ClusterNameLabel)
|
|
|
+ provider, _ := result.GetString(ProviderLabel)
|
|
|
+ accountID, _ := result.GetString(AccountIDLabel)
|
|
|
+ provisioner, _ := result.GetString(ProvisionerNameLabel)
|
|
|
+ region, _ := result.GetString(RegionLabel)
|
|
|
+
|
|
|
+ return &ClusterInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Provider: provider,
|
|
|
+ AccountID: accountID,
|
|
|
+ Provisioner: provisioner,
|
|
|
+ Region: region,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type ClusterManagementDurationResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
@@ -545,6 +697,75 @@ func DecodeClusterManagementPricePerHrResult(result *QueryResult) *ClusterManage
|
|
|
return DecodeClusterManagementDurationResult(result)
|
|
|
}
|
|
|
|
|
|
+type PodInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Pod string
|
|
|
+ NamespaceUID string
|
|
|
+ NodeUID string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodePodInfoResult(result *QueryResult) *PodInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ pod, _ := result.GetPod()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ nodeUID, _ := result.GetString(NodeUIDLabel)
|
|
|
+
|
|
|
+ return &PodInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Pod: pod,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ NodeUID: nodeUID,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type PodPVCVolumeResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ PVCUID string
|
|
|
+ PodVolumeName string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodePodPVCVolumeResult(result *QueryResult) *PodPVCVolumeResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ pvcUID, _ := result.GetString(PVCUIDLabel)
|
|
|
+ podVolumeName, _ := result.GetString(PodVolumeNameLabel)
|
|
|
+
|
|
|
+ return &PodPVCVolumeResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ PVCUID: pvcUID,
|
|
|
+ PodVolumeName: podVolumeName,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type OwnerResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ OwnerUID string
|
|
|
+ OwnerKind string
|
|
|
+ Controller bool
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeOwnerResult(result *QueryResult) *OwnerResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ ownerUID, _ := result.GetString(OwnerUIDLabel)
|
|
|
+ ownerKind, _ := result.GetString(OwnerKindLabel)
|
|
|
+ controller, _ := result.GetBool(ControllerLabel)
|
|
|
+
|
|
|
+ return &OwnerResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ OwnerUID: ownerUID,
|
|
|
+ OwnerKind: ownerKind,
|
|
|
+ Controller: controller,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type PodsResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
@@ -766,7 +987,7 @@ type GPUsUsageAvgResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodeGPUsUsageAvgResult(result *QueryResult) *GPUsUsageAvgResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
+ uid, _ := result.GetString(PodUIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pod, _ := result.GetPod()
|
|
|
@@ -792,7 +1013,7 @@ type GPUsUsageMaxResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodeGPUsUsageMaxResult(result *QueryResult) *GPUsUsageMaxResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
+ uid, _ := result.GetString(PodUIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pod, _ := result.GetPod()
|
|
|
@@ -847,7 +1068,7 @@ type GPUInfoResult struct {
|
|
|
}
|
|
|
|
|
|
func DecodeGPUInfoResult(result *QueryResult) *GPUInfoResult {
|
|
|
- uid, _ := result.GetString(UIDLabel)
|
|
|
+ uid, _ := result.GetString(PodUIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pod, _ := result.GetPod()
|
|
|
@@ -954,18 +1175,21 @@ func DecodePVCBytesRequestedResult(result *QueryResult) *PVCBytesRequestedResult
|
|
|
type PVCInfoResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
+ NamespaceUID string
|
|
|
Namespace string
|
|
|
VolumeName string
|
|
|
+ PVUID string
|
|
|
PersistentVolumeClaim string
|
|
|
StorageClass string
|
|
|
-
|
|
|
- Data []*util.Vector
|
|
|
+ Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
func DecodePVCInfoResult(result *QueryResult) *PVCInfoResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
+ pvUID, _ := result.GetString(PVUIDLabel)
|
|
|
volumeName, _ := result.GetString(VolumeNameLabel)
|
|
|
pvc, _ := result.GetString(PVCLabel)
|
|
|
storageClass, _ := result.GetString(StorageClassLabel)
|
|
|
@@ -973,11 +1197,14 @@ func DecodePVCInfoResult(result *QueryResult) *PVCInfoResult {
|
|
|
return &PVCInfoResult{
|
|
|
UID: uid,
|
|
|
Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
Namespace: namespace,
|
|
|
+ PVUID: pvUID,
|
|
|
VolumeName: volumeName,
|
|
|
PersistentVolumeClaim: pvc,
|
|
|
StorageClass: storageClass,
|
|
|
- Data: result.Values,
|
|
|
+
|
|
|
+ Data: result.Values,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -985,20 +1212,25 @@ type PVBytesResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
PersistentVolume string
|
|
|
-
|
|
|
- Data []*util.Vector
|
|
|
+ Value float64
|
|
|
}
|
|
|
|
|
|
func DecodePVBytesResult(result *QueryResult) *PVBytesResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
pv, _ := result.GetString(PVLabel)
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding PV bytes result for pv '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
|
|
|
return &PVBytesResult{
|
|
|
UID: uid,
|
|
|
Cluster: cluster,
|
|
|
PersistentVolume: pv,
|
|
|
- Data: result.Values,
|
|
|
+ Value: value,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1036,8 +1268,8 @@ type PVInfoResult struct {
|
|
|
PersistentVolume string
|
|
|
StorageClass string
|
|
|
ProviderID string
|
|
|
-
|
|
|
- Data []*util.Vector
|
|
|
+ CSIVolumeHandle string
|
|
|
+ Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
func DecodePVInfoResult(result *QueryResult) *PVInfoResult {
|
|
|
@@ -1046,6 +1278,7 @@ func DecodePVInfoResult(result *QueryResult) *PVInfoResult {
|
|
|
storageClass, _ := result.GetString(StorageClassLabel)
|
|
|
providerId, _ := result.GetProviderID()
|
|
|
pv, _ := result.GetString(PVLabel)
|
|
|
+ csiVolumeHandle, _ := result.GetString(CSIVolumeHandleLabel)
|
|
|
|
|
|
return &PVInfoResult{
|
|
|
UID: uid,
|
|
|
@@ -1053,7 +1286,47 @@ func DecodePVInfoResult(result *QueryResult) *PVInfoResult {
|
|
|
PersistentVolume: pv,
|
|
|
StorageClass: storageClass,
|
|
|
ProviderID: providerId,
|
|
|
- Data: result.Values,
|
|
|
+ CSIVolumeHandle: csiVolumeHandle,
|
|
|
+
|
|
|
+ Data: result.Values,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type PodNetworkBytesResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Service string
|
|
|
+ Internet bool
|
|
|
+ SameRegion bool
|
|
|
+ SameZone bool
|
|
|
+ NatGateway bool
|
|
|
+ Value float64
|
|
|
+}
|
|
|
+
|
|
|
+func DecodePodNetworkBytesResult(result *QueryResult) *PodNetworkBytesResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ service, _ := result.GetString(ServiceLabel)
|
|
|
+ internet, _ := result.GetBool(InternetLabel)
|
|
|
+ sameRegion, _ := result.GetBool(SameRegionLabel)
|
|
|
+ sameZone, _ := result.GetBool(SameZoneLabel)
|
|
|
+ natGateway, _ := result.GetBool(NatGatewayLabel)
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding pod network bytes result for pod '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
+
|
|
|
+ return &PodNetworkBytesResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Service: service,
|
|
|
+ Internet: internet,
|
|
|
+ SameRegion: sameRegion,
|
|
|
+ SameZone: sameZone,
|
|
|
+ NatGateway: natGateway,
|
|
|
+ Value: value,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1118,7 +1391,6 @@ type NetInternetServiceGiBResult = NetworkGiBResult
|
|
|
|
|
|
type NetNatGatewayPricePerGiBResult = NetworkPricePerGiBResult
|
|
|
type NetNatGatewayGiBResult = NetworkGiBResult
|
|
|
-
|
|
|
type NetZoneIngressGiBResult = NetworkGiBResult
|
|
|
type NetRegionIngressGiBResult = NetworkGiBResult
|
|
|
type NetInternetIngressGiBResult = NetworkGiBResult
|
|
|
@@ -1290,7 +1562,6 @@ type NodeLabelsResult struct {
|
|
|
Cluster string
|
|
|
Node string
|
|
|
Labels map[string]string
|
|
|
- Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
func DecodeNodeLabelsResult(result *QueryResult) *NodeLabelsResult {
|
|
|
@@ -1304,7 +1575,24 @@ func DecodeNodeLabelsResult(result *QueryResult) *NodeLabelsResult {
|
|
|
Cluster: cluster,
|
|
|
Node: node,
|
|
|
Labels: labels,
|
|
|
- Data: result.Values,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type NamespaceInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ Namespace string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeNamespaceInfoResult(result *QueryResult) *NamespaceInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespace, _ := result.GetNamespace()
|
|
|
+
|
|
|
+ return &NamespaceInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ Namespace: namespace,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1384,6 +1672,54 @@ func DecodeServiceLabelsResult(result *QueryResult) *ServiceLabelsResult {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type ServiceInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ Service string
|
|
|
+ ServiceType string
|
|
|
+ LBIngressAddress string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeServiceInfoResult(result *QueryResult) *ServiceInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ service, _ := result.GetString(ServiceLabel)
|
|
|
+ serviceType, _ := result.GetString(ServiceTypeLabel)
|
|
|
+ lbIngressAddress, _ := result.GetString(LBIngressAddress)
|
|
|
+
|
|
|
+ return &ServiceInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ Service: service,
|
|
|
+ ServiceType: serviceType,
|
|
|
+ LBIngressAddress: lbIngressAddress,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type DeploymentInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ Deployment string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeDeploymentInfoResult(result *QueryResult) *DeploymentInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ deployment, _ := result.GetString(DeploymentLabel)
|
|
|
+
|
|
|
+ return &DeploymentInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ Deployment: deployment,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type DeploymentLabelsResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
@@ -1410,6 +1746,111 @@ func DecodeDeploymentLabelsResult(result *QueryResult) *DeploymentLabelsResult {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type StatefulSetInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ StatefulSet string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeStatefulSetInfoResult(result *QueryResult) *StatefulSetInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ statefulSet, _ := result.GetString(StatefulSetLabel)
|
|
|
+
|
|
|
+ return &StatefulSetInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ StatefulSet: statefulSet,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type DaemonSetInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ DaemonSet string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeDaemonSetInfoResult(result *QueryResult) *DaemonSetInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ daemonSet, _ := result.GetString(DaemonSetLabel)
|
|
|
+
|
|
|
+ return &DaemonSetInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ DaemonSet: daemonSet,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type JobInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ Job string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeJobInfoResult(result *QueryResult) *JobInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ job, _ := result.GetString(JobLabel)
|
|
|
+
|
|
|
+ return &JobInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ Job: job,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type CronJobInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ CronJob string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeCronJobInfoResult(result *QueryResult) *CronJobInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ cronJob, _ := result.GetString(CronJobLabel)
|
|
|
+
|
|
|
+ return &CronJobInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ CronJob: cronJob,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type ReplicaSetInfoResult struct {
|
|
|
+ UID string
|
|
|
+ Cluster string
|
|
|
+ NamespaceUID string
|
|
|
+ ReplicaSet string
|
|
|
+}
|
|
|
+
|
|
|
+func DecodeReplicaSetInfoResult(result *QueryResult) *ReplicaSetInfoResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ cluster, _ := result.GetCluster()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
+ replicaSet, _ := result.GetString(ReplicaSetLabel)
|
|
|
+
|
|
|
+ return &ReplicaSetInfoResult{
|
|
|
+ UID: uid,
|
|
|
+ Cluster: cluster,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
+ ReplicaSet: replicaSet,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
type StatefulSetLabelsResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
@@ -1436,61 +1877,51 @@ func DecodeStatefulSetLabelsResult(result *QueryResult) *StatefulSetLabelsResult
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type DaemonSetLabelsResult struct {
|
|
|
+type PodsWithDaemonSetOwnerResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
Namespace string
|
|
|
Pod string
|
|
|
DaemonSet string
|
|
|
- Labels map[string]string
|
|
|
- Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
-func DecodeDaemonSetLabelsResult(result *QueryResult) *DaemonSetLabelsResult {
|
|
|
+func DecodePodsWithDaemonSetOwnerResult(result *QueryResult) *PodsWithDaemonSetOwnerResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pod, _ := result.GetPod()
|
|
|
daemonSet, _ := result.GetString(OwnerNameLabel)
|
|
|
- labels := result.GetLabels()
|
|
|
|
|
|
- return &DaemonSetLabelsResult{
|
|
|
+ return &PodsWithDaemonSetOwnerResult{
|
|
|
UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Namespace: namespace,
|
|
|
Pod: pod,
|
|
|
DaemonSet: daemonSet,
|
|
|
- Labels: labels,
|
|
|
- Data: result.Values,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type JobLabelsResult struct {
|
|
|
+type PodsWithJobOwnerResult struct {
|
|
|
UID string
|
|
|
Cluster string
|
|
|
Namespace string
|
|
|
Pod string
|
|
|
Job string
|
|
|
- Labels map[string]string
|
|
|
- Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
-func DecodeJobLabelsResult(result *QueryResult) *JobLabelsResult {
|
|
|
+func DecodePodsWithJobOwnerResult(result *QueryResult) *PodsWithJobOwnerResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
cluster, _ := result.GetCluster()
|
|
|
namespace, _ := result.GetNamespace()
|
|
|
pod, _ := result.GetPod()
|
|
|
job, _ := result.GetString(OwnerNameLabel)
|
|
|
- labels := result.GetLabels()
|
|
|
|
|
|
- return &JobLabelsResult{
|
|
|
+ return &PodsWithJobOwnerResult{
|
|
|
UID: uid,
|
|
|
Cluster: cluster,
|
|
|
Namespace: namespace,
|
|
|
Pod: pod,
|
|
|
Job: job,
|
|
|
- Labels: labels,
|
|
|
- Data: result.Values,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1567,126 +1998,143 @@ func DecodeReplicaSetsWithRolloutResult(result *QueryResult) *ReplicaSetsWithRol
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaMetricResult struct {
|
|
|
+type ResourceQuotaInfoResult struct {
|
|
|
UID string
|
|
|
- Namespace string
|
|
|
+ NamespaceUID string
|
|
|
ResourceQuota string
|
|
|
- Resource string
|
|
|
- Unit string
|
|
|
- Data []*util.Vector
|
|
|
}
|
|
|
|
|
|
-func DecodeResourceQuotaMetricResult(result *QueryResult) *ResourceQuotaMetricResult {
|
|
|
+func DecodeResourceQuotaInfoResult(result *QueryResult) *ResourceQuotaInfoResult {
|
|
|
uid, _ := result.GetString(UIDLabel)
|
|
|
- namespace, _ := result.GetNamespace()
|
|
|
+ namespaceUID, _ := result.GetString(NamespaceUIDLabel)
|
|
|
resourceQuota, _ := result.GetString(ResourceQuotaLabel)
|
|
|
- resource, _ := result.GetString(ResourceLabel)
|
|
|
- unit, _ := result.GetString(UnitLabel)
|
|
|
|
|
|
- return &ResourceQuotaMetricResult{
|
|
|
+ return &ResourceQuotaInfoResult{
|
|
|
UID: uid,
|
|
|
- Namespace: namespace,
|
|
|
+ NamespaceUID: namespaceUID,
|
|
|
ResourceQuota: resourceQuota,
|
|
|
- Resource: resource,
|
|
|
- Unit: unit,
|
|
|
- Data: result.Values,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaSpecCPURequestAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecCPURequestAvgResult(result *QueryResult) *ResourceQuotaSpecCPURequestAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecCPURequestMaxResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecCPURequestMaxResult(result *QueryResult) *ResourceQuotaSpecCPURequestMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecRAMRequestAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecRAMRequestAvgResult(result *QueryResult) *ResourceQuotaSpecRAMRequestAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecRAMRequestMaxResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecRAMRequestMaxResult(result *QueryResult) *ResourceQuotaSpecRAMRequestMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecCPULimitAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecCPULimitAvgResult(result *QueryResult) *ResourceQuotaSpecCPULimitAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecCPULimitMaxResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecCPULimitMaxResult(result *QueryResult) *ResourceQuotaSpecCPULimitMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
-}
|
|
|
-
|
|
|
-type ResourceQuotaSpecRAMLimitAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaSpecRAMLimitAvgResult(result *QueryResult) *ResourceQuotaSpecRAMLimitAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+type ResourceResult struct {
|
|
|
+ UID string
|
|
|
+ Resource string
|
|
|
+ Unit string
|
|
|
+ Value float64
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaSpecRAMLimitMaxResult = ResourceQuotaMetricResult
|
|
|
+func DecodeResourceResult(result *QueryResult) *ResourceResult {
|
|
|
+ uid, _ := result.GetString(UIDLabel)
|
|
|
+ resource, _ := result.GetString(ResourceLabel)
|
|
|
+ unit, _ := result.GetString(UnitLabel)
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding resource for uid '%s': empty value returned", uid)
|
|
|
+ }
|
|
|
|
|
|
-func DecodeResourceQuotaSpecRAMLimitMaxResult(result *QueryResult) *ResourceQuotaSpecRAMLimitMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+ return &ResourceResult{
|
|
|
+ UID: uid,
|
|
|
+ Resource: resource,
|
|
|
+ Unit: unit,
|
|
|
+ Value: value,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedCPURequestAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaStatusUsedCPURequestAvgResult(result *QueryResult) *ResourceQuotaStatusUsedCPURequestAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+// DCGM needs specialized results because it uses UUID instead of the uid label that we use.
|
|
|
+type DCGMDeviceInfoResult struct {
|
|
|
+ UUID string
|
|
|
+ Device string
|
|
|
+ ModelName string
|
|
|
+ HostName string
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedCPURequestMaxResult = ResourceQuotaMetricResult
|
|
|
+func DecodeDCGMDeviceInfoResult(result *QueryResult) *DCGMDeviceInfoResult {
|
|
|
+ uuid, _ := result.GetString(UUIDLabel)
|
|
|
+ device, _ := result.GetString(DeviceLabel)
|
|
|
+ modelName, _ := result.GetString(ModelNameLabel)
|
|
|
+ hostName, _ := result.GetString(HostNameLabel)
|
|
|
|
|
|
-func DecodeResourceQuotaStatusUsedCPURequestMaxResult(result *QueryResult) *ResourceQuotaStatusUsedCPURequestMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+ return &DCGMDeviceInfoResult{
|
|
|
+ UUID: uuid,
|
|
|
+ Device: device,
|
|
|
+ ModelName: modelName,
|
|
|
+ HostName: hostName,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedRAMRequestAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaStatusUsedRAMRequestAvgResult(result *QueryResult) *ResourceQuotaStatusUsedRAMRequestAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+type DCGMDeviceUptimeResult struct {
|
|
|
+ UUID string
|
|
|
+ First time.Time
|
|
|
+ Last time.Time
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedRAMRequestMaxResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaStatusUsedRAMRequestMaxResult(result *QueryResult) *ResourceQuotaStatusUsedRAMRequestMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+func (res *DCGMDeviceUptimeResult) GetStartEnd(windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
|
|
|
+ return getStartEnd(res.First, res.Last, windowStart, windowEnd, resolution)
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedCPULimitAvgResult = ResourceQuotaMetricResult
|
|
|
+func getStartEnd(first, last, windowStart, windowEnd time.Time, resolution time.Duration) (time.Time, time.Time) {
|
|
|
+ // The only corner-case here is what to do if you only get one timestamp.
|
|
|
+ // This dilemma still requires the use of the resolution, and can be
|
|
|
+ // clamped using the window. In this case, we want to honor the existence
|
|
|
+ // of the pod by giving "one resolution" worth of duration, half on each
|
|
|
+ // side of the given timestamp.
|
|
|
+ if first.Equal(last) {
|
|
|
+ first = first.Add(-1 * resolution / time.Duration(2))
|
|
|
+ last = last.Add(resolution / time.Duration(2))
|
|
|
+ }
|
|
|
+ if first.Before(windowStart) {
|
|
|
+ first = windowStart
|
|
|
+ }
|
|
|
+ if last.After(windowEnd) {
|
|
|
+ last = windowEnd
|
|
|
+ }
|
|
|
+ // prevent end times in the future
|
|
|
+ now := time.Now().UTC()
|
|
|
+ if last.After(now) {
|
|
|
+ last = now
|
|
|
+ }
|
|
|
|
|
|
-func DecodeResourceQuotaStatusUsedCPULimitAvgResult(result *QueryResult) *ResourceQuotaStatusUsedCPULimitAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+ return first, last
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedCPULimitMaxResult = ResourceQuotaMetricResult
|
|
|
+func DecodeDCGMDeviceUptimeResult(result *QueryResult) *DCGMDeviceUptimeResult {
|
|
|
+ uuid, _ := result.GetString(UUIDLabel)
|
|
|
+ first := time.Unix(int64(result.Values[0].Timestamp), 0).UTC()
|
|
|
+ last := time.Unix(int64(result.Values[len(result.Values)-1].Timestamp), 0).UTC()
|
|
|
|
|
|
-func DecodeResourceQuotaStatusUsedCPULimitMaxResult(result *QueryResult) *ResourceQuotaStatusUsedCPULimitMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+ return &DCGMDeviceUptimeResult{
|
|
|
+ UUID: uuid,
|
|
|
+ First: first,
|
|
|
+ Last: last,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedRAMLimitAvgResult = ResourceQuotaMetricResult
|
|
|
-
|
|
|
-func DecodeResourceQuotaStatusUsedRAMLimitAvgResult(result *QueryResult) *ResourceQuotaStatusUsedRAMLimitAvgResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+type DCGMDeviceContainerUsageResult struct {
|
|
|
+ UUID string
|
|
|
+ PodUID string
|
|
|
+ Container string
|
|
|
+ Value float64
|
|
|
}
|
|
|
|
|
|
-type ResourceQuotaStatusUsedRAMLimitMaxResult = ResourceQuotaMetricResult
|
|
|
+func DecodeDCGMDeviceContainerUsageResult(result *QueryResult) *DCGMDeviceContainerUsageResult {
|
|
|
+ uuid, _ := result.GetString(UUIDLabel)
|
|
|
+ podUID, _ := result.GetString(PodUIDLabel)
|
|
|
+ container, _ := result.GetString(ContainerLabel)
|
|
|
+ var value float64
|
|
|
+ if len(result.Values) > 0 {
|
|
|
+ value = result.Values[0].Value
|
|
|
+ } else {
|
|
|
+ log.Warnf("Error decoding DCGM Device Container Udage Result for device '%s': empty value returned", uuid)
|
|
|
+ }
|
|
|
|
|
|
-func DecodeResourceQuotaStatusUsedRAMLimitMaxResult(result *QueryResult) *ResourceQuotaStatusUsedRAMLimitMaxResult {
|
|
|
- return DecodeResourceQuotaMetricResult(result)
|
|
|
+ return &DCGMDeviceContainerUsageResult{
|
|
|
+ UUID: uuid,
|
|
|
+ PodUID: podUID,
|
|
|
+ Container: container,
|
|
|
+ Value: value,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func DecodeAll[T any](results []*QueryResult, decode ResultDecoder[T]) []*T {
|