Skip to content

Commit

Permalink
feat(cl-mimicry): add probe server
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Apr 18, 2024
1 parent 728ff47 commit 7d6be5d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/clmimicry/mimicry.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func (m *Mimicry) Start(ctx context.Context) error {
}
}

if m.Config.ProbeAddr != nil {
if err := m.ServeProbe(ctx); err != nil {
return err
}
}

m.log.
WithField("version", xatu.Full()).
WithField("id", m.id.String()).
Expand Down Expand Up @@ -214,6 +220,30 @@ func (m *Mimicry) ServePProf(ctx context.Context) error {
return nil
}

func (m *Mimicry) ServeProbe(ctx context.Context) error {
probeServer := &http.Server{
Addr: *m.Config.ProbeAddr,
ReadHeaderTimeout: 120 * time.Second,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("OK"))
if err != nil {
m.log.Error("Failed to write response: ", err)
}
}),
}

go func() {
m.log.Infof("Serving probe at %s", *m.Config.ProbeAddr)

if err := probeServer.ListenAndServe(); err != nil {
m.log.Fatal(err)
}
}()

return nil
}

func (m *Mimicry) createNewClientMeta(ctx context.Context) (*xatu.ClientMeta, error) {
return &xatu.ClientMeta{
Name: m.Config.Name,
Expand Down

0 comments on commit 7d6be5d

Please sign in to comment.