new tracing system

This commit is contained in:
Joe Kralicky 2025-01-03 19:45:53 +00:00
parent 8f36870650
commit b9065b6a55
No known key found for this signature in database
GPG key ID: 75C4875F34A9FB79
130 changed files with 7928 additions and 1836 deletions

View file

@ -0,0 +1,40 @@
package snippets
import (
"context"
"errors"
"net/http"
"github.com/pomerium/pomerium/internal/log"
"github.com/pomerium/pomerium/internal/testenv"
)
func RunWithDelayedShutdown(ctx context.Context, serve func() error, stop func()) func() error {
env := testenv.EnvFromContext(ctx)
stopping := make(chan struct{})
serveExited := make(chan error, 1)
env.OnStateChanged(testenv.Stopping, func() {
close(stopping)
})
cancel := env.OnStateChanged(testenv.Stopped, func() {
stop()
if err := <-serveExited; err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Ctx(ctx).Err(err).Msg("error stopping server")
}
})
go func() {
serveExited <- serve()
close(serveExited)
}()
return func() error {
select {
case <-stopping:
return nil
case err := <-serveExited:
cancel()
return err
}
}
}