-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add metrics and refactor SPKS #81
Conversation
c6c341e
to
7f99373
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Check the bugs in lab cluster, also don't forget to see if the prometheus metrics are exposed.
pkg/cmd/spks.go
Outdated
logger.Error(err, "can't export data to Odoo") | ||
return err | ||
} | ||
firstTime := make(chan bool, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just call runSPKSBilling()
here instead of creating an additional channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this is leftover from way another approach :D I have no idea why it survived, it was part of retry mechanism etc. switching to simple function call
@@ -199,11 +201,13 @@ func QueryPrometheus(ctx context.Context, v1api v1.API, query string, logger log | |||
case model.ValVector: | |||
vectorVal := result.(model.Vector) | |||
if len(vectorVal) != 1 { | |||
return 0, fmt.Errorf("expected 1 result, got %d", len(vectorVal)) | |||
logger.Error(err, "Result vector length is not 1, prometheus query failed and returned: ", "result", vectorVal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we increase the failure metric here?
} | ||
default: | ||
return 0, fmt.Errorf("result type is not Vector: %s", result.Type()) | ||
logger.Error(err, "result type is not Vector: ", "result", result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well?
pkg/cmd/spks.go
Outdated
logger.Error(err, "Error querying Prometheus") | ||
return 0, err | ||
return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't you returning (int, error)
for this function? That would make it much clearer.
Also, instead of increasing the metrics here, you could do it in runSPKSBilling()
. It would simplify the logic, as you'd only have to catch one error case and not all three as in this function.
pkg/cmd/spks.go
Outdated
logger.Error(err, "Error querying Prometheus") | ||
return err | ||
} | ||
now := time.Now().In(location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check with tobru if the timestamps are now really correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had to change a bit the code on Monday because the timestamp was showing 00:00Z instead of 22:00Z UTC. Now data is arriving properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's correct as it is now. We tested and verified it in Odoo directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just fix Simon's comments and the rest is fine. We tested on Monday and data arrives ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one small nitpick and Simon's fixes
pkg/cmd/spks.go
Outdated
logger.Error(err, "Error querying Prometheus") | ||
return err | ||
} | ||
now := time.Now().In(location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's correct as it is now. We tested and verified it in Odoo directly.
pkg/cmd/spks.go
Outdated
{ | ||
ProductID: "appcat-spks-mariadb-standard", | ||
InstanceID: "mariadb-standard", | ||
SalesOrder: salesOrder, | ||
UnitID: UnitID, | ||
ConsumedUnits: float64(mariadbStandard), | ||
TimeRange: odoo.TimeRange{ | ||
From: startYesterdayAbsolute, | ||
To: endYesterdayAbsolute, | ||
}, | ||
}, | ||
{ | ||
ProductID: "appcat-spks-mariadb-premium", | ||
InstanceID: "mariadb-premium", | ||
SalesOrder: salesOrder, | ||
UnitID: UnitID, | ||
ConsumedUnits: float64(mariadbPremium), | ||
TimeRange: odoo.TimeRange{ | ||
From: startYesterdayAbsolute, | ||
To: endYesterdayAbsolute, | ||
}, | ||
}, | ||
{ | ||
ProductID: "appcat-spks-redis-standard", | ||
InstanceID: "redis-standard", | ||
SalesOrder: salesOrder, | ||
UnitID: UnitID, | ||
ConsumedUnits: float64(redisStandard), | ||
TimeRange: odoo.TimeRange{ | ||
From: startYesterdayAbsolute, | ||
To: endYesterdayAbsolute, | ||
}, | ||
}, | ||
{ | ||
ProductID: "appcat-spks-redis-premium", | ||
InstanceID: "redis-premium", | ||
SalesOrder: salesOrder, | ||
UnitID: UnitID, | ||
ConsumedUnits: float64(redisPremium), | ||
TimeRange: odoo.TimeRange{ | ||
From: startYesterdayAbsolute, | ||
To: endYesterdayAbsolute, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick: Lot's of copy&paste. This can probably be compacted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted timerange to separate variable, but generation of those provides even more code :D
|
Checklist
changelog.
The PR has a meaningful description that sums up the change. It will be
linked in the changelog.
bug
,enhancement
,documentation
,change
,breaking
,dependency
as they show up in the changelog.