|
@@ -6,6 +6,7 @@ import (
|
|
|
"reflect"
|
|
"reflect"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
|
|
+ "github.com/opencost/opencost/core/pkg/log"
|
|
|
"github.com/opencost/opencost/core/pkg/util/json"
|
|
"github.com/opencost/opencost/core/pkg/util/json"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -74,9 +75,9 @@ func (a *Any) InterfaceToAny(itf interface{}) error {
|
|
|
a.Labels = labels
|
|
a.Labels = labels
|
|
|
a.Start = start
|
|
a.Start = start
|
|
|
a.End = end
|
|
a.End = end
|
|
|
- a.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ a.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
@@ -154,9 +155,8 @@ func (ca *Cloud) InterfaceToCloud(itf interface{}) error {
|
|
|
ca.Labels = labels
|
|
ca.Labels = labels
|
|
|
ca.Start = start
|
|
ca.Start = start
|
|
|
ca.End = end
|
|
ca.End = end
|
|
|
- ca.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ ca.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
@@ -221,21 +221,10 @@ func (cm *ClusterManagement) InterfaceToClusterManagement(itf interface{}) error
|
|
|
labels[k] = v.(string)
|
|
labels[k] = v.(string)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // parse start and end strings to time.Time
|
|
|
|
|
- start, err := time.Parse(time.RFC3339, fmap["start"].(string))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
- end, err := time.Parse(time.RFC3339, fmap["end"].(string))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
cm.Properties = &properties
|
|
cm.Properties = &properties
|
|
|
cm.Labels = labels
|
|
cm.Labels = labels
|
|
|
- cm.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ cm.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if Cost, err := getTypedVal(fmap["totalCost"]); err == nil {
|
|
if Cost, err := getTypedVal(fmap["totalCost"]); err == nil {
|
|
@@ -331,9 +320,8 @@ func (d *Disk) InterfaceToDisk(itf interface{}) error {
|
|
|
d.Labels = labels
|
|
d.Labels = labels
|
|
|
d.Start = start
|
|
d.Start = start
|
|
|
d.End = end
|
|
d.End = end
|
|
|
- d.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ d.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
d.Breakdown = &breakdown
|
|
d.Breakdown = &breakdown
|
|
|
|
|
|
|
@@ -448,9 +436,8 @@ func (n *Network) InterfaceToNetwork(itf interface{}) error {
|
|
|
n.Labels = labels
|
|
n.Labels = labels
|
|
|
n.Start = start
|
|
n.Start = start
|
|
|
n.End = end
|
|
n.End = end
|
|
|
- n.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ n.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
@@ -559,9 +546,8 @@ func (n *Node) InterfaceToNode(itf interface{}) error {
|
|
|
n.Labels = labels
|
|
n.Labels = labels
|
|
|
n.Start = start
|
|
n.Start = start
|
|
|
n.End = end
|
|
n.End = end
|
|
|
- n.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ n.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
n.CPUBreakdown = &cpuBreakdown
|
|
n.CPUBreakdown = &cpuBreakdown
|
|
|
n.RAMBreakdown = &ramBreakdown
|
|
n.RAMBreakdown = &ramBreakdown
|
|
@@ -670,9 +656,8 @@ func (lb *LoadBalancer) InterfaceToLoadBalancer(itf interface{}) error {
|
|
|
lb.Labels = labels
|
|
lb.Labels = labels
|
|
|
lb.Start = start
|
|
lb.Start = start
|
|
|
lb.End = end
|
|
lb.End = end
|
|
|
- lb.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ lb.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
if adjustment, err := getTypedVal(fmap["adjustment"]); err == nil {
|
|
@@ -741,21 +726,10 @@ func (sa *SharedAsset) InterfaceToSharedAsset(itf interface{}) error {
|
|
|
labels[k] = v.(string)
|
|
labels[k] = v.(string)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // parse start and end strings to time.Time
|
|
|
|
|
- start, err := time.Parse(time.RFC3339, fmap["start"].(string))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
- end, err := time.Parse(time.RFC3339, fmap["end"].(string))
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
sa.Properties = &properties
|
|
sa.Properties = &properties
|
|
|
sa.Labels = labels
|
|
sa.Labels = labels
|
|
|
- sa.Window = Window{
|
|
|
|
|
- start: &start,
|
|
|
|
|
- end: &end,
|
|
|
|
|
|
|
+ if _, found := fmap["window"]; found {
|
|
|
|
|
+ sa.Window = toWindow(fmap["window"].(map[string]interface{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if Cost, err := getTypedVal(fmap["totalCost"]); err == nil {
|
|
if Cost, err := getTypedVal(fmap["totalCost"]); err == nil {
|
|
@@ -973,6 +947,35 @@ func toAssetProp(fproperties map[string]interface{}) AssetProperties {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func toWindow(fproperties map[string]interface{}) Window {
|
|
|
|
|
+
|
|
|
|
|
+ var start, end time.Time
|
|
|
|
|
+ var err error
|
|
|
|
|
+
|
|
|
|
|
+ if startStr, v := fproperties["start"].(string); v {
|
|
|
|
|
+ start, err = time.Parse(time.RFC3339, startStr)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Errorf("error parsing window start from string %s, setting as 0 time", startStr)
|
|
|
|
|
+ start = time.Time{}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if endStr, v := fproperties["end"].(string); v {
|
|
|
|
|
+ end, err = time.Parse(time.RFC3339, endStr)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Errorf("error parsing window end from string %s, setting as 0 time", endStr)
|
|
|
|
|
+ end = time.Time{}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return NewClosedWindow(start, end)
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Creates an Breakdown directly from map[string]interface{}
|
|
// Creates an Breakdown directly from map[string]interface{}
|
|
|
func toBreakdown(fproperties map[string]interface{}) Breakdown {
|
|
func toBreakdown(fproperties map[string]interface{}) Breakdown {
|
|
|
var breakdown Breakdown
|
|
var breakdown Breakdown
|