Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

ci/maintenance: Add more date formats to filter when using grafiti to clean aws resources #1890

Merged
merged 1 commit into from
Sep 12, 2017

Conversation

cpanato
Copy link
Contributor

@cpanato cpanato commented Sep 12, 2017

No description provided.

@cpanato cpanato force-pushed the add_more_date_formats branch from 2b373db to 3995263 Compare September 12, 2017 14:41
Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Grafiti actually support all these date formats?

@cpanato
Copy link
Contributor Author

cpanato commented Sep 12, 2017

my understanding of grafiti is it takes the tag you defined to use when deleting resources and match if the tag in the resource.
I added this others formats because I saw some resources in our AWS account with that format in the tag, and then when grafiti run will not delete those because does not match with the filter.

I ran one grafiti delete using this config and at least it not break anything :)

@squat

Copy link
Contributor

@squat squat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be throwing all of these dates at Grafiti. We should pick ONE that works and use it. This is confusing and highlights our uncertainty in our own tool. If we need to fix Grafiti to be consistent then we should do that in the Grafiti repo.

@cpanato
Copy link
Contributor Author

cpanato commented Sep 12, 2017

@squat grafiti is consistent in tagging the resources. What I saw in AWS was other users tagging the expirationDate with other formats like the one I added. eg. M-D-Y

@squat
Copy link
Contributor

squat commented Sep 12, 2017

Sure, the questions is: can Grafiti interpret all of these expiration date formats? My suspicion is "no".

@cpanato
Copy link
Contributor Author

cpanato commented Sep 12, 2017

@squat I ran this in one region which I I had free tier machines and each of one had this specific date format in the expirationDate tag and grafiti delete all machines.
I will send thru slack the log from the execution.

@squat
Copy link
Contributor

squat commented Sep 12, 2017

Ok, sorry I misunderstood how we were leveraging this date in Grafiti. This tag has no special meaning, e.g. time, in Grafiti other than being a string. We are just using this as the set of strings to select resources to delete.

@cpanato
Copy link
Contributor Author

cpanato commented Sep 12, 2017

thanks! also was good because I did a real testing :)

@cpanato cpanato merged commit c140a1d into coreos:master Sep 12, 2017
@cpanato cpanato deleted the add_more_date_formats branch September 12, 2017 16:48
wking added a commit to wking/openshift-installer that referenced this pull request Jul 27, 2018
tag-aws.sh is using grafiti, whose tagPatterns takes jq expressions
[1].  We've been using strftime since the script landed in 82bdd9f
(installer/scripts: AWS tag and delete scripts, 2017-06-28,
coreos/tectonic-installer#1239).  jq's strftime doesn't respect your
configured $TZ, but the coming jq 1.6 will add strflocaltime which
does [2,3].  jq uses seconds since the epoch for date-time values [4].
You can test the new construct with:

  $ jq --null-input --raw-output 'now + 24*60*60 | strftime("%Y-%m-%d")'
  2018-07-27

-d is not part of the POSIX date specification [5], but it (and the
'tomorrow' value) are supported by GNU Coreutils [6,7].  We've been
using -d in clean-aws.sh for a while now, so this is now a new
dependency.

I've also dropped date_override, since we can just set date_string
directly.  And I've shuffled around some of the conditionals to avoid
calling the 'date' and 'jq' commands needlessly when --date-override
is set.

I've also replaced the multiple date calls in clean-aws.sh with a
single call to jq.  jq was already a required dependency for this
script, and only needing a single child process is much faster:

  $ time for i in $(seq 100); do A="$(jq --null-input '[["%Y-%m-%d", "%Y-%-m-%-d", "%m-%d-%Y", "%m-%-d-%-Y", "%-m-%-d-%-Y", "%d-%m-%Y", "%d-%-m-%-Y"][] | . as $format | [now, now - 24*60*60][] | strftime($format)]')"; done

  real   0m0.256s
  user   0m0.186s
  sys    0m0.077s
  $ time for i in $(seq 100); do A="$(date "+%Y-%m-%d" -d "-1 day")\",\"$(date "+%Y-%-m-%-d" -d "-1 day")\",\"$(date "+%m-%-d-%-Y" -d "-1 day")\",\"$(date "+%-m-%-d-%-Y" -d "-1 day")\",\"$(date "+%d-%m-%-Y" -d "-1 day")\",\"$(date "+%d-%-m-%-Y" -d "-1 day")\",\"$(date +%m-%d-%Y)\",\"$(date +%d-%m-%Y)\",\"$(date +%d-%-m-%Y)\",\"$(date +%Y-%m-%d)\",\"$(date +%Y-%-m-%-d)"; done

  real   0m1.358s
  user   0m0.604s
  sys    0m0.832s

And that's despite the fact that the old approach skipped some formats
for today (e.g. %m-%-d-%-Y had been only used to format yesterday).

The plethora of date formats are mostly from 3995263 (ci: add more
date format when grafiti apply the cleanning, 2017-09-12,
coreos/tectonic-installer#1890), although we've had some since
82bdd9f.  The motivation seems to be matching human-generated tags
[8], which are less reliably formatted.

[1]: https://github.com/coreos/grafiti/blob/89a8bc92ad7fde49cd3dd78197c6b3616a857f36/README.md#configure-grafiti
[2]: https://github.com/stedolan/jq/wiki/FAQ
[3]: jqlang/jq@06f2060
[4]: https://stedolan.github.io/jq/manual/v1.5/#Dates
[5]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html
[6]: https://www.gnu.org/software/coreutils/manual/html_node/Options-for-date.html
[7]: https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html
[8]: coreos/tectonic-installer#1890 (comment)
frobware pushed a commit to frobware/installer that referenced this pull request Sep 17, 2018
tag-aws.sh is using grafiti, whose tagPatterns takes jq expressions
[1].  We've been using strftime since the script landed in 82bdd9f
(installer/scripts: AWS tag and delete scripts, 2017-06-28,
coreos/tectonic-installer#1239).  jq's strftime doesn't respect your
configured $TZ, but the coming jq 1.6 will add strflocaltime which
does [2,3].  jq uses seconds since the epoch for date-time values [4].
You can test the new construct with:

  $ jq --null-input --raw-output 'now + 24*60*60 | strftime("%Y-%m-%d")'
  2018-07-27

-d is not part of the POSIX date specification [5], but it (and the
'tomorrow' value) are supported by GNU Coreutils [6,7].  We've been
using -d in clean-aws.sh for a while now, so this is now a new
dependency.

I've also dropped date_override, since we can just set date_string
directly.  And I've shuffled around some of the conditionals to avoid
calling the 'date' and 'jq' commands needlessly when --date-override
is set.

I've also replaced the multiple date calls in clean-aws.sh with a
single call to jq.  jq was already a required dependency for this
script, and only needing a single child process is much faster:

  $ time for i in $(seq 100); do A="$(jq --null-input '[["%Y-%m-%d", "%Y-%-m-%-d", "%m-%d-%Y", "%m-%-d-%-Y", "%-m-%-d-%-Y", "%d-%m-%Y", "%d-%-m-%-Y"][] | . as $format | [now, now - 24*60*60][] | strftime($format)]')"; done

  real   0m0.256s
  user   0m0.186s
  sys    0m0.077s
  $ time for i in $(seq 100); do A="$(date "+%Y-%m-%d" -d "-1 day")\",\"$(date "+%Y-%-m-%-d" -d "-1 day")\",\"$(date "+%m-%-d-%-Y" -d "-1 day")\",\"$(date "+%-m-%-d-%-Y" -d "-1 day")\",\"$(date "+%d-%m-%-Y" -d "-1 day")\",\"$(date "+%d-%-m-%-Y" -d "-1 day")\",\"$(date +%m-%d-%Y)\",\"$(date +%d-%m-%Y)\",\"$(date +%d-%-m-%Y)\",\"$(date +%Y-%m-%d)\",\"$(date +%Y-%-m-%-d)"; done

  real   0m1.358s
  user   0m0.604s
  sys    0m0.832s

And that's despite the fact that the old approach skipped some formats
for today (e.g. %m-%-d-%-Y had been only used to format yesterday).

The plethora of date formats are mostly from 3995263 (ci: add more
date format when grafiti apply the cleanning, 2017-09-12,
coreos/tectonic-installer#1890), although we've had some since
82bdd9f.  The motivation seems to be matching human-generated tags
[8], which are less reliably formatted.

[1]: https://github.com/coreos/grafiti/blob/89a8bc92ad7fde49cd3dd78197c6b3616a857f36/README.md#configure-grafiti
[2]: https://github.com/stedolan/jq/wiki/FAQ
[3]: jqlang/jq@06f2060
[4]: https://stedolan.github.io/jq/manual/v1.5/#Dates
[5]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html
[6]: https://www.gnu.org/software/coreutils/manual/html_node/Options-for-date.html
[7]: https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html
[8]: coreos/tectonic-installer#1890 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants