refactor: replace usages of the spec compiler with the ast compiler (#13222)
This replaces usages of the spec compiler with the ast compiler and it removes the error message referencing the spec compiler as an available input. It does not remove any of the code using the spec compiler that is involved for proxying requests and it does not remove it from the API.pull/13405/head
parent
5e09aa178b
commit
b68b5053db
|
|
@ -102,6 +102,8 @@ func TestPipeline_WriteV2_Query(t *testing.T) {
|
|||
// This test initializes a default launcher; writes some data; queries the data (success);
|
||||
// sets memory limits to the same read query; checks that the query fails because limits are exceeded.
|
||||
func TestPipeline_QueryMemoryLimits(t *testing.T) {
|
||||
t.Skip("setting memory limits in the client is not implemented yet")
|
||||
|
||||
l := launcher.RunTestLauncherOrFail(t, ctx)
|
||||
l.SetupOrFail(t)
|
||||
defer l.ShutdownOrFail(t, ctx)
|
||||
|
|
@ -112,7 +114,8 @@ func TestPipeline_QueryMemoryLimits(t *testing.T) {
|
|||
}
|
||||
|
||||
// compile a from query and get the spec
|
||||
spec, err := flux.Compile(context.Background(), fmt.Sprintf(`from(bucket:"%s") |> range(start:-5m)`, l.Bucket.Name), time.Now())
|
||||
qs := fmt.Sprintf(`from(bucket:"%s") |> range(start:-5m)`, l.Bucket.Name)
|
||||
pkg, err := flux.Parse(qs)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -121,8 +124,8 @@ func TestPipeline_QueryMemoryLimits(t *testing.T) {
|
|||
req := &query.Request{
|
||||
Authorization: l.Auth,
|
||||
OrganizationID: l.Org.ID,
|
||||
Compiler: lang.SpecCompiler{
|
||||
Spec: spec,
|
||||
Compiler: lang.ASTCompiler{
|
||||
AST: pkg,
|
||||
},
|
||||
}
|
||||
if err := l.QueryAndNopConsume(context.Background(), req); err != nil {
|
||||
|
|
@ -131,9 +134,9 @@ func TestPipeline_QueryMemoryLimits(t *testing.T) {
|
|||
|
||||
// ok, the first request went well, let's add memory limits:
|
||||
// this query should error.
|
||||
spec.Resources = flux.ResourceManagement{
|
||||
MemoryBytesQuota: 100,
|
||||
}
|
||||
// spec.Resources = flux.ResourceManagement{
|
||||
// MemoryBytesQuota: 100,
|
||||
// }
|
||||
|
||||
if err := l.QueryAndNopConsume(context.Background(), req); err != nil {
|
||||
if !strings.Contains(err.Error(), "allocation limit reached") {
|
||||
|
|
|
|||
|
|
@ -64,8 +64,10 @@ func (r QueryRequest) WithDefaults() QueryRequest {
|
|||
|
||||
// Validate checks the query request and returns an error if the request is invalid.
|
||||
func (r QueryRequest) Validate() error {
|
||||
// TODO(jsternberg): Remove this, but we are going to not mention
|
||||
// the spec in the error if it is being used.
|
||||
if r.Query == "" && r.Spec == nil && r.AST == nil {
|
||||
return errors.New(`request body requires either query, spec, or AST`)
|
||||
return errors.New(`request body requires either query or AST`)
|
||||
}
|
||||
|
||||
if r.Spec != nil && r.Extern != nil {
|
||||
|
|
@ -220,7 +222,7 @@ func (r QueryRequest) proxyRequest(now func() time.Time) (*query.ProxyRequest, e
|
|||
if err := r.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Query is preferred over spec
|
||||
// Query is preferred over AST
|
||||
var compiler flux.Compiler
|
||||
if r.Query != "" {
|
||||
pkg, err := flux.Parse(r.Query)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ func (p *syncRunPromise) finish(res *runResult, err error) {
|
|||
func (p *syncRunPromise) doQuery(wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
spec, err := flux.Compile(p.ctx, p.t.Flux, time.Unix(p.qr.Now, 0))
|
||||
pkg, err := flux.Parse(p.t.Flux)
|
||||
if err != nil {
|
||||
p.finish(nil, err)
|
||||
return
|
||||
|
|
@ -162,8 +162,9 @@ func (p *syncRunPromise) doQuery(wg *sync.WaitGroup) {
|
|||
req := &query.Request{
|
||||
Authorization: p.auth,
|
||||
OrganizationID: p.t.OrganizationID,
|
||||
Compiler: lang.SpecCompiler{
|
||||
Spec: spec,
|
||||
Compiler: lang.ASTCompiler{
|
||||
AST: pkg,
|
||||
Now: time.Unix(p.qr.Now, 0),
|
||||
},
|
||||
}
|
||||
it, err := p.qs.Query(p.ctx, req)
|
||||
|
|
@ -232,7 +233,7 @@ func (e *asyncQueryServiceExecutor) Execute(ctx context.Context, run backend.Que
|
|||
return nil, err
|
||||
}
|
||||
|
||||
spec, err := flux.Compile(ctx, t.Flux, time.Unix(run.Now, 0))
|
||||
pkg, err := flux.Parse(t.Flux)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -240,8 +241,9 @@ func (e *asyncQueryServiceExecutor) Execute(ctx context.Context, run backend.Que
|
|||
req := &query.Request{
|
||||
Authorization: auth,
|
||||
OrganizationID: t.OrganizationID,
|
||||
Compiler: lang.SpecCompiler{
|
||||
Spec: spec,
|
||||
Compiler: lang.ASTCompiler{
|
||||
AST: pkg,
|
||||
Now: time.Unix(run.Now, 0),
|
||||
},
|
||||
}
|
||||
// Only set the authorizer on the context where we need it here.
|
||||
|
|
|
|||
|
|
@ -37,15 +37,18 @@ type fakeQueryService struct {
|
|||
|
||||
var _ query.AsyncQueryService = (*fakeQueryService)(nil)
|
||||
|
||||
func makeSpec(q string) *flux.Spec {
|
||||
qs, err := flux.Compile(context.Background(), q, time.Unix(123, 0))
|
||||
func makeAST(q string) lang.ASTCompiler {
|
||||
pkg, err := flux.Parse(q)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return qs
|
||||
return lang.ASTCompiler{
|
||||
AST: pkg,
|
||||
Now: time.Unix(123, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func makeSpecString(q *flux.Spec) string {
|
||||
func makeASTString(q lang.ASTCompiler) string {
|
||||
b, err := json.Marshal(q)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -71,16 +74,16 @@ func (s *fakeQueryService) Query(ctx context.Context, req *query.Request) (flux.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
sc, ok := req.Compiler.(lang.SpecCompiler)
|
||||
astc, ok := req.Compiler.(lang.ASTCompiler)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("fakeQueryService only supports the SpecCompiler, got %T", req.Compiler)
|
||||
return nil, fmt.Errorf("fakeQueryService only supports the ASTCompiler, got %T", req.Compiler)
|
||||
}
|
||||
|
||||
fq := &fakeQuery{
|
||||
wait: make(chan struct{}),
|
||||
results: make(chan flux.Result),
|
||||
}
|
||||
s.queries[makeSpecString(sc.Spec)] = fq
|
||||
s.queries[makeASTString(astc)] = fq
|
||||
|
||||
go fq.run(ctx)
|
||||
|
||||
|
|
@ -93,7 +96,7 @@ func (s *fakeQueryService) SucceedQuery(script string) {
|
|||
defer s.mu.Unlock()
|
||||
|
||||
// Unblock the flux.
|
||||
spec := makeSpecString(makeSpec(script))
|
||||
spec := makeASTString(makeAST(script))
|
||||
close(s.queries[spec].wait)
|
||||
delete(s.queries, spec)
|
||||
}
|
||||
|
|
@ -104,7 +107,7 @@ func (s *fakeQueryService) FailQuery(script string, forced error) {
|
|||
defer s.mu.Unlock()
|
||||
|
||||
// Unblock the flux.
|
||||
spec := makeSpecString(makeSpec(script))
|
||||
spec := makeASTString(makeAST(script))
|
||||
s.queries[spec].forcedError = forced
|
||||
close(s.queries[spec].wait)
|
||||
delete(s.queries, spec)
|
||||
|
|
@ -122,7 +125,7 @@ func (s *fakeQueryService) WaitForQueryLive(t *testing.T, script string) {
|
|||
t.Helper()
|
||||
|
||||
const attempts = 10
|
||||
spec := makeSpecString(makeSpec(script))
|
||||
spec := makeASTString(makeAST(script))
|
||||
for i := 0; i < attempts; i++ {
|
||||
if i != 0 {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
|
|
|
|||
Loading…
Reference in New Issue