diff --git a/pkg/cmd/cloudscale.go b/pkg/cmd/cloudscale.go index fc7ec33..56c2eb7 100644 --- a/pkg/cmd/cloudscale.go +++ b/pkg/cmd/cloudscale.go @@ -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 } @@ -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() diff --git a/pkg/cmd/exoscale.go b/pkg/cmd/exoscale.go index a6d99e5..d03a25f 100644 --- a/pkg/cmd/exoscale.go +++ b/pkg/cmd/exoscale.go @@ -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", @@ -128,10 +131,11 @@ 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()) @@ -139,10 +143,9 @@ func ExoscaleCmds() *cli.Command { 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) } }() @@ -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) @@ -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 } @@ -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)) } }()