跳转到主要内容

一个Looker清理工具

项目描述

image


Henry:一个Looker清理工具

Henry是一个命令行工具,帮助您确定Looker实例中的模型膨胀并识别模型和探索中未使用的功能。它旨在帮助开发人员从未使用的探索中清理模型,从未使用的连接和字段中清理探索,以及维护一个健康、友好的实例。

目录

状态和支持

Henry在任何方面都未经Looker支持或保证。请勿联系Looker支持解决Henry的问题。问题可以通过https://github.com/looker-open-source/henry/issues记录

安装

Henry需要python3.7+。它发布在PyPI上,可以使用pip安装

$ pip install henry

为了开发设置,请遵循下面的开发设置

使用

为了显示使用信息,请使用

$ henry --help

适用于许多命令的全局选项

身份验证

Henry使用Looker SDK发出API调用,并需要API3凭证。这些凭证可以通过.ini文件或环境变量提供,如在此处记录所示。默认情况下,该工具在工作目录中查找名为"looker.ini"的文件。如果配置文件的名称不同或位于其他位置,则必须使用--config-file参数指定。

示例.ini文件

[Looker]
# Base URL for API. Do not include /api/* in the url
base_url=https://self-signed.looker.com:19999
# API 3 client id
client_id=YourClientID
# API 3 client secret
client_secret=YourClientSecret
# Set to false if testing locally against self-signed certs. Otherwise leave True
verify_ssl=True

[Production]
base_url=https://production.looker.com:19999
client_id=YourClientID
client_secret=YourClientSecret
verify_ssl=True

假设以上ini文件内容,可以按照以下方式运行Henry:

$ henry pulse --config-file=looker.ini --section=Looker

由于默认设置,这相当于:

$ henry pulse

使用“生产”部分下的详细信息运行它,可以按照以下方式:

$ henry pulse --section=Production

API超时设置

默认情况下,API调用超时时间为120秒。可以使用--timeout参数来覆盖。

输出到文件

如果使用--save标志,则工具会将结果保存到您的当前工作目录。示例用法

$ henry vacuum models --save

将结果保存到当前工作目录中的vacuum_models_{date}_{time}.csv

Pulse命令

命令henry pulse运行一系列测试,有助于确定实例的整体健康状况。

分析命令

命令analyze旨在帮助识别变得臃肿的模型和探索,并使用vacuum对其进行修剪。

分析项目

命令analyze projects扫描项目内容,并检查成功所需的基本功能的状态,如git连接状态和验证要求。

+-------------------+---------------+--------------+-------------------------+---------------------+------------------------+
| Project           |  # Models     | # View Files | Git Connection Status   | PR Mode             | Is Validation Required |
|-------------------+---------------+--------------+-------------------------+---------------------+------------------------|
| marketing         |       1       |      13      | OK                      | links               | True                   |
| admin             |       2       |      74      | OK                      | off                 | True                   |
| powered_by_looker |       1       |      14      | OK                      | links               | True                   |
| salesforce        |       1       |      36      | OK                      | required            | False                  |
| thelook_event     |       1       |      17      | OK                      | required            | True                   |
+-------------------+---------------+--------------+-------------------------+---------------------+------------------------+

分析模型

显示每个模型中的探索数量以及针对该模型查询的数量。

+-------------------+------------------+-----------------+-------------------+-------------------+
| Project           | Model            |  # Explores     | # Unused Explores |    Query Count    |
|-------------------+------------------+-----------------+-------------------+-------------------|
| salesforce        | salesforce       |        8        |         0         |       39923       |
| thelook_event     | thelook          |       10        |         0         |      166307       |
| powered_by_looker | powered_by       |        5        |         0         |       49122       |
| marketing         | thelook_adwords  |        3        |         0         |       40869       |
| admin             | looker_base      |        0        |         0         |         0         |
| admin             | looker_on_looker |       10        |         9         |        28         |
+-------------------+------------------+-----------------+-------------------+-------------------+

分析探索

显示探索及其使用情况。如果传递了--min-queries参数,则使用阈值以下的使用次数的连接和字段将被视为未使用。

+---------+-----------------------------------------+-------------+-------------------+--------------+----------------+---------------+-----------------+---------------+
| Model   | Explore                                 | Is Hidden   | Has Description   |   # Joins    | # Unused Joins |    # Fields   | # Unused Fields |  Query Count  |
|---------+-----------------------------------------+-------------+-------------------+--------------+----------------+---------------+-----------------+---------------|
| thelook | cohorts                                 | True        | False             |      3       |       0        |      19       |        4        |      333      |
| thelook | data_tool                               | True        | False             |      3       |       0        |      111      |       90        |      736      |
| thelook | order_items                             | False       | True              |      7       |       0        |      153      |       16        |    126898     |
| thelook | events                                  | False       | True              |      6       |       0        |      167      |       68        |     19372     |
| thelook | sessions                                | False       | False             |      6       |       0        |      167      |       83        |     12205     |
| thelook | affinity                                | False       | False             |      2       |       0        |      34       |       13        |     3179      |
| thelook | orders_with_share_of_wallet_application | False       | True              |      9       |       0        |      161      |       140       |     1586      |
| thelook | journey_mapping                         | False       | False             |      11      |       2        |      238      |       228       |      14       |
| thelook | inventory_snapshot                      | False       | False             |      3       |       0        |      25       |       15        |      33       |
| thelook | kitten_order_items                      | True        | False             |      8       |       0        |      154      |       138       |      39       |
+---------+-----------------------------------------+-------------+-------------------+--------------+----------------+---------------+-----------------+---------------+

真空信息

命令vacuum根据预定义的准则输出未使用的内容,开发人员可以使用这些内容来清理模型和探索。

真空模型

命令vacuum models公开模型及其查询数量,时间跨度预设。列出的探索在该时间段内没有达到最低查询次数。因此,可以安全地隐藏它们并在以后删除。

+------------------+---------------------------------------------+-------------------------+
| Model            | Explore                                     |     Model Query Count   |
|------------------+---------------------------------------------+-------------------------|
| salesforce       |                                             |          39450          |
| thelook          |                                             |         164930          |
| powered_by       |                                             |          49453          |
| thelook_adwords  |                                             |          38108          |
| looker_on_looker | user_full                                   |           27            |
|                  | history_full                                |                         |
|                  | content_view                                |                         |
|                  | project_status                              |                         |
|                  | field_usage_full                            |                         |
|                  | dashboard_performance_full                  |                         |
|                  | user_weekly_app_activity_period_over_period |                         |
|                  | pdt_state                                   |                         |
|                  | user_daily_query_activity                   |                         |
+------------------+---------------------------------------------+-------------------------+

真空探索

命令vacuum explores公开在指定时间段内查询次数低于或等于最小查询次数阈值的连接和字段(默认=0,可以使用--min-queries参数更改)。默认时间范围是90天,可以使用--timeframe参数更改。

例如:从上面的分析函数运行上述,我们知道cohorts探索有4个字段在过去的90天内一次都没有被查询过。运行以下真空命令

$ henry vacuum explores --model thelook --explore cohorts

提供了未使用字段的名称

+---------+-----------+----------------+------------------------------+
| Model   | Explore   | Unused Joins   | Unused Fields                |
|---------+-----------+----------------+------------------------------|
| thelook | cohorts   | users          | users.id                     |
|         |           |                | order_items.id               |
|         |           |                | order_items.id               |
|         |           |                | order_items.total_sale_price |
+---------+-----------+----------------+------------------------------+

如果连接未使用,这意味着该连接引入的字段在定义的时间框架内没有被使用。因此,作为该连接结果公开的字段不会明确列出为未使用字段。

非常重要的一点是要注意,在某个探索中列为未使用的字段并不意味着要从视图中完全删除,因为它们可能在其他探索(通过扩展)或过滤器中使用。相反,应该隐藏这些字段(如果它们在别处没有被使用),或者使用fields LookML参数从探索中排除它们。

贡献

请参阅CONTRIBUTING文件。欢迎在GitHub上提交错误报告和拉取请求:https://github.com/looker-open-source/henry/issues

行为准则

预期与Henry项目的代码库、问题跟踪器、聊天室和邮件列表互动的所有人都应遵循行为准则

版权

版权(c)2018 Joseph Axisa,Looker Data Sciences。有关更多信息,请参阅MIT许可证

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源代码分发

henry-temp-fix-1.1.2.tar.gz (19.3 kB 查看哈希值)

上传时间 源代码

构建分发

henry_temp_fix-1.1.2-py3-none-any.whl (19.4 kB 查看哈希值)

上传时间 Python 3

支持者