-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): parse query from string
- Loading branch information
Showing
3 changed files
with
81 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/humanlogio/humanlog/internal/pkg/state" | ||
"github.com/humanlogio/humanlog/pkg/localstorage" | ||
"github.com/humanlogio/humanlog/pkg/sink" | ||
"github.com/humanlogio/logql/parse" | ||
Check failure on line 21 in internal/localsvc/svc.go GitHub Actions / test (stable, ubuntu-latest)
Check failure on line 21 in internal/localsvc/svc.go GitHub Actions / test (stable, macos-latest)
|
||
"golang.org/x/sync/errgroup" | ||
"google.golang.org/protobuf/types/known/durationpb" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
|
@@ -273,10 +274,21 @@ func (svc *Service) SummarizeEvents(ctx context.Context, req *connect.Request[qr | |
} | ||
func (svc *Service) WatchQuery(ctx context.Context, req *connect.Request[qrv1.WatchQueryRequest], stream *connect.ServerStream[qrv1.WatchQueryResponse]) error { | ||
query := req.Msg.GetQuery() | ||
if query == nil { | ||
if req.Msg.PlaintextQuery == nil { | ||
return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("need either a `query` object or a `plaintext_query` string")) | ||
} | ||
var err error | ||
query, err = parse.Parse(req.Msg.PlaintextQuery.Query) | ||
if err != nil { | ||
return connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("parsing `plaintext_query`: %v", err)) | ||
} | ||
} | ||
|
||
ll := svc.ll.With( | ||
slog.String("query.query", query.Query.String()), | ||
) | ||
|
||
if query.From != nil { | ||
ll = ll.With(slog.String("query.from", query.From.AsTime().Format(time.RFC3339Nano))) | ||
} | ||
|