Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo committed Oct 27, 2023
1 parent 00c36d0 commit 3876fd2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *Runner) Start(ctx context.Context) (err error) {
}

func (r *Runner) subscribeAndTranslate(ctx context.Context) {
message.HandleSubscription(message.Metadata{Runner: string(v1alpha1.LogComponentGatewayAPIRunner), Resource: "gatewayapi-resources"}, r.ProviderResources.GatewayAPIResources.Subscribe(ctx),
message.HandleSubscription(message.Metadata{Runner: string(v1alpha1.LogComponentGatewayAPIRunner), Resource: "provider-resources"}, r.ProviderResources.GatewayAPIResources.Subscribe(ctx),
func(update message.Update[string, *gatewayapi.Resources], errChan chan error) {
r.Logger.Info("received an update")

Expand Down
8 changes: 4 additions & 4 deletions internal/message/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ package message
import "github.com/envoyproxy/gateway/internal/metrics"

var (
messageDepth = metrics.NewGauge("message_depth", "Current depth of message queue.")
watchableDepth = metrics.NewGauge("watchable_depth", "Current depth of watchable queue.")

messageSubscribedDurationSeconds = metrics.NewHistogram("message_subscribed_duration_seconds", "How long in seconds a subscribed message is handled.", []float64{0.001, 0.01, 0.1, 1, 5, 10})
watchableSubscribedDurationSeconds = metrics.NewHistogram("watchable_subscribed_duration_seconds", "How long in seconds a subscribed watchable is handled.", []float64{0.001, 0.01, 0.1, 1, 5, 10})

messageSubscribedTotal = metrics.NewCounter("message_subscribed_total", "Total number of subscribed message.")
watchableSubscribedTotal = metrics.NewCounter("watchable_subscribed_total", "Total number of subscribed watchable.")

messageSubscribedErrorsTotal = metrics.NewCounter("message_subscribed_errors_total", "Total number of subscribed message errors.")
watchableSubscribedErrorsTotal = metrics.NewCounter("watchable_subscribed_errors_total", "Total number of subscribed watchable errors.")

runnerLabel = metrics.NewLabel("runner")

Expand Down
14 changes: 7 additions & 7 deletions internal/message/watchutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Metadata struct {
}

func (m Metadata) LabelValues() []metrics.LabelValue {
labels := []metrics.LabelValue{}
labels := make([]metrics.LabelValue, 0, 2)
if m.Runner != "" {
labels = append(labels, runnerLabel.Value(m.Runner))
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func HandleSubscription[K comparable, V any](
go func() {
for err := range errChans {
logger.WithValues("runner", meta.Runner).Error(err, "observed an error")
messageSubscribedErrorsTotal.With(meta.LabelValues()...).Increment()
watchableSubscribedErrorsTotal.With(meta.LabelValues()...).Increment()
}
}()

Expand All @@ -64,17 +64,17 @@ func HandleSubscription[K comparable, V any](
Key: k,
Value: v,
}, errChans)
messageSubscribedTotal.With(meta.LabelValues()...).Increment()
messageSubscribedDurationSeconds.With(meta.LabelValues()...).Record(time.Since(startHandleTime).Seconds())
watchableSubscribedTotal.With(meta.LabelValues()...).Increment()
watchableSubscribedDurationSeconds.With(meta.LabelValues()...).Record(time.Since(startHandleTime).Seconds())
}
}
for snapshot := range subscription {
messageDepth.With(meta.LabelValues()...).Record(float64(len(subscription)))
watchableDepth.With(meta.LabelValues()...).Record(float64(len(subscription)))
for _, update := range snapshot.Updates {
startHandleTime := time.Now()
handle(Update[K, V](update), errChans)
messageSubscribedTotal.With(meta.LabelValues()...).Increment()
messageSubscribedDurationSeconds.With(meta.LabelValues()...).Record(time.Since(startHandleTime).Seconds())
watchableSubscribedTotal.With(meta.LabelValues()...).Increment()
watchableSubscribedDurationSeconds.With(meta.LabelValues()...).Record(time.Since(startHandleTime).Seconds())
}
}
}

0 comments on commit 3876fd2

Please sign in to comment.