mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add audit logs for dormancy events (#15298)
This commit is contained in:
33
coderd/audit/fields.go
Normal file
33
coderd/audit/fields.go
Normal file
@ -0,0 +1,33 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"cdr.dev/slog"
|
||||
)
|
||||
|
||||
type BackgroundSubsystem string
|
||||
|
||||
const (
|
||||
BackgroundSubsystemDormancy BackgroundSubsystem = "dormancy"
|
||||
)
|
||||
|
||||
func BackgroundTaskFields(subsystem BackgroundSubsystem) map[string]string {
|
||||
return map[string]string{
|
||||
"automatic_actor": "coder",
|
||||
"automatic_subsystem": string(subsystem),
|
||||
}
|
||||
}
|
||||
|
||||
func BackgroundTaskFieldsBytes(ctx context.Context, logger slog.Logger, subsystem BackgroundSubsystem) []byte {
|
||||
af := BackgroundTaskFields(subsystem)
|
||||
|
||||
wriBytes, err := json.Marshal(af)
|
||||
if err != nil {
|
||||
logger.Error(ctx, "marshal additional fields for dormancy audit", slog.Error(err))
|
||||
return []byte("{}")
|
||||
}
|
||||
|
||||
return wriBytes
|
||||
}
|
Reference in New Issue
Block a user