Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bigler <[email protected]>
  • Loading branch information
TheBigLee committed Dec 19, 2023
1 parent 381f96f commit 44b9cd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
5 changes: 3 additions & 2 deletions pkg/cmd/cloudscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func CloudscaleCmds() *cli.Command {

if len(metrics) == 0 {
logger.Info("No data to export to odoo", "date", billingDate)
time.Sleep(time.Hour)
continue
}

Expand All @@ -143,9 +144,9 @@ func CloudscaleCmds() *cli.Command {
if err != nil {
logger.Error(err, "could not export cloudscale bucket metrics")
}
time.Sleep(time.Hour * time.Duration(collectInterval))
}

time.Sleep(time.Hour * time.Duration(collectInterval))
time.Sleep(time.Hour)
}
}()
wg.Wait()
Expand Down
27 changes: 15 additions & 12 deletions pkg/cmd/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ func ExoscaleCmds() *cli.Command {
salesOrder string
clusterId string
uom string
collectInterval int
billingHour int
// For dbaas in minutes
// For objectstorage in hours
// TODO: Fix this mess
collectInterval int
billingHour int
)
return &cli.Command{
Name: "exoscale",
Expand Down Expand Up @@ -128,21 +131,21 @@ func ExoscaleCmds() *cli.Command {
metrics, err := o.GetMetrics(c.Context)
if err != nil {
logger.Error(err, "cannot execute objectstorage collector")
os.Exit(1)
wg.Done()
}
if len(metrics) == 0 {
logger.Info("No data to export to odoo")
time.Sleep(time.Hour)
continue
}
logger.Info("Exporting data to Odoo", "time", time.Now())
err = odooClient.SendData(metrics)
if err != nil {
logger.Error(err, "cannot export metrics")
}

time.Sleep(time.Hour * time.Duration(collectInterval))
}

time.Sleep(time.Hour * time.Duration(collectInterval))
time.Sleep(time.Hour)
}
}()

Expand Down Expand Up @@ -188,9 +191,9 @@ func ExoscaleCmds() *cli.Command {

odooClient := odoo.NewOdooAPIClient(c.Context, odooURL, odooOauthTokenURL, odooClientId, odooClientSecret, logger)

if collectInterval < 1 || collectInterval > 24 {
// Set to run once a day after billingHour in case the collectInterval is out of boundaries
collectInterval = 1
// For Dbaas the interval is in minutes
if collectInterval < 1 || collectInterval > 60 {
collectInterval = 15
}

d, err := exoscale.NewDBaaS(exoscaleClient, k8sClient, k8sControlClient, collectInterval, salesOrder, clusterId, mapping)
Expand All @@ -205,11 +208,12 @@ func ExoscaleCmds() *cli.Command {
metrics, err := d.GetMetrics(c.Context)
if err != nil {
logger.Error(err, "cannot execute dbaas collector")
os.Exit(1)
wg.Done()
}

if len(metrics) == 0 {
logger.Info("No data to export to odoo", "time", time.Now())
time.Sleep(time.Minute * time.Duration(collectInterval))
continue
}

Expand All @@ -218,8 +222,7 @@ func ExoscaleCmds() *cli.Command {
if err != nil {
logger.Error(err, "cannot export metrics")
}

time.Sleep(time.Hour * time.Duration(collectInterval))
time.Sleep(time.Minute * time.Duration(collectInterval))
}
}()

Expand Down

0 comments on commit 44b9cd6

Please sign in to comment.