Skip to content

Commit

Permalink
Merge pull request #126 from UgOrange/metrics
Browse files Browse the repository at this point in the history
feat: Add otel metrics
  • Loading branch information
Danny-Wei authored Nov 14, 2024
2 parents 3f3cce5 + 1bee784 commit af3eaf6
Show file tree
Hide file tree
Showing 17 changed files with 1,414 additions and 63 deletions.
17 changes: 14 additions & 3 deletions cmd/varmor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/bytedance/vArmor/internal/webhooks"
varmorclient "github.com/bytedance/vArmor/pkg/client/clientset/versioned"
varmorinformer "github.com/bytedance/vArmor/pkg/client/informers/externalversions"
"github.com/bytedance/vArmor/pkg/metrics"
"github.com/bytedance/vArmor/pkg/signal"
)

Expand All @@ -63,9 +64,11 @@ var (
managerIP string
webhookMatchLabel string
bpfExclusiveMode bool
statusUpdateCycle time.Duration
auditLogPaths string
setupLog = log.Log.WithName("SETUP")
enableMetrics bool
//syncMetricsSecond int
statusUpdateCycle time.Duration
auditLogPaths string
setupLog = log.Log.WithName("SETUP")
)

func main() {
Expand All @@ -88,6 +91,8 @@ func main() {
flag.BoolVar(&bpfExclusiveMode, "bpfExclusiveMode", false, "Set this flag to enable exclusive mode for the BPF enforcer. It will disable the AppArmor confinement when using the BPF enforcer.")
flag.DurationVar(&statusUpdateCycle, "statusUpdateCycle", time.Hour*2, "Configure the status update cycle for VarmorPolicy and ArmorProfile")
flag.StringVar(&auditLogPaths, "auditLogPaths", "/var/log/audit/audit.log|/var/log/kern.log", "Configure the file search list to select the audit log file and read the AppArmor and Seccomp audit events. Please use a vertical bar to separate the file paths, the first valid file will be used to track the audit events.")
flag.BoolVar(&enableMetrics, "enableMetrics", false, "Set this flag to enable metrics.")
//flag.IntVar(&syncMetricsSecond, "syncMetricsSecond", 10, "Configure the profile metric update seconds")
flag.Parse()

// Set the webhook matchLabels configuration.
Expand Down Expand Up @@ -144,6 +149,9 @@ func main() {
gin.SetMode(gin.ReleaseMode)
}

// init a metrics
metricsModule := metrics.NewMetricsModule(log.Log.WithName("METRICS"), enableMetrics, 10)

if agent {
setupLog.Info("vArmor agent startup")

Expand All @@ -161,6 +169,7 @@ func main() {
config.ClassifierServicePort,
auditLogPaths,
stopCh,
metricsModule,
log.Log.WithName("AGENT"),
)
if err != nil {
Expand Down Expand Up @@ -270,6 +279,7 @@ func main() {
managerIP,
config.WebhookServicePort,
bpfExclusiveMode,
metricsModule,
log.Log.WithName("WEBHOOK-SERVER"))
if err != nil {
setupLog.Error(err, "Failed to create webhook webhookServer")
Expand All @@ -288,6 +298,7 @@ func main() {
varmorClient.CrdV1beta1(),
kubeClient.AuthenticationV1(),
statusUpdateCycle,
metricsModule,
log.Log.WithName("STATUS-SERVICE"),
)
if err != nil {
Expand Down
22 changes: 15 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ require (
github.com/nxadm/tail v1.4.11
github.com/opencontainers/runtime-spec v1.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.3
github.com/rs/zerolog v1.33.0
github.com/seccomp/libseccomp-golang v0.10.0
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/prometheus v0.52.0
go.opentelemetry.io/otel/metric v1.30.0
go.opentelemetry.io/otel/sdk/metric v1.30.0
golang.org/x/sys v0.26.0
google.golang.org/grpc v1.64.1
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand All @@ -36,7 +41,9 @@ require (
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.10.0-rc.8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/continuity v0.4.2 // indirect
Expand Down Expand Up @@ -68,7 +75,7 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -87,28 +94,29 @@ require (
github.com/opencontainers/runc v1.1.5 // indirect
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading

0 comments on commit af3eaf6

Please sign in to comment.