소스 검색

Minor updates for dependencies, added go mod to collector-source

Matt Bolt 1 년 전
부모
커밋
cbe1517152

+ 0 - 0
pkg/errors/panic.go → core/pkg/errors/panic.go


+ 5 - 0
modules/collector-source/go.mod

@@ -0,0 +1,5 @@
+module github.com/opencost/opencost/modules/collector-source
+
+replace github.com/opencost/opencost/core => ./../../core
+
+go 1.23.0

+ 0 - 1
modules/prometheus-source/go.mod

@@ -9,7 +9,6 @@ replace (
 
 require (
 	github.com/julienschmidt/httprouter v1.3.0
-	github.com/opencost/opencost v1.113.0
 	github.com/opencost/opencost/core v0.0.0-20241211165149-ee44b80e2fd0
 	github.com/prometheus/client_golang v1.20.5
 	gopkg.in/yaml.v2 v2.4.0

+ 0 - 2
modules/prometheus-source/go.sum

@@ -241,8 +241,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
 github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
 github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
-github.com/opencost/opencost v1.113.0 h1:QciC1V1e/BmTvsei/MxvAnhiUNEuxCGkehx7+U2G0qQ=
-github.com/opencost/opencost v1.113.0/go.mod h1:o1F9J5JXdtGymtQzLnhiCA2AQCt5/Q5cL7NB6ApHgd8=
 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
 github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
 github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=

+ 1 - 1
modules/prometheus-source/pkg/prom/query.go

@@ -13,7 +13,7 @@ import (
 	"github.com/opencost/opencost/core/pkg/util/httputil"
 	"github.com/opencost/opencost/core/pkg/util/json"
 
-	"github.com/opencost/opencost/pkg/errors"
+	"github.com/opencost/opencost/core/pkg/errors"
 	prometheus "github.com/prometheus/client_golang/api"
 	v1 "github.com/prometheus/client_golang/api/prometheus/v1"
 )

+ 1 - 1
pkg/cloud/aws/provider.go

@@ -21,6 +21,7 @@ import (
 	"github.com/opencost/opencost/pkg/cloud/utils"
 
 	"github.com/opencost/opencost/core/pkg/env"
+	errs "github.com/opencost/opencost/core/pkg/errors"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/opencost"
 	"github.com/opencost/opencost/core/pkg/util"
@@ -29,7 +30,6 @@ import (
 	"github.com/opencost/opencost/core/pkg/util/timeutil"
 	"github.com/opencost/opencost/pkg/clustercache"
 	ocenv "github.com/opencost/opencost/pkg/env"
-	errs "github.com/opencost/opencost/pkg/errors"
 
 	awsSDK "github.com/aws/aws-sdk-go-v2/aws"
 	"github.com/aws/aws-sdk-go-v2/config"

+ 1 - 1
pkg/cloudcost/ingestor.go

@@ -6,13 +6,13 @@ import (
 	"sync/atomic"
 	"time"
 
+	"github.com/opencost/opencost/core/pkg/errors"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/opencost"
 	"github.com/opencost/opencost/core/pkg/util/stringutil"
 	"github.com/opencost/opencost/core/pkg/util/timeutil"
 	"github.com/opencost/opencost/pkg/cloud"
 	"github.com/opencost/opencost/pkg/env"
-	"github.com/opencost/opencost/pkg/errors"
 )
 
 // IngestorStatus includes diagnostic values for a given Ingestor

+ 1 - 1
pkg/cmd/costmodel/costmodel.go

@@ -15,11 +15,11 @@ import (
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"github.com/rs/cors"
 
+	"github.com/opencost/opencost/core/pkg/errors"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/version"
 	"github.com/opencost/opencost/pkg/costmodel"
 	"github.com/opencost/opencost/pkg/env"
-	"github.com/opencost/opencost/pkg/errors"
 	"github.com/opencost/opencost/pkg/filemanager"
 	"github.com/opencost/opencost/pkg/metrics"
 )

+ 0 - 35
pkg/costmodel/cluster.go

@@ -1,7 +1,6 @@
 package costmodel
 
 import (
-	"fmt"
 	"net"
 	"strconv"
 	"strings"
@@ -13,7 +12,6 @@ import (
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/opencost"
 	"github.com/opencost/opencost/core/pkg/source"
-	"github.com/opencost/opencost/core/pkg/util/timeutil"
 	"github.com/opencost/opencost/pkg/cloud/models"
 	"github.com/opencost/opencost/pkg/env"
 )
@@ -59,39 +57,6 @@ type ClusterCostsBreakdown struct {
 	User   float64 `json:"user"`
 }
 
-// NewClusterCostsFromCumulative takes cumulative cost data over a given time range, computes
-// the associated monthly rate data, and returns the Costs.
-func NewClusterCostsFromCumulative(cpu, gpu, ram, storage float64, window, offset time.Duration, dataHours float64) (*ClusterCosts, error) {
-	start, end := timeutil.ParseTimeRange(window, offset)
-
-	// If the number of hours is not given (i.e. is zero) compute one from the window and offset
-	if dataHours == 0 {
-		dataHours = end.Sub(start).Hours()
-	}
-
-	// Do not allow zero-length windows to prevent divide-by-zero issues
-	if dataHours == 0 {
-		return nil, fmt.Errorf("illegal time range: window %s, offset %s", window, offset)
-	}
-
-	cc := &ClusterCosts{
-		Start:             &start,
-		End:               &end,
-		CPUCumulative:     cpu,
-		GPUCumulative:     gpu,
-		RAMCumulative:     ram,
-		StorageCumulative: storage,
-		TotalCumulative:   cpu + gpu + ram + storage,
-		CPUMonthly:        cpu / dataHours * (timeutil.HoursPerMonth),
-		GPUMonthly:        gpu / dataHours * (timeutil.HoursPerMonth),
-		RAMMonthly:        ram / dataHours * (timeutil.HoursPerMonth),
-		StorageMonthly:    storage / dataHours * (timeutil.HoursPerMonth),
-	}
-	cc.TotalMonthly = cc.CPUMonthly + cc.GPUMonthly + cc.RAMMonthly + cc.StorageMonthly
-
-	return cc, nil
-}
-
 type Disk struct {
 	Cluster        string
 	Name           string

+ 7 - 1
pkg/costmodel/cluster_helpers.go

@@ -586,7 +586,13 @@ func lbValues(result *source.LBActiveMinutesResult) []*util.Vector {
 	return result.Data
 }
 
-func buildActiveDataMap[T comparable, U any](results []*U, keyGen func(*U) (T, bool), valuesFunc func(*U) []*util.Vector, resolution time.Duration, window opencost.Window) map[T]activeData {
+func buildActiveDataMap[T comparable, U any](
+	results []*U,
+	keyGen func(*U) (T, bool),
+	valuesFunc func(*U) []*util.Vector,
+	resolution time.Duration,
+	window opencost.Window,
+) map[T]activeData {
 	m := make(map[T]activeData)
 
 	for _, result := range results {

+ 1 - 1
pkg/costmodel/metrics.go

@@ -8,6 +8,7 @@ import (
 	"time"
 
 	"github.com/opencost/opencost/core/pkg/clusters"
+	"github.com/opencost/opencost/core/pkg/errors"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/source"
 	"github.com/opencost/opencost/core/pkg/util"
@@ -16,7 +17,6 @@ import (
 	"github.com/opencost/opencost/pkg/cloud/models"
 	"github.com/opencost/opencost/pkg/clustercache"
 	"github.com/opencost/opencost/pkg/env"
-	"github.com/opencost/opencost/pkg/errors"
 	"github.com/opencost/opencost/pkg/metrics"
 
 	promclient "github.com/prometheus/client_golang/api"

+ 1 - 1
pkg/customcost/ingestor.go

@@ -11,6 +11,7 @@ import (
 	"google.golang.org/protobuf/types/known/durationpb"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
+	"github.com/opencost/opencost/core/pkg/errors"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/model/pb"
 	"github.com/opencost/opencost/core/pkg/opencost"
@@ -18,7 +19,6 @@ import (
 	"github.com/opencost/opencost/core/pkg/util/stringutil"
 	"github.com/opencost/opencost/core/pkg/util/timeutil"
 	"github.com/opencost/opencost/pkg/env"
-	"github.com/opencost/opencost/pkg/errors"
 )
 
 // IngestorStatus includes diagnostic values for a given Ingestor