Skip to content

Commit

Permalink
[CORE-2256] Fix hint return and display (#9968)
Browse files Browse the repository at this point in the history
Reworked paging and hints. Added a plethora of tests against a testing
Loki instance. Worked with @pleeko to test expected vs. actual results.
  • Loading branch information
robert-uhl committed May 2, 2024
1 parent 6c0d400 commit 5c7086b
Show file tree
Hide file tree
Showing 21 changed files with 680 additions and 267 deletions.
12 changes: 12 additions & 0 deletions proto-docs.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto-docs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions python-sdk/pachyderm_sdk/api/logs/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/internal/jsonschema/logs/GetLogsRequest.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/internal/jsonschema/logs/GetLogsResponse.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/internal/jsonschema/logs/LogFilter.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/internal/jsonschema/logs/PagingHint.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/internal/jsonschema/logs/TimeRangeLogFilter.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/internal/lokiutil/testloki/testloki.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ type TestLoki struct {
lokiErrCh <-chan error
}

type Option func(config *map[string]any)

func WithoutOldSampleRejection(config *(map[string]any)) {
(*config)["limits_config"].(map[string]any)["reject_old_samples"] = false
}

func WithCreationGracePeriod(d time.Duration) func(config *(map[string]any)) {
return func(config *(map[string]any)) {
(*config)["limits_config"].(map[string]any)["creation_grace_period"] = d
}
}

// New starts a new Loki instance on the local machine.
func New(ctx context.Context, tmp string) (*TestLoki, error) {
func New(ctx context.Context, tmp string, opts ...Option) (*TestLoki, error) {
var errs error
attempts := 5
for i := 0; i < attempts; i++ {
log.Debug(ctx, "attempting to start loki", log.RetryAttempt(i, attempts))
l, err := buildAndStart(ctx, tmp)
l, err := buildAndStart(ctx, tmp, opts...)
if err != nil {
errors.JoinInto(&errs, errors.Wrapf(err, "startup attempt %d", i))
continue
Expand All @@ -50,7 +62,7 @@ func New(ctx context.Context, tmp string) (*TestLoki, error) {
return nil, errors.Wrapf(errs, "loki failed to start after %d attempts", attempts)
}

func buildAndStart(ctx context.Context, tmp string) (*TestLoki, error) {
func buildAndStart(ctx context.Context, tmp string, opts ...Option) (*TestLoki, error) {
bin, ok := bazel.FindBinary("//tools/loki", "loki")
if !ok {
log.Debug(ctx, "can't find //tools/loki via bazel, using loki in $PATH")
Expand Down Expand Up @@ -106,6 +118,9 @@ func buildAndStart(ctx context.Context, tmp string) (*TestLoki, error) {
config["server"].(map[string]any)["http_listen_port"] = port
config["server"].(map[string]any)["grpc_listen_port"] = port + 1
config["schema_config"].(map[string]any)["configs"].([]any)[0].(map[string]any)["from"] = "2020-10-24"
for _, opt := range opts {
opt(&config)
}

configBytes, err := yaml.Marshal(config)
if err != nil {
Expand Down
146 changes: 78 additions & 68 deletions src/logs/logs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/logs/logs.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/logs/logs.pb.zap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c7086b

Please sign in to comment.