Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
maskarb committed Aug 7, 2023
1 parent 811fbb1 commit f990676
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
10 changes: 5 additions & 5 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func GenerateReports(cr *metricscfgv1beta1.MetricsConfig, dirCfg *dirconfig.Dire
// ################################################################################################################
log.Info("querying for node metrics")
nodeResults := mappedResults{}
if err := c.getQueryRangeResults(nodeQueries, &nodeResults, 5); err != nil {
if err := c.getQueryRangeResults(nodeQueries, &nodeResults, MaxRetries); err != nil {
return err
}

Expand Down Expand Up @@ -274,7 +274,7 @@ func generateCostManagementReports(log gologr.Logger, c *PrometheusCollector, di

log.Info("querying for pod metrics")
podResults := mappedResults{}
if err := c.getQueryRangeResults(podQueries, &podResults, 5); err != nil {
if err := c.getQueryRangeResults(podQueries, &podResults, MaxRetries); err != nil {
return err
}

Expand Down Expand Up @@ -314,7 +314,7 @@ func generateCostManagementReports(log gologr.Logger, c *PrometheusCollector, di

log.Info("querying for storage metrics")
volResults := mappedResults{}
if err := c.getQueryRangeResults(volQueries, &volResults, 5); err != nil {
if err := c.getQueryRangeResults(volQueries, &volResults, MaxRetries); err != nil {
return err
}

Expand Down Expand Up @@ -346,7 +346,7 @@ func generateCostManagementReports(log gologr.Logger, c *PrometheusCollector, di

log.Info("querying for namespaces")
namespaceResults := mappedResults{}
if err := c.getQueryRangeResults(namespaceQueries, &namespaceResults, 5); err != nil {
if err := c.getQueryRangeResults(namespaceQueries, &namespaceResults, MaxRetries); err != nil {
return err
}

Expand Down Expand Up @@ -381,7 +381,7 @@ func generateResourceOpimizationReports(log gologr.Logger, c *PrometheusCollecto
ts := c.TimeSeries.End
log.Info(fmt.Sprintf("querying for resource-optimization for ts: %+v", ts))
rosResults := mappedResults{}
if err := c.getQueryResults(ts, resourceOptimizationQueries, &rosResults, 5); err != nil {
if err := c.getQueryResults(ts, resourceOptimizationQueries, &rosResults, MaxRetries); err != nil {
return err
}

Expand Down
1 change: 1 addition & 0 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func TestGenerateReportsNoCost(t *testing.T) {
}

func TestGenerateReportsQueryErrors(t *testing.T) {
MaxRetries = 1
mapResults := make(mappedMockPromResult)
fakeCollector := &PrometheusCollector{
PromConn: mockPrometheusConnection{
Expand Down
7 changes: 5 additions & 2 deletions collector/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io/ioutil"
"math"
"path/filepath"
"reflect"
"time"
Expand All @@ -27,6 +28,8 @@ const (
statusConfiguration
)

var MaxRetries int = 5

var (
ps *metricscfgv1beta1.PrometheusSpec

Expand Down Expand Up @@ -236,7 +239,7 @@ func (c *PrometheusCollector) getQueryRangeResults(queries *querys, results *map

if len(queriesToRetry) > 0 {
retries--
waitTime := time.Duration(5-retries) * time.Second
waitTime := time.Duration(math.Pow(2, float64(MaxRetries-retries))) * time.Second
log.Info(fmt.Sprintf("retrying failed queries after %s seconds", waitTime))
time.Sleep(waitTime)
return c.getQueryRangeResults(&queriesToRetry, results, retries)
Expand Down Expand Up @@ -276,7 +279,7 @@ func (c *PrometheusCollector) getQueryResults(ts time.Time, queries *querys, res

if len(queriesToRetry) > 0 {
retries--
waitTime := time.Duration(5-retries) * time.Second
waitTime := time.Duration(math.Pow(2, float64(MaxRetries-retries))) * time.Second
log.Info(fmt.Sprintf("retrying failed queries after %s seconds", waitTime))
time.Sleep(waitTime)
return c.getQueryResults(ts, &queriesToRetry, results, retries)
Expand Down
5 changes: 4 additions & 1 deletion controllers/kokumetricsconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func shutdown() {
os.RemoveAll(testingDir)
}

var _ = Describe("MetricsConfigController - CRD Handling", func() {
var _ = Describe("MetricsConfigController - CRD Handling", Ordered, func() {

const timeout = time.Second * 60
const interval = time.Second * 1
Expand All @@ -288,6 +288,9 @@ var _ = Describe("MetricsConfigController - CRD Handling", func() {
emptyDep1 := emptyDirDeployment.DeepCopy()
emptyDep2 := emptyDirDeployment.DeepCopy()

// override MaxRetries to reduce testing time
collector.MaxRetries = 1

BeforeEach(func() {

GitCommit = "1234567"
Expand Down
16 changes: 7 additions & 9 deletions scripts/txt_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def replace(file_path, pattern, subst):
remove(file_path)
move(abs_path, file_path)

def fix_csv(version, previous_version, image_sha, namespace=""):
def fix_csv(version, previous_version, image_sha, namespace):

# get the operator description from docs
docs = open("docs/csv-description.md")
Expand Down Expand Up @@ -72,17 +72,15 @@ def fix_dockerfile(version):
replace(filename, k, v)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Script for updating the appropriate fields of the CSV",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-n", "--namespace", help="namespace used for testing")
parser = argparse.ArgumentParser(description="Script for updating the appropriate fields of the CSV")
parser.add_argument("-n", "--namespace", help="namespace used for testing", default="")
parser.add_argument("version", help="New version of the CSV")
parser.add_argument("previous_version", help="Version of CSV being replaced")
parser.add_argument("image_sha", help="The image sha of the compiled operator")
args = parser.parse_args()
config = vars(args)
print(config)
print(vars(args))

check_version(config["version"], config["previous_version"])
check_version(args.version, args.previous_version)

fix_csv(**config)
fix_dockerfile(config["version"])
fix_csv(args.version, args.previous_version, args.image_sha, args.namespace)
fix_dockerfile(args.version)

0 comments on commit f990676

Please sign in to comment.