Skip to content

Commit

Permalink
add audit log samples (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcantrill authored Oct 25, 2024
1 parent 97c6e42 commit 7b2cc36
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/generator/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const (

// JSONFormat formats a log to appear in JSON style
JSONFormat Format = "json"

// RawFormat formats a log to appear as the sample with no changes. This is most
// applicable for audit like samples
RawFormat Format = "raw"
)

func FormatLog(style Format, hash string, messageCount int64, payload string) (string, error) {
Expand All @@ -42,6 +46,8 @@ func FormatLog(style Format, hash string, messageCount int64, payload string) (s
return "", err
}
return fmt.Sprintln(string(messageJSON)), nil
case RawFormat:
return fmt.Sprintln(payload), nil
default:
return fmt.Sprintf("goloader seq - %s - %010d - %s\n", hash, messageCount, payload), nil
}
Expand Down
12 changes: 12 additions & 0 deletions internal/generator/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generator

import (
_ "embed"
"encoding/json"
"fmt"
"math/rand"
Expand All @@ -16,6 +17,9 @@ const (
// application runtime environment.
ApplicationLogType LogType = "application"

// AuditLogType represents a log from a kubernetes API server audit log
AuditLogType LogType = "audit"

// SyntheticLogType represents a log that is composed of random
// alphabetical characters of a certain size.
SyntheticLogType LogType = "synthetic"
Expand Down Expand Up @@ -93,6 +97,11 @@ var (
"[DEBUG] plugin/errors: 2 kubernetes.default.svc. A: read udp 1.1.1.1:54608->1.1.1.1:53: i/o timeout",
"D0426 20:39:28.065697 1 scheduler.go:599] error selecting node for pod: running \"VolumeBinding\" filter plugin for pod \"eric-data-document-database-pg-1\": pod has unbound immediate PersistentVolumeClaims",
}

//go:embed samples_audit.txt
auditSamplesRaw string

auditSamples = strings.Split(strings.TrimSpace(auditSamplesRaw), "\n")
)

// RandomLog returns a log of a given type from the requested sample set.
Expand All @@ -101,6 +110,9 @@ func RandomLog(logType LogType, logSize int) (string, error) {
case ApplicationLogType:
index := rand.Intn(len(applicationSamples))
return applicationSamples[index], nil
case AuditLogType:
index := rand.Intn(len(auditSamples))
return auditSamples[index], nil
case SyntheticLogType:
if logSize < 0 {
return "", fmt.Errorf("invalid size for sythentic log")
Expand Down
102 changes: 102 additions & 0 deletions internal/generator/samples_audit.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func init() {
pflag.StringVar(&opts.ClientURL, "url", "", "URL of Promtail, LogCLI, or Elasticsearch client.")
pflag.BoolVar(&opts.DisableSecurityCheck, "disable-security-check", false, "Disable security check in HTTPS client.")
pflag.IntVar(&opts.LogsPerSecond, "logs-per-second", 1, "The rate to generate logs. This rate may not always be achievable.")
pflag.StringVar(&opts.LogType, "log-type", "simple", "Overwrite to control the type of logs generated. Allowed values: simple, application, synthetic.")
pflag.StringVar(&opts.LogFormat, "log-format", "default", "Overwrite to control the format of logs generated. Allowed values: default, crio (mimic CRIO output), csv, json")
pflag.StringVar(&opts.LogType, "log-type", "simple", "Overwrite to control the type of logs generated. Allowed values: application, audit, simple, synthetic.")
pflag.StringVar(&opts.LogFormat, "log-format", "default", "Overwrite to control the format of logs generated. Allowed values: default, crio (mimic CRIO output), csv, json, raw")
pflag.StringVar(&opts.LabelType, "label-type", "none", "Overwrite to control what labels are included in Loki logs. Allowed values: none, client, client-host")
pflag.BoolVar(&opts.UseRandomHostname, "use-random-hostname", false, "Ensures that the hostname field is unique by adding a random integer to the end.")
pflag.IntVar(&opts.SyntheticPayloadSize, "synthetic-payload-size", 100, "Overwrite to control size of synthetic log line.")
Expand Down

0 comments on commit 7b2cc36

Please sign in to comment.