-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added /-/healthy endpoint to Rule and the generic metrics HTTP …
…server. Signed-off-by: Martin Chodur <[email protected]>
- Loading branch information
Showing
12 changed files
with
252 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/improbable-eng/thanos/pkg/runutil" | ||
"github.com/improbable-eng/thanos/pkg/testutil" | ||
"github.com/oklog/run" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func queryHTTPGetEndpoint(ctx context.Context, t *testing.T, logger log.Logger, url string) (*http.Response, error) { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s", url), nil) | ||
testutil.Ok(t, err) | ||
return http.DefaultClient.Do(req.WithContext(ctx)) | ||
} | ||
|
||
func isHealthy() (bool, error) { | ||
return true, nil | ||
} | ||
|
||
func TestGenericHttpEndpoints(t *testing.T) { | ||
var g run.Group | ||
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) | ||
metricsRegistry := prometheus.NewRegistry() | ||
component := "sidecar" | ||
ctx := context.Background() | ||
|
||
freePort, err := testutil.FreePort() | ||
testutil.Ok(t, err) | ||
|
||
serverAddress := fmt.Sprintf("127.0.0.1:%d", freePort) | ||
|
||
err = metricHTTPListenGroup(&g, logger, metricsRegistry, serverAddress, component, isHealthy) | ||
testutil.Ok(t, err) | ||
go func() { _ = g.Run() }() | ||
|
||
testutil.Ok(t, runutil.Retry(time.Second, ctx.Done(), func() error { | ||
resp, err := queryHTTPGetEndpoint(ctx, t, log.NewNopLogger(), path.Join(serverAddress, "/-/healthy")) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, 200, resp.StatusCode) | ||
return err | ||
})) | ||
|
||
testutil.Ok(t, runutil.Retry(time.Second, ctx.Done(), func() error { | ||
resp, err := queryHTTPGetEndpoint(ctx, t, log.NewNopLogger(), path.Join(serverAddress, "/-/ready")) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, 200, resp.StatusCode) | ||
return err | ||
})) | ||
|
||
testutil.Ok(t, runutil.Retry(time.Second, ctx.Done(), func() error { | ||
resp, err := queryHTTPGetEndpoint(ctx, t, log.NewNopLogger(), path.Join(serverAddress, "/metrics")) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, 200, resp.StatusCode) | ||
return err | ||
})) | ||
|
||
testutil.Ok(t, runutil.Retry(time.Second, ctx.Done(), func() error { | ||
resp, err := queryHTTPGetEndpoint(ctx, t, log.NewNopLogger(), path.Join(serverAddress, "/debug/pprof/")) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, 200, resp.StatusCode) | ||
return err | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.