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

Frontend example graceful shutdown #31

Merged
merged 2 commits into from
Oct 31, 2024
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
10 changes: 5 additions & 5 deletions loadtest/aqua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# - all
registries:
- type: standard
ref: v4.107.0 # renovate: depName=aquaproj/aqua-registry
ref: v4.246.0 # renovate: depName=aquaproj/aqua-registry
packages:
- name: ko-build/ko@v0.15.1
- name: helmfile/helmfile@v0.159.0
- name: GoogleContainerTools/skaffold@v2.9.0
- name: helm/helm@v3.13.3
- name: ko-build/ko@v0.17.1
- name: helmfile/helmfile@v0.169.1
- name: GoogleContainerTools/skaffold@v2.13.2
- name: helm/helm@v3.16.2
3 changes: 2 additions & 1 deletion loadtest/cmd/attacker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ func main() {
for {
select {
case <-ctx.Done():
log.Printf("shutting down attacker...")
return
case <-ticker.C:
go createAndWatchTicket(ctx, frontendAddr, matchTimeout)
go createAndWatchTicket(context.Background(), frontendAddr, matchTimeout)
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions loadtest/cmd/frontend/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package main

import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"

cache "github.com/Code-Hex/go-generics-cache"
Expand All @@ -17,6 +21,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/sdk/metric"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"open-match.dev/open-match/pkg/pb"

Expand Down Expand Up @@ -57,8 +62,22 @@ func main() {
if err != nil {
log.Fatalf("failed to listen gRPC server via %s: %+v", addr, err)
}
log.Printf("frontend service is listening on %s...", addr)
if err := sv.Serve(lis); err != nil {

// start frontend server
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
defer cancel()
eg := new(errgroup.Group)
eg.Go(func() error {
log.Printf("frontend service is listening on %s...", addr)
return sv.Serve(lis)
})

// wait for stop signal
<-ctx.Done()
log.Printf("shutting down frontend service...")
// shutdown gracefully
sv.GracefulStop()
if err := eg.Wait(); err != nil {
log.Fatalf("failed to serve gRPC server: %+v", err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions loadtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
go.opentelemetry.io/otel/exporters/prometheus v0.44.0
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/sdk/metric v1.24.0
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.62.1
open-match.dev/open-match v1.8.1
)
Expand All @@ -41,9 +42,8 @@ require (
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
Expand Down
8 changes: 4 additions & 4 deletions loadtest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb h1:pC9Okm6BVmxEw76PUu0XUbOTQ92JX11hfvqTjAV3qxM=
golang.org/x/exp v0.0.0-20220328175248-053ad81199eb/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
Loading