-
Notifications
You must be signed in to change notification settings - Fork 777
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
feat: stats in webhook, audit & gator #2686
Merged
maxsmythe
merged 15 commits into
open-policy-agent:master
from
acpana:acpana/gator-stats
May 9, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b5dbfa2
feat: evaluation_metrics 2
acpana 361585b
feat: stats in gator
acpana 45d80d8
review: aggregate stats
acpana 14c792f
review: simple gator test flag
acpana f2f1026
review feedback 2
acpana 8268335
review: srework test stats
acpana c1847d1
testing: use a fake zap core
acpana f7a44b3
add stats with descriptioon
acpana bce2851
rename log label
acpana dcf0e41
actually use the unmarshalled yaml
acpana c408a02
rework formatOutput
acpana a3a1934
Merge branch 'master' into acpana/gator-stats
sozercan 15860aa
Merge branch 'master' into acpana/gator-stats
sozercan f0ca43f
Apply suggestions from code review
acpana 74ff964
lint pkg/logging/logging.go
acpana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func ErrFatalf(format string, a ...interface{}) { | ||
fmt.Fprintf(os.Stderr, format+"\n", a...) | ||
os.Exit(1) | ||
} | ||
|
||
func WriteToFile(s string, path string) { | ||
file, err := os.Create(path) | ||
if err != nil { | ||
ErrFatalf("error creating file at path %s: %v", path, err) | ||
} | ||
|
||
if _, err = fmt.Fprint(file, s); err != nil { | ||
ErrFatalf("error writing to file at path %s: %s", path, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ var ( | |
auditMatchKindOnly = flag.Bool("audit-match-kind-only", false, "only use kinds specified in all constraints for auditing cluster resources. if kind is not specified in any of the constraints, it will audit all resources (same as setting this flag to false)") | ||
apiCacheDir = flag.String("api-cache-dir", defaultAPICacheDir, "The directory where audit from api server cache are stored, defaults to /tmp/audit") | ||
emptyAuditResults []updateListEntry | ||
logStatsAudit = flag.Bool("log-stats-audit", false, "(alpha) log stats metrics for the audit run") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a doc to describe usage? can be a follow-up |
||
) | ||
|
||
// Manager allows us to audit resources periodically. | ||
|
@@ -491,6 +492,15 @@ func (am *Manager) auditFromCache(ctx context.Context) ([]Result, []error) { | |
continue | ||
} | ||
|
||
if *logStatsAudit { | ||
logging.LogStatsEntries( | ||
am.opa, | ||
am.log, | ||
resp.StatsEntries, | ||
"audit from cache review request stats", | ||
) | ||
} | ||
|
||
for _, r := range resp.Results() { | ||
results = append(results, Result{ | ||
Result: r, | ||
|
@@ -597,6 +607,16 @@ func (am *Manager) reviewObjects(ctx context.Context, kind string, folderCount i | |
} | ||
expansion.OverrideEnforcementAction(resultant.EnforcementAction, resultantResp) | ||
expansion.AggregateResponses(resultant.TemplateName, resp, resultantResp) | ||
expansion.AggregateStats(resultant.TemplateName, resp, resultantResp) | ||
} | ||
|
||
if *logStatsAudit { | ||
logging.LogStatsEntries( | ||
am.opa, | ||
am.log, | ||
resp.StatsEntries, | ||
"audit review request stats", | ||
) | ||
} | ||
|
||
if len(resp.Results()) > 0 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we add a doc that describes usage? can be a follow up
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 for
stats
feature I was going to do a follow up docs PR.