diff options
author | cdoern <cdoern@redhat.com> | 2021-08-09 10:07:46 -0400 |
---|---|---|
committer | cdoern <cdoern@redhat.com> | 2021-08-23 12:51:56 -0400 |
commit | d06d285e66251784126b4f19e047c2a93182d08e (patch) | |
tree | 1a1078cc0bca1f2c9fb864dd268c4644e381b8a7 | |
parent | 04ab2b16617fe2d3178eb0b461aacbcab609611e (diff) | |
download | podman-d06d285e66251784126b4f19e047c2a93182d08e.tar.gz podman-d06d285e66251784126b4f19e047c2a93182d08e.tar.bz2 podman-d06d285e66251784126b4f19e047c2a93182d08e.zip |
logFile until flag issue
we were adding a negative duration in podman events, causing inputs like
-5s to be correct and 5s to be incorrect.
fixes #11158
Signed-off-by: cdoern <cdoern@redhat.com>
-rw-r--r-- | cmd/podman/containers/logs.go | 4 | ||||
-rw-r--r-- | libpod/events/filters.go | 4 | ||||
-rw-r--r-- | libpod/events/journal_linux.go | 4 | ||||
-rw-r--r-- | libpod/events/logfile.go | 2 | ||||
-rw-r--r-- | pkg/api/handlers/compat/containers_logs.go | 4 | ||||
-rw-r--r-- | pkg/util/utils.go | 7 | ||||
-rw-r--r-- | pkg/util/utils_test.go | 2 | ||||
-rw-r--r-- | test/e2e/events_test.go | 13 | ||||
-rw-r--r-- | test/e2e/logs_test.go | 2 |
9 files changed, 30 insertions, 12 deletions
diff --git a/cmd/podman/containers/logs.go b/cmd/podman/containers/logs.go index 00a8d4b52..1548c6c24 100644 --- a/cmd/podman/containers/logs.go +++ b/cmd/podman/containers/logs.go @@ -120,7 +120,7 @@ func logsFlags(cmd *cobra.Command) { func logs(_ *cobra.Command, args []string) error { if logsOptions.SinceRaw != "" { // parse time, error out if something is wrong - since, err := util.ParseInputTime(logsOptions.SinceRaw) + since, err := util.ParseInputTime(logsOptions.SinceRaw, true) if err != nil { return errors.Wrapf(err, "error parsing --since %q", logsOptions.SinceRaw) } @@ -128,7 +128,7 @@ func logs(_ *cobra.Command, args []string) error { } if logsOptions.UntilRaw != "" { // parse time, error out if something is wrong - until, err := util.ParseInputTime(logsOptions.UntilRaw) + until, err := util.ParseInputTime(logsOptions.UntilRaw, false) if err != nil { return errors.Wrapf(err, "error parsing --until %q", logsOptions.UntilRaw) } diff --git a/libpod/events/filters.go b/libpod/events/filters.go index 4d27e8fc4..d5e2b81f3 100644 --- a/libpod/events/filters.go +++ b/libpod/events/filters.go @@ -135,7 +135,7 @@ func generateEventFilters(filters []string, since, until string) (map[string][]E } if len(since) > 0 { - timeSince, err := util.ParseInputTime(since) + timeSince, err := util.ParseInputTime(since, true) if err != nil { return nil, errors.Wrapf(err, "unable to convert since time of %s", since) } @@ -144,7 +144,7 @@ func generateEventFilters(filters []string, since, until string) (map[string][]E } if len(until) > 0 { - timeUntil, err := util.ParseInputTime(until) + timeUntil, err := util.ParseInputTime(until, false) if err != nil { return nil, errors.Wrapf(err, "unable to convert until time of %s", until) } diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 7006290e9..a3e0d9754 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -73,13 +73,15 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { if err != nil { return errors.Wrapf(err, "failed to parse event filters") } + var untilTime time.Time if len(options.Until) > 0 { - untilTime, err = util.ParseInputTime(options.Until) + untilTime, err = util.ParseInputTime(options.Until, false) if err != nil { return err } } + j, err := sdjournal.NewJournal() if err != nil { return err diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go index 952444f2b..e3f0ab8f0 100644 --- a/libpod/events/logfile.go +++ b/libpod/events/logfile.go @@ -53,7 +53,7 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error { return err } if len(options.Until) > 0 { - untilTime, err := util.ParseInputTime(options.Until) + untilTime, err := util.ParseInputTime(options.Until, false) if err != nil { return err } diff --git a/pkg/api/handlers/compat/containers_logs.go b/pkg/api/handlers/compat/containers_logs.go index 656e2c627..50cdb1e65 100644 --- a/pkg/api/handlers/compat/containers_logs.go +++ b/pkg/api/handlers/compat/containers_logs.go @@ -63,7 +63,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { var since time.Time if _, found := r.URL.Query()["since"]; found { - since, err = util.ParseInputTime(query.Since) + since, err = util.ParseInputTime(query.Since, true) if err != nil { utils.BadRequest(w, "since", query.Since, err) return @@ -73,7 +73,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) { var until time.Time if _, found := r.URL.Query()["until"]; found { if query.Until != "0" { - until, err = util.ParseInputTime(query.Until) + until, err = util.ParseInputTime(query.Until, false) if err != nil { utils.BadRequest(w, "until", query.Until, err) return diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 774590f44..37a00c25c 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -520,7 +520,7 @@ func WriteStorageConfigFile(storageOpts *stypes.StoreOptions, storageConf string // ParseInputTime takes the users input and to determine if it is valid and // returns a time format and error. The input is compared to known time formats // or a duration which implies no-duration -func ParseInputTime(inputTime string) (time.Time, error) { +func ParseInputTime(inputTime string, since bool) (time.Time, error) { timeFormats := []string{time.RFC3339Nano, time.RFC3339, "2006-01-02T15:04:05", "2006-01-02T15:04:05.999999999", "2006-01-02Z07:00", "2006-01-02"} // iterate the supported time formats @@ -542,7 +542,10 @@ func ParseInputTime(inputTime string) (time.Time, error) { if err != nil { return time.Time{}, errors.Errorf("unable to interpret time value") } - return time.Now().Add(-duration), nil + if since { + return time.Now().Add(-duration), nil + } + return time.Now().Add(duration), nil } // OpenExclusiveFile opens a file for writing and ensure it doesn't already exist diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go index 027acbdab..35322c7ea 100644 --- a/pkg/util/utils_test.go +++ b/pkg/util/utils_test.go @@ -280,7 +280,7 @@ func TestPeriodAndQuotaToCores(t *testing.T) { } func TestParseInputTime(t *testing.T) { - tm, err := ParseInputTime("1.5") + tm, err := ParseInputTime("1.5", true) if err != nil { t.Errorf("expected error to be nil but was: %v", err) } diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go index e2a169383..46ea10c56 100644 --- a/test/e2e/events_test.go +++ b/test/e2e/events_test.go @@ -184,6 +184,19 @@ var _ = Describe("Podman events", func() { Expect(result.OutputToString()).To(ContainSubstring(name2)) Expect(result.OutputToString()).To(ContainSubstring(name3)) + // string duration in 10 seconds + untilT := time.Now().Add(time.Second * 9) + result = podmanTest.Podman([]string{"events", "--since", "30s", "--until", "10s"}) + result.Wait(11) + Expect(result).Should(Exit(0)) + tEnd := time.Now() + outDur := tEnd.Sub(untilT) + diff := outDur.Seconds() > 0 + Expect(diff).To(Equal(true)) + Expect(result.OutputToString()).To(ContainSubstring(name1)) + Expect(result.OutputToString()).To(ContainSubstring(name2)) + Expect(result.OutputToString()).To(ContainSubstring(name3)) + wg.Wait() }) }) diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 0a973b802..71d30f063 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -145,7 +145,7 @@ var _ = Describe("Podman logs", func() { results := podmanTest.Podman([]string{"logs", "--until", "10m", cid}) results.WaitWithDefaultTimeout() Expect(results).To(Exit(0)) - Expect(len(results.OutputToStringArray())).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(3)) }) It("until time NOW: "+log, func() { |