-
Notifications
You must be signed in to change notification settings - Fork 41
Expose GOVUK_DATA_SYNC_PERIOD ENV variable for govuk_app_config #10770
Conversation
e6da4e4
to
c8573ac
Compare
This is to enable alphagov/govuk_app_config#160, which ignores certain exceptions if they occur during the data sync period. We want to set this via Puppet so that it is configured in only one repo. In the next commit I will DRY up the values so that they're only set in one place, but for now, there is precedent for duplicating the values - see /~https://github.com/alphagov/govuk-puppet/blob/5b1dc13ea3c7180318da284fe1dbe90a14460234/modules/monitoring/manifests/contacts.pp#L57-L59 We only want to define GOVUK_DATA_SYNC_PERIOD on Integration and Staging. If we hit an error on Production during the data sync period, we still want to log it to Sentry. Trello: https://trello.com/c/rAlvGlSp/2123-5-ignore-data-sync-errors-in-govukappconfig
c8573ac
to
198d072
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks neat Chris. I've a few minor comments on the function but approach seems sound.
module Puppet::Parser::Functions | ||
newfunction(:data_sync_times, :type => :rvalue, :doc => <<-EOS | ||
Return information about the data sync times, depending on the argument passed | ||
EOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh this is exotic, I've never seen a puppet function definition before. It seems a neat solution to the problem 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took inspiration from other functions we have in govuk-puppet, after initially trying (and failing) to define the start/finish times in YAML. Could have pursued YAML further but as we sometimes need the raw values and sometimes need a representation of them, seemed just as clean to put them in here. 👍
@@ -0,0 +1,38 @@ | |||
module Puppet::Parser::Functions | |||
newfunction(:data_sync_times, :type => :rvalue, :doc => <<-EOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you want to name this as format_data_sync_time
since the primary role of the function is the formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function returns values and doesn't change anything, I'd probably avoid the use of a verb like "format" in its name. Calling it format_data_sync_time
makes it sound like it's either editing something somewhere or returning edited versions of passed arguments. I think data_sync_times
is accurate for what it does: returning appropriate data sync time values based on the argument passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with Alan here 👍
f6daa94
to
6f9fbd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I just left a small suggestion (not a blocker!)
These values are beginning to leak into multiple places. It is good maintenance practice to try to keep them in one place. There is probably a cleaner way of doing this with YML config, but given that some places need the start/end times and others need specifically the start/end hour and minute, a function seems a reasonable thing to create to encapsulate all that knowledge. In any case, it is an improvement on trying to duplicate the values throughout the repository.
a6681b3
to
45fa8c2
Compare
@@ -127,6 +127,12 @@ | |||
'GOVUK_CSP_REPORT_URI': value => $csp_report_uri; | |||
} | |||
|
|||
if $::aws_migration and ($::aws_environment != 'production') { | |||
govuk_envvar { | |||
'GOVUK_DATA_SYNC_PERIOD': value => data_sync_times('time_range'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this does seem to be setting it (don't worry about the lack of leading zeros - Time.parse
still parses them fine):
$ more /etc/govuk/env.d/GOVUK_DATA_SYNC_PERIOD
22:0-8:0
But if I echo $GOVUK_DATA_SYNC_PERIOD
I get nothing. Do we know how/whether these variables get exported as traditional ENV vars @kevindew ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure exactly how they work - I think the govuk_setenv command sets them:
kevindew@ec2-integration-blue-email_alert_api-ip-10-1-6-234:~$ govuk_setenv email-alert-api env | grep GOVUK_DATA_SYNC_PERIOD
GOVUK_DATA_SYNC_PERIOD=22:0-8:0
You can see the env var if you go into an app console. For example Email Alert API on integration:
irb(main):002:0> ENV["GOVUK_DATA_SYNC_PERIOD"]
=> "22:0-8:0"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a relief - thanks for confirming!
This is to enable alphagov/govuk_app_config#160,
which ignores certain exceptions if they occur during the data
sync period. We want to set this via Puppet so that it is DRY and
configured in only one place.
Trello: https://trello.com/c/rAlvGlSp/2123-5-ignore-data-sync-errors-in-govukappconfig