This script demonstrates how to use a scheduled look to provide parameter option values to a Google Cloud Function, which will automatically maintain corresponding parameter option values specified in a LookML file.
- In a file in your LookML project, annotate the parameter options you want to maintain automatically by inserting a
# BEGIN AUTO-GENERATED PARAMETER VALUES
comment immediately before the parameter option values and an# END AUTO-GENERATED PARAMETER VALUES
comment immediately afterwards. See testfile.view.lkml for an example. - Save a look that returns two columns containing the data you want to use for parameter option labels and values. In this example, the look contains two columns, Event Name and Event ID.
- Clone this repository and set your own parameter values in env.yaml. You will need a Github API token that has permission to make changes to the repository containing your LookML files, and the Outgoing Webhook Token from your Looker instance.
- Create a GCP project and configure the gcloud command line utility by following the Quickstart instructions
- Deploy the function with
gcloud
(run this command in the directory containing the files from this repository)gcloud functions deploy lookml_parameter_option_generator --runtime python37 --trigger-http --env-vars-file env.yaml
- Schedule your previously saved look to provide results via webhook every five minutes, and only if the results have changed. Select "Webhook" in the "Where should this data go?" section of the Schedule Events modal, then enter the URL for your Google Cloud Function. Choose "JSON - Simple" in the "Format data as" section.
Example Webhook URL: https://us-central1-maintain-lookml-parameter.cloudfunctions.net/lookml_parameter_option_generator?filename=testfile&project_id=looker (replace
testfile
with the LookML filename that contains the parameter you want to maintain automatically, and replacelooker
with a project_id specified in your env.yaml file) - Click "Send Test" to make a request to your Google Cloud Function immediately
- Get function execution logs with
gcloud
gcloud functions logs read
When a new row is included in the results from the scheduled look, a new option for the related LookML parameter will be automatically written into the LookML file. In this example, if the scheduled look's results include a new row with Seventy Seven in the Event Name field and 77 in the Event ID field, the following option will be automatically added to the parameter in testfile.view.lkml:
allowed_value: {
label: "Seventy Seven"
value: "77"
}
Any existing options will be updated, because every allowed_value between the beginning and ending comments is rewritten each time for every row sent by the scheduled look.