-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
616e81a
commit 8aa7d5b
Showing
3 changed files
with
132 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package frontend | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"connectrpc.com/connect" | ||
"github.com/grafana/dskit/user" | ||
querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1" | ||
"github.com/grafana/pyroscope/pkg/util/httpgrpc" | ||
"github.com/opentracing/opentracing-go" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockLimits struct{} | ||
|
||
func (m *mockLimits) QuerySplitDuration(_ string) time.Duration { | ||
return time.Hour | ||
} | ||
|
||
func (m *mockLimits) MaxQueryParallelism(_ string) int { | ||
return 100 | ||
} | ||
|
||
func (m *mockLimits) MaxQueryLength(_ string) time.Duration { | ||
return time.Hour | ||
} | ||
|
||
func (m *mockLimits) MaxQueryLookback(_ string) time.Duration { | ||
return time.Hour * 24 | ||
} | ||
|
||
func (m *mockLimits) QueryAnalysisEnabled(_ string) bool { | ||
return true | ||
} | ||
|
||
func (m *mockLimits) MaxFlameGraphNodesDefault(_ string) int { | ||
return 10_000 | ||
} | ||
|
||
func (m *mockLimits) MaxFlameGraphNodesMax(_ string) int { | ||
return 100_000 | ||
} | ||
|
||
type mockRoundTripper struct { | ||
callback func(ctx context.Context, req *httpgrpc.HTTPRequest) (*httpgrpc.HTTPResponse, error) | ||
} | ||
|
||
func (m *mockRoundTripper) RoundTripGRPC(ctx context.Context, req *httpgrpc.HTTPRequest) (*httpgrpc.HTTPResponse, error) { | ||
if m.callback != nil { | ||
return m.callback(ctx, req) | ||
} | ||
return &httpgrpc.HTTPResponse{}, errors.New("not implemented") | ||
} | ||
|
||
func Test_Frontend_Diff(t *testing.T) { | ||
frontend := Frontend{ | ||
limits: &mockLimits{}, | ||
} | ||
|
||
ctx := user.InjectOrgID(context.Background(), "test") | ||
_, ctx = opentracing.StartSpanFromContext(ctx, "test") | ||
now := time.Now().UnixMilli() | ||
|
||
profileType := "memory:inuse_space:bytes:space:byte" | ||
|
||
t.Run("Diff outside of the query window", func(t *testing.T) { | ||
resp, err := frontend.Diff( | ||
ctx, | ||
connect.NewRequest(&querierv1.DiffRequest{ | ||
Left: &querierv1.SelectMergeStacktracesRequest{ | ||
ProfileTypeID: profileType, | ||
LabelSelector: "{}", | ||
Start: 0000, | ||
End: 1000, | ||
}, | ||
Right: &querierv1.SelectMergeStacktracesRequest{ | ||
ProfileTypeID: profileType, | ||
LabelSelector: "{}", | ||
Start: 2000, | ||
End: 3000, | ||
}, | ||
}), | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
}) | ||
|
||
t.Run("Failing left hand side", func(t *testing.T) { | ||
frontend.GRPCRoundTripper = &mockRoundTripper{callback: func(ctx context.Context, req *httpgrpc.HTTPRequest) (*httpgrpc.HTTPResponse, error) { | ||
t.Logf("mockRoundTripper callback: %v", req) | ||
return nil, errors.New("mockRoundTripper callback error") | ||
}} | ||
|
||
resp, err := frontend.Diff( | ||
ctx, | ||
connect.NewRequest(&querierv1.DiffRequest{ | ||
Left: &querierv1.SelectMergeStacktracesRequest{ | ||
ProfileTypeID: profileType, | ||
LabelSelector: "{}", | ||
Start: now + 0000, | ||
End: now + 1000, | ||
}, | ||
Right: &querierv1.SelectMergeStacktracesRequest{ | ||
ProfileTypeID: profileType, | ||
LabelSelector: "{}", | ||
Start: now + 2000, | ||
End: now + 3000, | ||
}, | ||
}), | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
}) | ||
|
||
} |
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