Skip to content

Commit

Permalink
Delete useless code (#4340)
Browse files Browse the repository at this point in the history
* delete monitor-metering useless code

* delete monitor-metering ci workflow
  • Loading branch information
bxy4543 committed Nov 23, 2023
1 parent 520c69d commit 4efa9d8
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 493 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/controllers.yml
Expand Up @@ -97,7 +97,6 @@ jobs:
- { name: license, path: license }
- { name: job-init, path: job/init }
- { name: resources, path: resources }
- { name: resources-metering, path: resources/metering }
- { name: node, path: node }
- { name: admission, path: admission }
steps:
Expand Down Expand Up @@ -199,7 +198,6 @@ jobs:
- { name: license, path: license }
- { name: job-init, path: job/init }
- { name: resources, path: resources }
- { name: resources-metering, path: resources/metering }
- { name: node, path: node }
- { name: admission, path: admission }
steps:
Expand Down
5 changes: 0 additions & 5 deletions controllers/pkg/database/interface.go
Expand Up @@ -24,9 +24,7 @@ import (

type Interface interface {
//InitDB() error
GetMeteringOwnerTimeResult(queryTime time.Time, queryCategories, queryProperties []string) (*MeteringOwnerTimeResult, error)
GetBillingLastUpdateTime(owner string, _type accountv1.Type) (bool, time.Time, error)
//TODO will delete this
GetBillingHistoryNamespaceList(ns *accountv1.NamespaceBillingHistorySpec, owner string) ([]string, error)
GetBillingHistoryNamespaces(startTime, endTime *time.Time, billType int, owner string) ([]string, error)
SaveBillings(billing ...*resources.Billing) error
Expand All @@ -38,8 +36,6 @@ type Interface interface {
InitDefaultPropertyTypeLS() error
SavePropertyTypes(types []resources.PropertyType) error
GetBillingCount(accountType accountv1.Type, startTime, endTime time.Time) (count, amount int64, err error)
//TODO delete
GenerateMeteringData(startTime, endTime time.Time, prices map[string]resources.Price) error
GenerateBillingData(startTime, endTime time.Time, prols *resources.PropertyTypeLS, namespaces []string, owner string) (orderID []string, amount int64, err error)
InsertMonitor(ctx context.Context, monitors ...*resources.Monitor) error
DropMonitorCollectionsOlderThan(days int) error
Expand All @@ -51,7 +47,6 @@ type Creator interface {
CreateBillingIfNotExist() error
//suffix by day, eg: monitor_20200101
CreateMonitorTimeSeriesIfNotExist(collTime time.Time) error
CreateMeteringTimeSeriesIfNotExist() error
}

type MeteringOwnerTimeResult struct {
Expand Down
63 changes: 0 additions & 63 deletions controllers/pkg/database/mongodb.go
Expand Up @@ -235,64 +235,6 @@ func (m *MongoDB) SaveBillings(billing ...*resources.Billing) error {
return err
}

func (m *MongoDB) GetMeteringOwnerTimeResult(queryTime time.Time, queryCategories, queryProperties []string) (*MeteringOwnerTimeResult, error) {
matchValue := bson.M{
"time": queryTime,
"category": bson.M{"$in": queryCategories},
}
if len(queryProperties) > 0 {
matchValue["property"] = bson.M{"$in": queryProperties}
}
pipeline := bson.A{
bson.D{{Key: "$match", Value: matchValue}},
bson.D{{Key: "$group", Value: bson.M{
"_id": bson.M{"property": "$property"},
"propertyTotal": bson.M{"$sum": "$amount"},
}}},
bson.D{{Key: "$project", Value: bson.M{
"_id": 0,
"property": "$_id.property",
"propertyTotal": 1,
}}},
bson.D{{Key: "$group", Value: bson.M{
"_id": nil,
"amountTotal": bson.M{"$sum": "$propertyTotal"},
"costs": bson.M{"$push": bson.M{"k": "$property", "v": "$propertyTotal"}},
}}},
bson.D{{Key: "$addFields", Value: bson.M{
//"owner": queryOwner,
"time": queryTime,
"amount": "$amountTotal",
"costs": bson.M{"$arrayToObject": "$costs"},
}}},
}

/*
db.metering.aggregate([
{ $match:
{ time: queryTime, category:
{ $in: ["ns-gxqoxr8s"] }, property: { $in: ["cpu", "memory", "storage"] } } },
{ $group: { _id: { property: "$property" }, propertyTotal: { $sum: "$amount" } } },
{ $project: { _id: 0, property: "$_id.property", propertyTotal: 1 } },
{ $group: { _id: null, amountTotal: { $sum: "$propertyTotal" }, costs: { $push: { k: "$property", v: "$propertyTotal" } } } },
{ $addFields: { orderId: "111111111", own: queryOwn, time: queryTime, type: 0, amount: "$amountTotal", costs: { $arrayToObject: "$costs" } } },
{ $out: "results1" }]);
*/
cursor, err := m.getMeteringCollection().Aggregate(context.Background(), pipeline)
if err != nil {
return nil, err
}
defer cursor.Close(context.Background())
if cursor.Next(context.Background()) {
var result MeteringOwnerTimeResult
if err = cursor.Decode(&result); err != nil {
return nil, err
}
return &result, nil
}
return nil, nil
}

// InsertMonitor insert monitor data to mongodb collection monitor + time (eg: monitor_20200101)
// The monitor data is saved daily 2020-12-01 00:00:00 - 2020-12-01 23:59:59 => monitor_20201201
func (m *MongoDB) InsertMonitor(ctx context.Context, monitors ...*resources.Monitor) error {
Expand Down Expand Up @@ -990,11 +932,6 @@ func (m *MongoDB) CreateMonitorTimeSeriesIfNotExist(collTime time.Time) error {
return m.CreateTimeSeriesIfNotExist(m.DBName, m.getMonitorCollectionName(collTime))
}

// CreateMeteringTimeSeriesIfNotExist creates the time series table for metering
func (m *MongoDB) CreateMeteringTimeSeriesIfNotExist() error {
return m.CreateTimeSeriesIfNotExist(m.DBName, m.MeteringConn)
}

func (m *MongoDB) CreateTimeSeriesIfNotExist(dbName, collectionName string) error {
// Check if the collection already exists
if exist, err := m.collectionExist(dbName, collectionName); exist || err != nil {
Expand Down
24 changes: 0 additions & 24 deletions controllers/pkg/database/mongodb_test.go
Expand Up @@ -33,30 +33,6 @@ import (
accountv1 "github.com/labring/sealos/controllers/account/api/v1"
)

func TestMongoDB_GetMeteringOwnerTimeResult(t *testing.T) {
dbCTX := context.Background()

//"mongodb://192.168.64.21:27017/"
m, err := NewMongoDB(dbCTX, os.Getenv("MONGODB_URI"))
if err != nil {
t.Errorf("failed to connect mongo: error = %v", err)
}
defer func() {
if err = m.Disconnect(dbCTX); err != nil {
t.Errorf("failed to disconnect mongo: error = %v", err)
}
}()

now := time.Now()
queryTime := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, time.Local).UTC().Add(-time.Hour)

got, err := m.GetMeteringOwnerTimeResult(queryTime, []string{"ns-0nfm8mkr"}, nil)
if err != nil {
t.Errorf("failed to get metering owner time result: error = %v", err)
}
t.Logf("all properties got: %v", got)
}

func TestMongoDB_QueryBillingRecords(t *testing.T) {
dbCTX := context.Background()

Expand Down
22 changes: 0 additions & 22 deletions controllers/resources/metering/Dockerfile

This file was deleted.

50 changes: 0 additions & 50 deletions controllers/resources/metering/Makefile

This file was deleted.

12 changes: 0 additions & 12 deletions controllers/resources/metering/deploy/Kubefile

This file was deleted.

66 changes: 0 additions & 66 deletions controllers/resources/metering/deploy/manifests/deploy.yaml

This file was deleted.

This file was deleted.

0 comments on commit 4efa9d8

Please sign in to comment.