Bug 1240538

Summary: Add direct support for time in LVM reports and LVM selection criteria
Product: Red Hat Enterprise Linux 7 Reporter: Peter Rajnoha <prajnoha>
Component: lvm2Assignee: Peter Rajnoha <prajnoha>
lvm2 sub component: Default / Unclassified QA Contact: cluster-qe <cluster-qe>
Status: CLOSED ERRATA Docs Contact:
Severity: low    
Priority: medium CC: agk, cmarthal, heinzm, jbrassow, msnitzer, prajnoha, prockai, rbednar, slevine, zkabelac
Version: 7.2Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: lvm2-2.02.125-1.el7 Doc Type: Bug Fix
Doc Text:
There are several changes in this release to provide better support for time reporting fields and selection based on these time fields in LVM2: - The lv_time reporting field is now recognized as proper time field, not just a string as it was before. - There's a new report/time_format lvm.conf setting to set the exact time format for time reporting fields (currently only lv_time field). See comments for report/time_format in /etc/lvm/lvm.conf file for more information about the formatting options that are supported. - Also, users can use time expressions in their selection criteria provided by -S|--select now. It's possible to define complete time specification (YYYY-MM-DD) or its subset: Recognized operators: "since" as an alias for ">=" "after" as an alias for ">" "until" as an alias for "<=" "before" as an alias for "<" The time specification: date time timezone date: YYYY-MM-DD (or shortly YYYYMMDD) YYYY-MM (shortly YYYYMM), auto DD=1 YYYY, auto MM=01 and DD=01 time: hh:mm:ss (or shortly hhmmss) hh:mm (or shortly hhmm), auto ss=0 hh (or shortly hh), auto mm=0, auto ss=0 timezone (always with + or - sign): +hh:mm or -hh:mm (or shortly +hhmm or -hhmm) +hh or -hh Alternatively, time can be expressed in the form which resembles to human language more: Then using free-form time expressions: - weekday names ("Sunday" - "Saturday" or abbreviated as "Sun" - "Sat") - labels for points in time ("noon", "midnight") - labels for a day relative to current day ("today", "yesterday") - points back in time with relative offset from today (N is a number) ( "N" "seconds"/"minutes"/"hours"/"days"/"weeks"/"years" "ago") ( "N" "secs"/"mins"/"hrs" ... "ago") ( "N" "s"/"m"/"h" ... "ago") - time specification either in hh:mm:ss format or with AM/PM suffixes - month names ("January" - "December" or abbreviated as "Jan" - "Dec")
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 12:46:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1163895    

Description Peter Rajnoha 2015-07-07 08:17:33 UTC
This is part of solution for original bug #1163895 so all the parts can be properly tested.

This bug is about extending reporting code to support time values and also to support time expressions for selection criteria (the -S/--select option).

Currently, there's only one reporting field which displays time. Before these changes, it was internally represented as string value only which did not allow more advanced matching when such field was used in selection criteria. Before, either the whole string matched or it matched regex. Also we couldn't define time in more natural way (e.g. yesterday, 3 weeks ago...) and we couldn't define time ranges.

We have extended support for time values in reporting and selection code so time is now properly recognized. For better readability of selection expressions, we have also added aliases for comparison operators that can be used with time values:

  "since" as an alias for ">="
  "after" as an alias for ">"
  "until" as an alias for "<="
  "before" as an alias for "<"

There are two basic ways how to define time so that LVM recognizes it:

===

A) Subset of strict stanardized format (subset of ISO 8601) which is directly recognized in libdevmapper for new DM_REPORT_FIELD_TYPE_TIME type:

date time timezone

date:
  YYYY-MM-DD (or shortly YYYYMMDD)
  YYYY-MM (shortly YYYYMM), auto DD=1
  YYYY, auto MM=01 and DD=01

time:
  hh:mm:ss (or shortly hhmmss)
  hh:mm (or shortly hhmm), auto ss=0
  hh (or shortly hh), auto mm=0, auto ss=0

  timezone (always with + or - sign):
  +hh:mm or -hh:mm (or shortly +hhmm or -hhmm)
  +hh or -hh
  (No support for timezone names here as they may be ambiguous!)

Note:
The full date/time specification is YYYY-MM-DD hh:mm:ss. Users are able to leave date/time parts from right to left. Whenever these parts are left out, a range is assumed automatically with second granularity. For example:

  "2015-07-07 9:51" means range of "2015-07-07 9:51:00" - "2015-07-07 9:51:59"
  "2015-07" means range of "2015-07-01 0:00:00" - "2015-07-31 23:59:59"
  "2015" means range of "2015-01-01 0:00:00" - "2015-12-31 23:59:59"
  ...

When used in selection criteria:
  lvs -S 'time since "2015-07-07 9:51"'
  lvs -S 'time = "2015-07""
  lvs -S 'time = "2015"'
  ...

===

B) An extension for date/time recognition (currently for the lv_time field only) which allows more free-form specification and it can be combined with these entities:

  - weekday names ("Sunday" - "Saturday" or abbreviated as "Sun" - "Sat")
  - labels for points in time ("noon", "midnight")
  - labels for a day relative to current day ("today", "yesterday")
  - points back in time with relative offset from today (N is a number)
    ( "N" "seconds"/"minutes"/"hours"/"days"/"weeks"/"years" "ago")
    ( "N" "secs"/"mins"/"hrs" ... "ago")
    ( "N" "s"/"m"/"h" ... "ago")
  - time specification either in hh:mm:ss format or with AM/PM suffixes
  - month names ("January" - "December" or abbreviated as "Jan" - "Dec")

For example:
   lvs -S 'time since "yesterday 9AM"'
   lvs -S 'time since "Feb 3 years 2 months ago"'
   lvs -S 'time = "February 2015"'
   lvs -S 'time since "Jan 15 2015" && time until yesterday'
   lvs -S 'time since "today 6AM"'
   ...and lots of other combinations from the set above (LVM will error out with a proper error message pointing to the problematic part if time was not recognized properly or if it finds the time expression ambiguous).

=======


We have also provided new report/time_format lvm.conf option with which it's possible to define the way the time is displayed for time reporting fields. The format is described in lvm.conf comments (it's actually a restricted subset of formatting sequences which is also known from strftime function [man 3 strftime] and date command [man 1 date]).

For example:
  $ lvmconfig --type full report/time_format
  time_format="%a %Y-%m-%d %T %z %Z [%s]"

  $lvs -o name,time vg/lvol1
  LV    Time                                           
  lvol1 Tue 2015-07-07 09:25:24 +0200 CEST [1436253924]

Comment 7 errata-xmlrpc 2015-11-19 12:46:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2147.html