Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "SHOW RESOURCE MONITORS" #8

Merged
merged 9 commits into from
May 19, 2022

Conversation

paulsewardasc
Copy link
Contributor

@paulsewardasc paulsewardasc commented May 12, 2022

Example query results

Results
select
  name,
  credit_quota,
  used_credits,
  remaining_credits
from
  snowflake_resource_monitor;
+--------------------------------+--------------+--------------+-------------------+
| name                           | credit_quota | used_credits | remaining_credits |
+--------------------------------+--------------+--------------+-------------------+
| WAREHOUSE SEARCH               | 10           | 0            | 10                |
| TEST_LARGE                     | 5            | 0            | 5                 |
| ABC_MEDIUM                     | 25           | 0.57         | 24.43             |
+--------------------------------+--------------+--------------+-------------------+


select account,
    name as warehouse,
    credit_quota,
    used_credits,
    remaining_credits,
    round(cast(used_credits/credit_quota*100 as numeric), 1) as "% Used",
    case
        when used_credits/credit_quota*100 > 90 then 'alert'
        when used_credits/credit_quota*100 > 75 then 'warning'
        else 'ok'
    end as type
from snowflake_resource_monitor
where used_credits/credit_quota*100 > 75
order by used_credits/credit_quota desc
+--------------+----------------------------+--------------+--------------+-------------------+--------+---------+
| account      | warehouse                  | credit_quota | used_credits | remaining_credits | % Used | type    |
+--------------+----------------------------+--------------+--------------+-------------------+--------+---------+
| acount1      | WAREHOUSE1                 | 7            | 8.54         | -1.54             | 122.0  | alert   |
| acount1      | WAREHOUSE2                 | 13           | 15.62        | -2.62             | 120.2  | alert   |
| acount1      | WAREHOUSE3                 | 300          | 270.58       | 29.42             | 90.2   | alert   |
| acount1      | WAREHOUSE TEST             | 578          | 451.98       | 126.02            | 78.2   | warning |
+--------------+----------------------------+--------------+--------------+-------------------+--------+---------+

select
  name,
  notify_at, 
  suspend_at, 
  suspend_immediately_at
from
  snowflake_resource_monitor
+-----------------+------------------+------------+------------------------+
| name            | notify_at        | suspend_at | suspend_immediately_at |
+-----------------+------------------+------------+------------------------+
| WAREHOUSE1121   | 100%,50%,75%,90% | <null>     | <null>                 |
| WAREHOUSE TEST  | 25%,50%,75%      | <null>     | <null>                 |
| DATA WH001      | 100%,50%         | <null>     | <null>                 |
| SEARCH          | 100%,25%,75%,90% | 90%        | 100%                   |
+-----------------+------------------+------------+------------------------+

@rajlearner17
Copy link

@paulsewardasc Awesome to see this PR. Thank you 👍
We will review it and get back to you as needed.

Copy link
Contributor

@cbruno10 cbruno10 left a comment

Choose a reason for hiding this comment

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

Hey @paulsewardasc , thanks for working on adding this table and opening a PR!

I've added some comments and suggestions, can you please have a look at them when you get a chance? If you have any questions, please let me know!

README.md Outdated
@@ -31,7 +31,32 @@ where
(last_success_login > now() - interval '30 days')
and last_success_login is not null;
```
## Examples
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding examples here, can you please create a new table document, e.g., https://github.com/turbot/steampipe-plugin-snowflake/blob/main/docs/tables/snowflake_database.md? These docs are helpful as they show up on https://hub.steampipe.io/plugins/turbot/snowflake/tables.

Also, for the examples, can you please follow our standard formatting as per Table Documentation Standards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulsewardasc Did you push up the new commit yet? I don't see it in the Commits list yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is here, do I need to do something else? It may not have been here last night.

https://github.com/paulsewardasc/steampipe-plugin-snowflake/tree/resource_monitors

return nil, nil
}

func ScanResourceMonitor(row *sqlx.Row) (*ResourceMonitor, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function used anywhere? If not, can you please remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed


type ResourceMonitor struct {
Name sql.NullString `json:"name" db:"name"`
CreditQuota sql.NullString `json:"credit_quota" db:"credit_quota"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of the formatting looks a bit off here, can you please run gofmt -w <filename> to update the file to use the standard Go formatting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

{Name: "frequency", Type: proto.ColumnType_STRING, Description: "Daily, Weekly, etc"},
{Name: "start_time", Type: proto.ColumnType_TIMESTAMP, Description: "Date and time when the monitor was started."},
{Name: "end_time", Type: proto.ColumnType_TIMESTAMP, Description: "Date and time when the monitor was stopped."},
{Name: "notify_at", Type: proto.ColumnType_STRING, Description: "Levels to which to alert"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{Name: "notify_at", Type: proto.ColumnType_STRING, Description: "Levels to which to alert"},
{Name: "notify_at", Type: proto.ColumnType_STRING, Description: "Levels to which to alert."},

Please see Table and Column Descriptions for more information on formatting descriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


func tableSnowflakeResourceMonitor(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "snowflake_resource_monitors",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Name: "snowflake_resource_monitors",
Name: "snowflake_resource_monitor",

Can you please make the table name singular?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done although the command run is "SHOW RESOURCE MONITORS"

snowflake/table_snowflake_resource_monitor.go Show resolved Hide resolved
EndTime sql.NullTime `json:"end_time" db:"end_time"`
NotifyAt sql.NullString `json:"notify_at" db:"notify_at"`
SuspendAt sql.NullString `json:"suspend_at" db:"suspend_at"`
SuspendImdAt sql.NullString `json:"suspend_immediately_at" db:"suspend_immediately_at"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SuspendImdAt sql.NullString `json:"suspend_immediately_at" db:"suspend_immediately_at"`
SuspendImmediatelyAt sql.NullString `json:"suspend_immediately_at" db:"suspend_immediately_at"`

We prefer to use full names (even if they're a bit long) so there's no ambiguity and all names are consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

logger := plugin.Logger(ctx)
db, err := connect(ctx, d)
if err != nil {
logger.Error("snowflake_warehouse.listSnowflakeResourceMonitors", "connnection.error", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.Error("snowflake_warehouse.listSnowflakeResourceMonitors", "connnection.error", err)
logger.Error("snowflake_resource_monitor.listSnowflakeResourceMonitors", "connnection.error", err)

Can you please fix other logging statements like this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
defer rows.Close()

dbs := []ResourceMonitor{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dbs := []ResourceMonitor{}
resourceMonitors := []ResourceMonitor{}

We should match the variable name more closely with what we're retrieving

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@cbruno10 cbruno10 left a comment

Choose a reason for hiding this comment

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

@paulsewardasc Thanks for making the updates quickly! I've added a few more suggestions/comments, but I believe these should be the latest round of suggestions.

Can you please have a look when you get a chance? If you have any questions, please let me know.

snowflake/plugin.go Outdated Show resolved Hide resolved
snowflake/table_snowflake_resource_monitor.go Outdated Show resolved Hide resolved
snowflake/table_snowflake_resource_monitor.go Outdated Show resolved Hide resolved
snowflake/table_snowflake_resource_monitor.go Outdated Show resolved Hide resolved
{Name: "end_time", Type: proto.ColumnType_TIMESTAMP, Description: "Date and time when the monitor was stopped."},
{Name: "notify_at", Type: proto.ColumnType_STRING, Description: "Levels to which to alert."},
{Name: "suspend_at", Type: proto.ColumnType_STRING, Description: "Levels to which to suspend warehouse"},
{Name: "suspend_immediately_at", Type: proto.ColumnType_STRING, Description: "Levels to which to suspend warehouse"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this column's value ever have more than 1 level at which the warehouse will be suspended? If so, is it a comma delimited list (or a list with another delimiter)? Going off of the description, it seems like we could expect more than 1 level.

Do you have a link to where you pulled this description from? That may be helpful for me to compare the current descriptions vs. what the docs/other sources mention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This column can have 1 or more values, having problems compiling the code at the moment, the function keeps show the show warehouse schema

Copy link
Contributor

Choose a reason for hiding this comment

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

@paulsewardasc Are you still having troubles compiling the plugin? Please let me know here or over Slack if there's anything I can help with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it, the plugin.go file was wrong!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The credit_quota is defined in snowflake as a variant data type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The remaining_credits is defined as a float and suspend is a NUMBER(38,0) is that helps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

READER_ACCOUNT_NAME VARCHAR(16777216)
NAME VARCHAR(16777216)
CREATED TIMESTAMP_LTZ(6)
CREDIT_QUOTA VARIANT
USED_CREDITS VARIANT
REMAINING_CREDITS FLOAT
OWNER VARCHAR(16777216)
WAREHOUSES VARCHAR(16777216)
NOTIFY NUMBER(38,0)
SUSPEND NUMBER(38,0)
SUSPEND_IMMEDIATE NUMBER(38,0)
LEVEL VARCHAR(9)
READER_ACCOUNT_DELETED_ON TIMESTAMP_LTZ(6)

Copy link
Contributor

Choose a reason for hiding this comment

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

For the credit_quota column, I think OK to leave as a double. In the example query results you added, they appear to be integers instead of doubles, but if there's a possibility there's precision as per https://docs.snowflake.com/en/sql-reference/data-types-numeric.html#number, then double is correct.

For notfiy_at, suspend_at, and suspend_at_immediately, do you have example query results that include single value and multi-value rows? I'd be curious to see how the data looks since the column types are currently marked as STRING, but if there can be multiple values, should the column types be JSON instead (which handles arrays)?

docs/tables/snowflake_resource_monitor.md Show resolved Hide resolved
docs/tables/snowflake_resource_monitor.md Outdated Show resolved Hide resolved
docs/tables/snowflake_resource_monitor.md Show resolved Hide resolved
@cbruno10
Copy link
Contributor

Hey @paulsewardasc , thanks for the quick updates a few days ago! I believe the last set of questions I have before I'm ready to approve is mentioned in #8 (comment), when you get a chance can you please have a look? If there's anything I can expand on, please let me know. Thanks!

@paulsewardasc
Copy link
Contributor Author

Hey @paulsewardasc , thanks for the quick updates a few days ago! I believe the last set of questions I have before I'm ready to approve is mentioned in #8 (comment), when you get a chance can you please have a look? If there's anything I can expand on, please let me know. Thanks!

Hi, I am not sure what I need to do, I have added an example.

@cbruno10
Copy link
Contributor

@paulsewardasc Sorry about that, I didn't realize you updated the PR comment/description with a new example showing those columns, I was originally looking in the review comment chain where I asked for the examples.

Based on the examples, the column type STRING makes sense.

@cbruno10 cbruno10 merged commit cf12688 into turbot:main May 19, 2022
@cbruno10
Copy link
Contributor

@paulsewardasc Thanks for creating the PR and working through the various reviews! We really appreciate the contribution and plan to release a new version of this plugin this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants