Skip to content

Commit

Permalink
chore: add basic IT for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Apr 24, 2024
1 parent 4bd8d49 commit c107156
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
33 changes: 33 additions & 0 deletions build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -1262,6 +1263,38 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, opts integration.Tes
})
})

t.Run("Metrics", func(t *testing.T) {
if authConfig.Required() {
t.Skip("Skipping metrics test for now as it requires authentication")
}

if protocol == integration.ProtocolGRPC {
t.Skip("Skipping metrics test for now as it requires HTTP/HTTPS protocol")
}

t.Log(`Ensure /metrics endpoint is reachable.`)

resp, err := http.Get(fmt.Sprintf("%s/metrics", addr))
require.NoError(t, err)

require.NotNil(t, resp)

assert.Equal(t, resp.StatusCode, http.StatusOK)

t.Log(`Ensure /metrics endpoint returns expected content type.`)

assert.Contains(t, resp.Header.Get("Content-Type"), "text/plain; version=0.0.4")

t.Log(`Ensure /metrics endpoint returns expected metrics.`)

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)

defer resp.Body.Close()

assert.Contains(t, string(body), "flipt_evaluations_requests_total")
})

t.Run("Delete", func(t *testing.T) {
if !namespaceIsDefault(namespace) {
t.Log(`Namespace with flags fails.`)
Expand Down
18 changes: 14 additions & 4 deletions build/testing/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ func (a AuthConfig) NamespaceScoped() bool {
return a == StaticTokenAuthNamespaced
}

type Protocol string

const (
ProtocolHTTP Protocol = "http"
ProtocolHTTPS Protocol = "https"
ProtocolGRPC Protocol = "grpc"
)

type TestOpts struct {
Addr string
Protocol string
Protocol Protocol
Namespace string
AuthConfig AuthConfig
References bool
Expand All @@ -75,14 +83,16 @@ type TestOpts struct {
func Harness(t *testing.T, fn func(t *testing.T, sdk sdk.SDK, opts TestOpts)) {
var transport sdk.Transport

protocol, host, _ := strings.Cut(*fliptAddr, "://")
p, host, _ := strings.Cut(*fliptAddr, "://")
protocol := Protocol(p)

switch protocol {
case "grpc":
case ProtocolGRPC:
conn, err := grpc.Dial(host, grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)

transport = sdkgrpc.NewTransport(conn)
case "http", "https":
case ProtocolHTTP, ProtocolHTTPS:
transport = sdkhttp.NewTransport(fmt.Sprintf("%s://%s", protocol, host))
default:
t.Fatalf("Unexpected flipt address protocol %s://%s", protocol, host)
Expand Down

0 comments on commit c107156

Please sign in to comment.