Skip to content

Commit

Permalink
refactor: rename control-plane metrics (#3727)
Browse files Browse the repository at this point in the history
* refactor metrics naming for watchable map

Signed-off-by: shawnh2 <[email protected]>

* refactor metrics naming for status updater

Signed-off-by: shawnh2 <[email protected]>

* refactor metrics naming for xds server

Signed-off-by: shawnh2 <[email protected]>

* refactor metrics naming for infra manager

Signed-off-by: shawnh2 <[email protected]>

* formatter metrics

Signed-off-by: shawnh2 <[email protected]>

* refactor metrics naming for wasm

Signed-off-by: shawnh2 <[email protected]>

* fix lint

Signed-off-by: shawnh2 <[email protected]>

---------

Signed-off-by: shawnh2 <[email protected]>
  • Loading branch information
shawnh2 authored Jul 3, 2024
1 parent 5050e36 commit 015e7ff
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 176 deletions.
104 changes: 35 additions & 69 deletions internal/infrastructure/kubernetes/infra_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@ func (i *Infra) createOrUpdateServiceAccount(ctx context.Context, r ResourceRend
}
)

resourceApplyTotal.With(labels...).Increment()

if sa, err = r.ServiceAccount(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -64,11 +61,8 @@ func (i *Infra) createOrUpdateConfigMap(ctx context.Context, r ResourceRender) (
}
)

resourceApplyTotal.With(labels...).Increment()

if cm, err = r.ConfigMap(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.StatusFailure, labels...).Increment()
return err
}

Expand All @@ -79,9 +73,9 @@ func (i *Infra) createOrUpdateConfigMap(ctx context.Context, r ResourceRender) (
defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -101,11 +95,8 @@ func (i *Infra) createOrUpdateDeployment(ctx context.Context, r ResourceRender)
}
)

resourceApplyTotal.With(labels...).Increment()

if deployment, err = r.Deployment(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

Expand All @@ -119,9 +110,9 @@ func (i *Infra) createOrUpdateDeployment(ctx context.Context, r ResourceRender)
defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -141,11 +132,8 @@ func (i *Infra) createOrUpdateDaemonSet(ctx context.Context, r ResourceRender) (
}
)

resourceApplyTotal.With(labels...).Increment()

if daemonSet, err = r.DaemonSet(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

Expand All @@ -159,9 +147,9 @@ func (i *Infra) createOrUpdateDaemonSet(ctx context.Context, r ResourceRender) (
defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -179,10 +167,8 @@ func (i *Infra) createOrUpdatePodDisruptionBudget(ctx context.Context, r Resourc
}
)

resourceApplyTotal.With(labels...).Increment()

if pdb, err = r.PodDisruptionBudget(); err != nil {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

Expand All @@ -195,9 +181,9 @@ func (i *Infra) createOrUpdatePodDisruptionBudget(ctx context.Context, r Resourc
defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -218,11 +204,8 @@ func (i *Infra) createOrUpdateHPA(ctx context.Context, r ResourceRender) (err er
}
)

resourceApplyTotal.With(labels...).Increment()

if hpa, err = r.HorizontalPodAutoscaler(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

Expand All @@ -235,9 +218,9 @@ func (i *Infra) createOrUpdateHPA(ctx context.Context, r ResourceRender) (err er
defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -257,20 +240,17 @@ func (i *Infra) createOrUpdateService(ctx context.Context, r ResourceRender) (er
}
)

resourceApplyTotal.With(labels...).Increment()

if svc, err = r.Service(); err != nil {
resourceApplyFailed.With(labels...).Increment()

resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
return err
}

defer func() {
if err == nil {
resourceApplyDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceApplySuccess.With(labels...).Increment()
resourceApplyTotal.WithSuccess(labels...).Increment()
} else {
resourceApplyFailed.With(labels...).Increment()
resourceApplyTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -295,14 +275,12 @@ func (i *Infra) deleteServiceAccount(ctx context.Context, r ResourceRender) (err
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -327,14 +305,12 @@ func (i *Infra) deleteDeployment(ctx context.Context, r ResourceRender) (err err
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -359,14 +335,12 @@ func (i *Infra) deleteDaemonSet(ctx context.Context, r ResourceRender) (err erro
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -391,14 +365,12 @@ func (i *Infra) deleteConfigMap(ctx context.Context, r ResourceRender) (err erro
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -423,14 +395,12 @@ func (i *Infra) deleteService(ctx context.Context, r ResourceRender) (err error)
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -455,14 +425,12 @@ func (i *Infra) deleteHPA(ctx context.Context, r ResourceRender) (err error) {
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand All @@ -487,14 +455,12 @@ func (i *Infra) deletePDB(ctx context.Context, r ResourceRender) (err error) {
}
)

resourceDeleteTotal.With(labels...).Increment()

defer func() {
if err == nil {
resourceDeleteDurationSeconds.With(labels...).Record(time.Since(startTime).Seconds())
resourceDeleteSuccess.With(labels...).Increment()
resourceDeleteTotal.WithSuccess(labels...).Increment()
} else {
resourceDeleteFailed.With(labels...).Increment()
resourceDeleteTotal.WithFailure(metrics.ReasonError, labels...).Increment()
}
}()

Expand Down
28 changes: 20 additions & 8 deletions internal/infrastructure/kubernetes/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ package kubernetes
import "github.com/envoyproxy/gateway/internal/metrics"

var (
resourceApplyTotal = metrics.NewCounter("resource_apply_total", "Total number of applied resources.")
resourceApplyFailed = metrics.NewCounter("resource_apply_failed", "Number of applied resources that failed.")
resourceApplySuccess = metrics.NewCounter("resource_apply_success", "Number of applied resources that succeed.")
resourceApplyDurationSeconds = metrics.NewHistogram("resource_apply_duration_seconds", "How long in seconds a resource be applied successfully.", []float64{0.001, 0.01, 0.1, 1, 5, 10})
resourceApplyTotal = metrics.NewCounter(
"resource_apply_total",
"Total number of applied resources.",
)

resourceDeleteTotal = metrics.NewCounter("resource_delete_total", "Total number of deleted resources.")
resourceDeleteFailed = metrics.NewCounter("resource_delete_failed", "Number of deleted resources that failed.")
resourceDeleteSuccess = metrics.NewCounter("resource_delete_success", "Number of deleted resources that succeed.")
resourceDeleteDurationSeconds = metrics.NewHistogram("resource_delete_duration_seconds", "How long in seconds a resource be deleted successfully.", []float64{0.001, 0.01, 0.1, 1, 5, 10})
resourceApplyDurationSeconds = metrics.NewHistogram(
"resource_apply_duration_seconds",
"How long in seconds a resource be applied successfully.",
[]float64{0.001, 0.01, 0.1, 1, 5, 10},
)

resourceDeleteTotal = metrics.NewCounter(
"resource_delete_total",
"Total number of deleted resources.",
)

resourceDeleteDurationSeconds = metrics.NewHistogram(
"resource_delete_duration_seconds",
"How long in seconds a resource be deleted successfully.",
[]float64{0.001, 0.01, 0.1, 1, 5, 10},
)

kindLabel = metrics.NewLabel("kind")
nameLabel = metrics.NewLabel("name")
Expand Down
27 changes: 17 additions & 10 deletions internal/message/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ package message
import "github.com/envoyproxy/gateway/internal/metrics"

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

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})

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

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

runnerLabel = metrics.NewLabel("runner")

watchableDepth = metrics.NewGauge(
"watchable_depth",
"Current depth of watchable queue.",
)

watchableSubscribeDurationSeconds = metrics.NewHistogram(
"watchable_subscribe_duration_seconds",
"How long in seconds a subscribed watchable queue is handled.",
[]float64{0.001, 0.01, 0.1, 1, 5, 10},
)

watchableSubscribeTotal = metrics.NewCounter(
"watchable_subscribe_total",
"Total number of subscribed watchable queue.",
)

runnerLabel = metrics.NewLabel("runner")
messageLabel = metrics.NewLabel("message")
)
10 changes: 5 additions & 5 deletions internal/message/watchutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func HandleSubscription[K comparable, V any](
go func() {
for err := range errChans {
logger.WithValues("runner", meta.Runner).Error(err, "observed an error")
watchableSubscribedErrorsTotal.With(meta.LabelValues()...).Increment()
watchableSubscribeTotal.WithFailure(metrics.ReasonError, meta.LabelValues()...).Increment()
}
}()

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

0 comments on commit 015e7ff

Please sign in to comment.