Skip to content

Commit

Permalink
feat: refactor enricher for cross-platform compatibility and update d…
Browse files Browse the repository at this point in the history
…ependencies
  • Loading branch information
ritwikranjan committed Jan 24, 2025
1 parent fed6d36 commit 57093e8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/hubble_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// go:build !windows

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package cmd
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,6 @@ replace k8s.io/perf-tests/network/benchmarks/netperf => github.com/Azure/perf-te

replace go.universe.tf/metallb => github.com/cilium/metallb v0.1.1-0.20220829170633-5d7dfb1129f7

// replace github.com/cilium/cilium => github.com/ritwikranjan/cilium v0.0.0-20250114123205-3b4fd6e1c18d
replace github.com/cilium/cilium => github.com/ritwikranjan/cilium v0.0.0-20250124161933-2d6f94502143

replace github.com/cilium/cilium => github.com/anubhabMajumdar/cilium v0.0.0-20250114231451-025e95e1ee63
// replace github.com/cilium/cilium => github.com/anubhabMajumdar/cilium v0.0.0-20250114231451-025e95e1ee63
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/anubhabMajumdar/cilium v0.0.0-20250114231451-025e95e1ee63 h1:Cc3bhXmJPLdQLILnJGZ8fMP2j+qxFnWzADaPFpfd+w0=
github.com/anubhabMajumdar/cilium v0.0.0-20250114231451-025e95e1ee63/go.mod h1:EqOosPzJuv28Hz3Ulz6cCXfYKbll7vbIwMGZU5houOw=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
Expand Down Expand Up @@ -813,6 +811,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/ritwikranjan/cilium v0.0.0-20250124161933-2d6f94502143 h1:5nyk2h9pHZWwxstDsnPWpMpJ7b0sofajcBkaGima+YI=
github.com/ritwikranjan/cilium v0.0.0-20250124161933-2d6f94502143/go.mod h1:EqOosPzJuv28Hz3Ulz6cCXfYKbll7vbIwMGZU5houOw=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
Expand Down
4 changes: 2 additions & 2 deletions pkg/enricher/enricher.go → pkg/enricher/enricher_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Enricher struct {

inputRing *container.Ring

Reader *container.RingReader
Reader container.RingReaderInterface

outputRing *container.Ring
}
Expand Down Expand Up @@ -186,6 +186,6 @@ func (e *Enricher) Write(ev *v1.Event) {
e.inputRing.Write(ev)
}

func (e *Enricher) ExportReader() *container.RingReader {
func (e *Enricher) ExportReader() RingReaderInterface {
return container.NewRingReader(e.outputRing, e.outputRing.OldestWrite())
}
43 changes: 43 additions & 0 deletions pkg/enricher/enricher_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

package enricher

import (
"context"
"sync"

v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
"github.com/microsoft/retina/pkg/controllers/cache"
)

var (
e *Enricher
once sync.Once
initialized bool
)

type Enricher struct {
}

func New(ctx context.Context, cache cache.CacheInterface) *Enricher {
once.Do(func() {
e = &Enricher{}
initialized = true
})
return e
}

func Instance() *Enricher {
return e
}

func IsInitialized() bool {
return initialized
}

func (e *Enricher) Run() {}

func (e *Enricher) Write(_ *v1.Event) {}

func (e *Enricher) ExportReader() RingReaderInterface { return nil }

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions pkg/enricher/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
package enricher

import (
"context"

v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
"github.com/cilium/cilium/pkg/hubble/container"
)

//go:generate go run go.uber.org/mock/mockgen@v0.4.0 -destination=mock_enricherinterface.go -copyright_file=../lib/ignore_headers.txt -package=enricher github.com/microsoft/retina/pkg/enricher EnricherInterface

type EnricherInterface interface {
Run()
Write(ev *v1.Event)
ExportReader() *container.RingReader
ExportReader() RingReaderInterface
}

type RingReaderInterface interface {
Previous() (*v1.Event, error)
Next() (*v1.Event, error)
NextFollow(ctx context.Context) *v1.Event
Close() error
}
File renamed without changes.
File renamed without changes.

0 comments on commit 57093e8

Please sign in to comment.