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

POL-1405 Replace deprecated Kubecost endpoints for Kubecost Cluster Policy #2833

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

midir99
Copy link
Contributor

@midir99 midir99 commented Nov 14, 2024

Description

The endpoint we are currently using has been deprecated “/model/savings/clusterSizing"
It still works but only returns one cluster rather than all clusters.

The new endpoint is returns a different response “/model/savings/clusterSizingETL" and simply adding ETL onto the end of our current end point in the policy returns null values in ds_cluster_sizing

This endpoint returns all cluster recommendations in one response.

Issues Resolved

Link to Example Applied Policy

https://app.flexeratest.com/orgs/1105/automation/applied-policies/projects/60073?policyId=673520d66168ce351f89f548

Contribution Check List

  • New functionality includes testing.
  • New functionality has been documented in the README if applicable
  • New functionality has been documented in CHANGELOG.MD

Copy link
Contributor

github-actions bot commented Nov 14, 2024

2 Errors
🚫

cost/kubecost/cluster/CHANGELOG.md

Markdown syntax errors found:

cost/kubecost/cluster/CHANGELOG.md:8: MD012 Multiple consecutive blank lines

Further documentation is available for these failures:

  • MD012: https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md#md012—multiple-consecutive-blank-lines
🚫

cost/kubecost/cluster/kubecost_cluster_rightsizing_recommendations.pt

Version number in policy template does not match latest version number in CHANGELOG.md. Please review both files to make sure they are correct and aligned with each other.


Policy Template has consecutive empty lines. Code blocks and other code constructs should never be separated by more than one empty line:

Line 54


Orphaned script code blocks found. Blocks that are not used anywhere in the policy should be removed:

js_get_cluster_list


parameter code blocks found with out of order fields.
Fields should be in the following order: type, category, label, description, allowed_values, allowed_pattern, min_value, max_value, default

Line 39: parameter "param_allow_shared_core"
Line 47: parameter "param_include_overhead"

1 Warning
⚠️

cost/kubecost/cluster/kubecost_cluster_rightsizing_recommendations.pt

Policy template updated but associated README.md file has not been. Please verify that any necessary changes have been made to the README.


parameter code blocks with missing default field found. Please add the default field to these blocks:

Line 39
Line 47

Optionally, you can add a comment within the parameter code blocks to indicate that the parameter requires user input and avoid this message.

  • # No default value, user input required

While not required, it is recommended that every parameter have a default value unless user input for that parameter is required and too specific for any default value to make sense


Datasources and scripts with mismatched names found. These names should match; for example, a datasource named ds_currency should be paired with a script named js_currency. This convention should only be ignored when the same script is called by multiple datasources. The following datasource/script pairs have mismatched names:

Line 212: ds_cluster_sizing / js_cluster_parse


Recommendation policy has export that is missing recommended fields. These fields are scraped by the Flexera platform for dashboards:

Line 358: tags

Generated by 🚫 Danger

Copy link
Contributor

@XOmniverse XOmniverse left a comment

Choose a reason for hiding this comment

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

I requested some specific changes, but more broadly, there appear to be a lot more changes here than just updating deprecated API endpoints.

Please fully document all changes in the changelog.

@@ -1,5 +1,9 @@
# Changelog

## v0.3.2

- Replace usage of Kubecost deprecated endpoints for newest versions
Copy link
Contributor

Choose a reason for hiding this comment

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

This is awkwardly worded. Recommended change:

  • Updated API endpoints for Kubecost. Functionality unchanged.

@midir99 midir99 requested review from Rajasundar and removed request for joseluiszuflores November 25, 2024 15:50
## v0.3.3

- Updated API endpoints for Kubecost.
- Added two new params param_allow_shared_core,param_include_overhead.

Choose a reason for hiding this comment

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

we can use backticks or quotes here around the parameter names to indicate they are code or field names.

Copy link

@Rajasundar Rajasundar left a comment

Choose a reason for hiding this comment

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

@joseluiszuflores, I've added few comments with questions for clarification.

category "Include overhead"
label "Include overhead"
allowed_values "true", "false"
description " By enabling this option, Kubecost takes into account not only the resources used by applications and containers, but also those needed to operate and maintain the Kubernetes environment"

Choose a reason for hiding this comment

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

Additional leading space at the beginning can be removed.

result "result"
code <<-'EOS'
result = []
// Loop over each accountKey in data.accountID

Choose a reason for hiding this comment

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

comment can be removed, as the code already shows that data.accountID is being iterated.

// Loop over each accountKey in data.accountID
for (var accountKey in data.accountID) {
var accountData = data.accountID[accountKey];
// Extract required fields and push them as a flat object to extractedData

Choose a reason for hiding this comment

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

may be, the comment can be removed here as well as the code clearly indicates what it is doing.

@@ -141,10 +158,10 @@ script "js_currency", type:"javascript" do
result "result"
code <<-EOS
code = ds_kubecost_currency_code['code'].toUpperCase().trim()
// using default code.

Choose a reason for hiding this comment

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

comment can be removed.

totalNodeCount: crs['totalNodeCount'],
totalRAMGB: crs['totalRAMGB'],
totalVCPUs: crs['totalVCPUs'],
monthlyRate: (Math.round(crs['monthlyRate'] * 100) / 100 ).toFixed(2),

Choose a reason for hiding this comment

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

Looks like the precision and return type varies here. Is this intended?

Initial code will return 3 decimals (number) and the new code will return 2 decimals (string).

totalRAMGB: crs['totalRAMGB'],
totalVCPUs: crs['totalVCPUs'],
monthlyRate: (Math.round(crs['monthlyRate'] * 100) / 100 ).toFixed(2),
totalMonthlyCost: (Math.round(recommendation['totalMonthlyCost'] * 100) / 100 ).toFixed(2),

Choose a reason for hiding this comment

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

Loooks like the precision and return type varies here. Is this intended?

Initial code will return 3 decimals (number) and the new code will return 2 decimals (string).

monthlyRate: (Math.round(crs['monthlyRate'] * 100) / 100 ).toFixed(2),
totalMonthlyCost: (Math.round(recommendation['totalMonthlyCost'] * 100) / 100 ).toFixed(2),
// Note: Savings is presented as a negative value. Hence why we multiply by a negative number to invert it
savings: (Math.round(recommendation['monthlySavings'] * 100) / 100 ).toFixed(2),

Choose a reason for hiding this comment

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

Loooks like the precision and return type varies here. Is this intended and not inline with the comment in line no. 324

Initial code will return 3 decimals (number) and the new code will return 2 decimals (string).

end

script "js_recommendations", type: "javascript" do
parameters "ds_cluster_sizing", "ds_currency", "ds_applied_policy", "param_strategy", "param_min_nodes", "param_lookback", "param_target_util"
parameters "ds_cluster_sizing", "ds_currency","ds_applied_policy", "param_strategy", "param_min_nodes", "param_lookback", "param_target_util"

Choose a reason for hiding this comment

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

Inconsistency in spacing.

Suggested change
parameters "ds_cluster_sizing", "ds_currency","ds_applied_policy", "param_strategy", "param_min_nodes", "param_lookback", "param_target_util"
parameters "ds_cluster_sizing", "ds_currency", "ds_applied_policy", "param_strategy", "param_min_nodes", "param_lookback", "param_target_util"

datasource "ds_recommendations" do
run_script $js_recommendations, $ds_cluster_sizing, $ds_currency, $ds_applied_policy, $param_strategy, $param_min_nodes, $param_lookback, $param_target_util
run_script $js_recommendations, $ds_cluster_sizing, $ds_currency, $ds_applied_policy,$param_strategy, $param_min_nodes, $param_lookback, $param_target_util

Choose a reason for hiding this comment

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

Inconsistency in spacing.

Suggested change
run_script $js_recommendations, $ds_cluster_sizing, $ds_currency, $ds_applied_policy,$param_strategy, $param_min_nodes, $param_lookback, $param_target_util
run_script $js_recommendations, $ds_cluster_sizing, $ds_currency, $ds_applied_policy, $param_strategy, $param_min_nodes, $param_lookback, $param_target_util

description "By enabling this option, Kubecost takes into account not only the resources used by applications and containers, but also those needed to operate and maintain the Kubernetes environment"
end


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

Copy link

@Rajasundar Rajasundar left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

5 participants