Skip to content

Commit

Permalink
Merge branch 'main' into gateway-api-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaohuabing authored Sep 27, 2024
2 parents 845cfa6 + 14830c7 commit 689792e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
7 changes: 2 additions & 5 deletions internal/admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import (

"github.com/davecgh/go-spew/spew"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/logging"
)

var adminLogger = logging.DefaultLogger(egv1a1.LogLevelInfo).WithName("admin")

func Init(cfg *config.Server) error {
if cfg.EnvoyGateway.GetEnvoyGatewayAdmin().EnableDumpConfig {
spewConfig := spew.NewDefaultConfig()
Expand All @@ -34,6 +30,7 @@ func start(cfg *config.Server) error {
address := cfg.EnvoyGateway.GetEnvoyGatewayAdminAddress()
enablePprof := cfg.EnvoyGateway.GetEnvoyGatewayAdmin().EnablePprof

adminLogger := cfg.Logger.WithName("admin")
adminLogger.Info("starting admin server", "address", address, "enablePprof", enablePprof)

if enablePprof {
Expand All @@ -57,7 +54,7 @@ func start(cfg *config.Server) error {
// Listen And Serve Admin Server.
go func() {
if err := adminServer.ListenAndServe(); err != nil {
cfg.Logger.Error(err, "start admin server failed")
adminLogger.Error(err, "start admin server failed")
}
}()

Expand Down
3 changes: 3 additions & 0 deletions internal/admin/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/logging"
)

func TestInitAdminServer(t *testing.T) {
Expand All @@ -20,6 +21,8 @@ func TestInitAdminServer(t *testing.T) {
EnvoyGatewaySpec: egv1a1.EnvoyGatewaySpec{},
},
}

svrConfig.Logger = logging.NewLogger(egv1a1.DefaultEnvoyGatewayLogging())
err := Init(svrConfig)
require.NoError(t, err)
}
17 changes: 3 additions & 14 deletions internal/metrics/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,10 @@ import (
"go.opentelemetry.io/otel"
api "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
log "github.com/envoyproxy/gateway/internal/logging"
)

var (
meter = func() api.Meter {
return otel.GetMeterProvider().Meter("envoy-gateway")
}

metricsLogger = log.DefaultLogger(egv1a1.LogLevelInfo).WithName("metrics")
)

func init() {
otel.SetLogger(metricsLogger.Logger)
var meter = func() api.Meter {
return otel.GetMeterProvider().Meter("envoy-gateway")
}

// MetricType is the type of a metric.
Expand Down Expand Up @@ -56,7 +45,7 @@ type Metadata struct {
Bounds []float64
}

// metrics stores stores metrics
// metrics stores metrics
type store struct {
started bool
mu sync.Mutex
Expand Down
6 changes: 6 additions & 0 deletions internal/metrics/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ import (

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
log "github.com/envoyproxy/gateway/internal/logging"
)

const (
defaultEndpoint = "/metrics"
)

var metricsLogger log.Logger

// Init initializes and registers the global metrics server.
func Init(cfg *config.Server) error {
metricsLogger = cfg.Logger.WithName("metrics")
otel.SetLogger(metricsLogger.Logger)

options, err := newOptions(cfg)
if err != nil {
return err
Expand Down
13 changes: 1 addition & 12 deletions internal/provider/kubernetes/status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ func (m MutatorFunc) Mutate(old client.Object) client.Object {
type UpdateHandler struct {
log logr.Logger
client client.Client
sendUpdates chan struct{}
updateChannel chan Update
}

func NewUpdateHandler(log logr.Logger, client client.Client) *UpdateHandler {
return &UpdateHandler{
log: log,
client: client,
sendUpdates: make(chan struct{}),
updateChannel: make(chan Update, 100),
}
}
Expand Down Expand Up @@ -129,9 +127,6 @@ func (u *UpdateHandler) Start(ctx context.Context) error {
u.log.Info("started status update handler")
defer u.log.Info("stopped status update handler")

// Enable Updaters to start sending updates to this handler.
close(u.sendUpdates)

for {
select {
case <-ctx.Done():
Expand All @@ -148,7 +143,6 @@ func (u *UpdateHandler) Start(ctx context.Context) error {
// Writer retrieves the interface that should be used to write to the UpdateHandler.
func (u *UpdateHandler) Writer() Updater {
return &UpdateWriter{
enabled: u.sendUpdates,
updateChannel: u.updateChannel,
}
}
Expand All @@ -160,18 +154,13 @@ type Updater interface {

// UpdateWriter takes status updates and sends these to the UpdateHandler via a channel.
type UpdateWriter struct {
enabled <-chan struct{}
updateChannel chan<- Update
}

// Send sends the given Update off to the update channel for writing by the UpdateHandler.
func (u *UpdateWriter) Send(update Update) {
// Non-blocking receive to see if we should pass along update.
select {
case <-u.enabled:
u.updateChannel <- update
default:
}
u.updateChannel <- update
}

// isStatusEqual checks if two objects have equivalent status.
Expand Down

0 comments on commit 689792e

Please sign in to comment.