mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-07 13:49:02 +00:00
fix(logs): resolve time ranges using client local time zone for logs commands
This commit is contained in:
1 parent
e3479409b1
commit
5fa236871f
13 files changed
+282
-16
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/cli"
|
||||
"github.com/psviderski/uncloud/internal/cli/completion"
|
||||
@@ -64,6 +65,11 @@ If no services are specified, streams logs from the uncloud service.`,
|
||||
}
|
||||
|
||||
func runLogs(ctx context.Context, uncli *cli.CLI, services []string, opts logs.Options) error {
|
||||
since, until, err := logs.TimeRange(opts.Since, opts.Until, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(services) == 0 {
|
||||
services = []string{api.SystemServiceUncloud}
|
||||
}
|
||||
@@ -88,8 +94,8 @@ func runLogs(ctx context.Context, uncli *cli.CLI, services []string, opts logs.O
|
||||
logsOpts := api.ServiceLogsOptions{
|
||||
Follow: opts.Follow,
|
||||
Tail: tail,
|
||||
Since: opts.Since,
|
||||
Until: opts.Until,
|
||||
Since: since,
|
||||
Until: until,
|
||||
Machines: cli.ExpandCommaSeparatedValues(opts.Machines),
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/cli/logs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunLogsInvalidTimeFilters(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Invalid filters must fail before connecting to the cluster.
|
||||
for _, flag := range []string{"since", "until"} {
|
||||
opts := logs.Options{}
|
||||
if flag == "since" {
|
||||
opts.Since = "invalid"
|
||||
} else {
|
||||
opts.Until = "invalid"
|
||||
}
|
||||
err := runLogs(context.Background(), nil, nil, opts)
|
||||
require.ErrorContains(t, err, "invalid --"+flag+" value")
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/psviderski/uncloud/internal/cli"
|
||||
@@ -78,6 +79,11 @@ If no services are specified, streams logs from all services defined in the Comp
|
||||
}
|
||||
|
||||
func RunLogs(ctx context.Context, uncli *cli.CLI, args []string, opts logs.Options) error {
|
||||
since, until, err := logs.TimeRange(opts.Since, opts.Until, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
serviceArgs, err := logs.ParseServiceArgs(args)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -121,8 +127,8 @@ func RunLogs(ctx context.Context, uncli *cli.CLI, args []string, opts logs.Optio
|
||||
baseOpts := api.ServiceLogsOptions{
|
||||
Follow: opts.Follow,
|
||||
Tail: tail,
|
||||
Since: opts.Since,
|
||||
Until: opts.Until,
|
||||
Since: since,
|
||||
Until: until,
|
||||
Machines: cli.ExpandCommaSeparatedValues(opts.Machines),
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/psviderski/uncloud/internal/cli/logs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunLogsInvalidTimeFilters(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Invalid filters must fail before loading Compose files or connecting to the cluster.
|
||||
for _, flag := range []string{"since", "until"} {
|
||||
opts := logs.Options{}
|
||||
if flag == "since" {
|
||||
opts.Since = "invalid"
|
||||
} else {
|
||||
opts.Until = "invalid"
|
||||
}
|
||||
err := RunLogs(context.Background(), nil, nil, opts)
|
||||
require.ErrorContains(t, err, "invalid --"+flag+" value")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user