Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new metrics #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lint/go: ## Execute golangci-lint.

.PHONY: lint/protobuf
lint/protobuf: ## Execute buf linter.
@go run github.com/bufbuild/buf/cmd/buf lint
@go run $(BUF) dep update && go run $(BUF) lint

.PHONY: run/tests
run/tests: run/unit-tests run/integration-tests ## Execute all unit and integration tests
Expand Down
28 changes: 28 additions & 0 deletions internal/core/worker/metricsreporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ var (
monitoring.LabelScheduler,
},
})
gameRoomActiveGaugeMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "gru_active",
Help: "The number of game rooms with status active, with running matches but not fully occupied",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})

instanceReadyGaugeMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Expand Down Expand Up @@ -144,6 +154,17 @@ var (
monitoring.LabelScheduler,
},
})

runningMatchesGaugeMetric = monitoring.CreateGaugeMetric(&monitoring.MetricOpts{
Namespace: monitoring.Namespace,
Subsystem: monitoring.SubsystemWorker,
Name: "running_matches",
Help: "The total number of running matches",
Labels: []string{
monitoring.LabelGame,
monitoring.LabelScheduler,
},
})
)

func reportGameRoomReadyNumber(game, schedulerName string, numberOfGameRooms int) {
Expand All @@ -164,6 +185,9 @@ func reportGameRoomErrorNumber(game, schedulerName string, numberOfGameRooms int
func reportGameRoomOccupiedNumber(game, schedulerName string, numberOfGameRooms int) {
gameRoomOccupiedGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(numberOfGameRooms))
}
func reportGameRoomActiveNumber(game, schedulerName string, numberOfGameRooms int) {
gameRoomActiveGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(numberOfGameRooms))
}

func reportInstanceReadyNumber(game, schedulerName string, numberOfInstances int) {
instanceReadyGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(numberOfInstances))
Expand All @@ -183,3 +207,7 @@ func reportInstanceTerminatingNumber(game, schedulerName string, numberOfInstanc
func reportInstanceErrorNumber(game, schedulerName string, numberOfInstances int) {
instanceErrorGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(numberOfInstances))
}

func reportTotalRunningMatches(game, schedulerName string, runningMatches int) {
runningMatchesGaugeMetric.WithLabelValues(game, schedulerName).Set(float64(runningMatches))
}
22 changes: 22 additions & 0 deletions internal/core/worker/metricsreporter/metrics_reporter_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (w *MetricsReporterWorker) reportGameRoomMetrics() {
w.reportOccupiedRooms()
w.reportTerminatingRooms()
w.reportUnreadyRooms()
w.reportActiveRooms()
w.reportTotalRunningMatches()
}

func (w *MetricsReporterWorker) reportPendingRooms() {
Expand Down Expand Up @@ -189,3 +191,23 @@ func (w *MetricsReporterWorker) reportUnreadyRooms() {
}
reportGameRoomUnreadyNumber(w.scheduler.Game, w.scheduler.Name, unreadyRooms)
}

func (w *MetricsReporterWorker) reportActiveRooms() {
activeRooms, err := w.roomStorage.GetRoomCountByStatus(w.workerContext, w.scheduler.Name, game_room.GameStatusActive)
if err != nil {
w.logger.Error("Error getting active pods", zap.Error(err))
return
}

reportGameRoomActiveNumber(w.scheduler.Game, w.scheduler.Name, activeRooms)
}

func (w *MetricsReporterWorker) reportTotalRunningMatches() {
runningMatches, err := w.roomStorage.GetRunningMatchesCount(w.workerContext, w.scheduler.Name)
if err != nil {
w.logger.Error("Error getting running matches", zap.Error(err))
return
}

reportTotalRunningMatches(w.scheduler.Game, w.scheduler.Name, runningMatches)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func TestMetricsReporterWorker_StartProduceMetrics(t *testing.T) {
Return(55, nil).MinTimes(3)
roomStorage.EXPECT().GetRoomCountByStatus(gomock.Any(), scheduler.Name, game_room.GameStatusError).
Return(66, nil).MinTimes(3)
roomStorage.EXPECT().GetRoomCountByStatus(gomock.Any(), scheduler.Name, game_room.GameStatusActive).
Return(77, nil).MinTimes(3)
roomStorage.EXPECT().GetRunningMatchesCount(gomock.Any(), scheduler.Name).
Return(88, nil).MinTimes(3)
instanceStorage.EXPECT().GetAllInstances(gomock.Any(), scheduler.Name).Return(instances, nil).MinTimes(3)

go func() {
Expand All @@ -93,12 +97,15 @@ func TestMetricsReporterWorker_StartProduceMetrics(t *testing.T) {
assert.Equal(t, float64(44), testutil.ToFloat64(gameRoomOccupiedGaugeMetric))
assert.Equal(t, float64(55), testutil.ToFloat64(gameRoomUnreadyGaugeMetric))
assert.Equal(t, float64(66), testutil.ToFloat64(gameRoomErrorGaugeMetric))
assert.Equal(t, float64(77), testutil.ToFloat64(gameRoomActiveGaugeMetric))

assert.Equal(t, float64(8), testutil.ToFloat64(instanceReadyGaugeMetric))
assert.Equal(t, float64(8), testutil.ToFloat64(instancePendingGaugeMetric))
assert.Equal(t, float64(8), testutil.ToFloat64(instanceUnknownGaugeMetric))
assert.Equal(t, float64(8), testutil.ToFloat64(instanceTerminatingGaugeMetric))
assert.Equal(t, float64(8), testutil.ToFloat64(instanceErrorGaugeMetric))

assert.Equal(t, float64(88), testutil.ToFloat64(runningMatchesGaugeMetric))
})
}

Expand Down Expand Up @@ -132,6 +139,10 @@ func TestMetricsReporterWorker_StartDoNotProduceMetrics(t *testing.T) {
Return(0, errors.New("some_error")).MinTimes(3)
roomStorage.EXPECT().GetRoomCountByStatus(gomock.Any(), scheduler.Name, game_room.GameStatusError).
Return(0, errors.New("some_error")).MinTimes(3)
roomStorage.EXPECT().GetRoomCountByStatus(gomock.Any(), scheduler.Name, game_room.GameStatusActive).
Return(0, errors.New("some_error")).MinTimes(3)
roomStorage.EXPECT().GetRunningMatchesCount(gomock.Any(), scheduler.Name).
Return(0, errors.New("some_error")).MinTimes(3)
instanceStorage.EXPECT().GetAllInstances(gomock.Any(), scheduler.Name).
Return([]*game_room.Instance{}, errors.New("some_error")).MinTimes(3)

Expand Down
2 changes: 2 additions & 0 deletions proto/api/v1/schedulers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import "google/api/annotations.proto";
import "api/v1/messages.proto";
import "google/protobuf/descriptor.proto";

// FieldOptions extension to validate the field
extend google.protobuf.FieldOptions {
// Validator for the field
optional string validator = 51234;
}

Expand Down
Loading