mirror of
https://github.com/containers/podman
synced 2024-10-18 16:24:34 +00:00
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>
This commit is contained in:
parent
dda3e5b4e4
commit
c28720dc52
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue