2023-01-30 15:49:44 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ExecutionStats stores the statistics for the single policy/rule application
|
|
|
|
type ExecutionStats struct {
|
2023-04-05 19:07:04 +02:00
|
|
|
// processingTime is the time required to apply the policy/rule on the resource
|
2023-04-05 14:27:18 +02:00
|
|
|
processingTime time.Duration
|
|
|
|
// timestamp of the instant the policy/rule got triggered
|
|
|
|
timestamp time.Time
|
2023-01-30 15:49:44 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:07:04 +02:00
|
|
|
func NewExecutionStats(startTime, endTime time.Time) ExecutionStats {
|
2023-04-05 14:27:18 +02:00
|
|
|
return ExecutionStats{
|
|
|
|
timestamp: startTime,
|
|
|
|
processingTime: endTime.Sub(startTime),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ExecutionStats) Time() time.Time {
|
|
|
|
return s.timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ExecutionStats) Timestamp() int64 {
|
|
|
|
return s.timestamp.Unix()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s ExecutionStats) ProcessingTime() time.Duration {
|
|
|
|
return s.processingTime
|
|
|
|
}
|
|
|
|
|
2023-01-30 15:49:44 +01:00
|
|
|
// PolicyStats stores statistics for the single policy application
|
|
|
|
type PolicyStats struct {
|
2023-04-12 18:20:42 +02:00
|
|
|
// rulesAppliedCount is the count of rules that were applied successfully
|
|
|
|
rulesAppliedCount int
|
|
|
|
// rulesErrorCount is the count of rules that with execution errors
|
|
|
|
rulesErrorCount int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ps *PolicyStats) RulesAppliedCount() int {
|
|
|
|
return ps.rulesAppliedCount
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ps *PolicyStats) RulesErrorCount() int {
|
|
|
|
return ps.rulesErrorCount
|
2023-01-30 15:49:44 +01:00
|
|
|
}
|