Skip to content

Commit

Permalink
Add system event types from event-worker
Browse files Browse the repository at this point in the history
These types are for auditing and billing metrics

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Dec 15, 2023
1 parent e88354f commit bff9435
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions types/system_events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package types

import "time"

const (
TypeFunctionUsage = "function_usage"
TypeAPIAccess = "api_access"
)

type Event interface {
EventType() string
}

type FunctionUsageEvent struct {
Namespace string `json:"namespace"`
FunctionName string `json:"function_name"`
Started time.Time `json:"started"`
Duration time.Duration `json:"duration"`
MemoryBytes int64 `json:"memory_bytes"`
}

func (e FunctionUsageEvent) EventType() string {
return TypeFunctionUsage
}

type APIAccessEvent struct {
Actor *Actor `json:"actor,omitempty"`
Path string `json:"path"`
Method string `json:"method"`
Actions []string `json:"actions"`
ResponseCode int `json:"response_code"`
CustomMessage string `json:"custom_message,omitempty"`
Namespace string `json:"namespace,omitempty"`
Time time.Time `json:"time"`
}

func (e APIAccessEvent) EventType() string {
return TypeAPIAccess
}

// Actor is the user that triggered an event.
// Get from OIDC claims, we can add any of the default OIDC profile or email claim fields if desired.
type Actor struct {
// OIDC subject, a unique identifier of the user.
Sub string `json:"sub"`
// Full name of the subject, can be the name of a user of OpenFaaS component.
Name string `json:"name,omitempty"`
// OpenFaaS issuer
Issuer string `json:"issuer,omitempty"`
// Federated issuer
FedIssuer string `json:"fed_issuer,omitempty"`
}

0 comments on commit bff9435

Please sign in to comment.