-
Notifications
You must be signed in to change notification settings - Fork 378
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
fix:修复bug 折扣为负数的问题 并且设置了折扣的取值范围 #760
Conversation
🎉 Successfully Build Images. Docker RegistryOverview: https://hub.docker.com/u/gocrane
Quick Deploy - Helm helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
--set craned.image.repository=gocrane/craned \
--set craned.image.tag=pr-760-5de6951 \
--set metricAdapter.image.repository=gocrane/metric-adapter \
--set metricAdapter.image.tag=pr-760-5de6951 \
--set craneAgent.image.repository=gocrane/crane-agent \
--set craneAgent.image.tag=pr-760-5de6951 \
--set cranedDashboard.image.repository=gocrane/dashboard \
--set cranedDashboard.image.tag=pr-760-5de6951 crane/crane Coding RegistryOverview: https://finops.coding.net/public-artifacts/gocrane/crane/packages
Quick Deploy - Helm helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
--set craned.image.repository=finops-docker.pkg.coding.net/gocrane/crane/craned \
--set craned.image.tag=pr-760-5de6951 \
--set metricAdapter.image.repository=finops-docker.pkg.coding.net/gocrane/crane/metric-adapter \
--set metricAdapter.image.tag=pr-760-5de6951 \
--set craneAgent.image.repository=finops-docker.pkg.coding.net/gocrane/crane/crane-agent \
--set craneAgent.image.tag=pr-760-5de6951 \
--set cranedDashboard.image.repository=finops-docker.pkg.coding.net/gocrane/crane/dashboard \
--set cranedDashboard.image.tag=pr-760-5de6951 crane/crane Ghcr RegistryOverview: https://github.com/orgs/gocrane/packages?repo_name=crane
Quick Deploy - Helm helm repo add crane https://finops-helm.pkg.coding.net/gocrane/gocrane
helm install crane -n crane-system --create-namespace \
--set craned.image.repository=ghcr.io/gocrane/crane/craned \
--set craned.image.tag=pr-760-5de6951 \
--set metricAdapter.image.repository=ghcr.io/gocrane/crane/metric-adapter \
--set metricAdapter.image.tag=pr-760-5de6951 \
--set craneAgent.image.repository=ghcr.io/gocrane/crane/crane-agent \
--set craneAgent.image.tag=pr-760-5de6951 \
--set cranedDashboard.image.repository=ghcr.io/gocrane/crane/dashboard \
--set cranedDashboard.image.tag=pr-760-5de6951 crane/crane |
* @Author: 若城 | ||
* @Date: 2023-05-04 22:20:52 | ||
* @LastEditTime: 2023-05-04 22:23:49 | ||
*/ |
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.
Please remove this
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.
好的
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.
已经去掉了
@@ -22,7 +28,7 @@ const defaultCluster = { | |||
id: v4(), | |||
clusterName: '', | |||
craneUrl: '', | |||
discount: 100, | |||
discount: 1, |
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.
Why set the discount to 1? default value is 100.
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.
折扣的取值范围是 1-9.9
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.
The range of 1-9.9 of the value is not correct.
The value will be passed to pql(Prometheus Query Language) string.
crane/pkg/web/src/hooks/useCraneDiscount.ts
Lines 4 to 10 in 087dc98
export const useCraneDiscount = () => { | |
const selectedClusterId = useSelector((state) => state.insight.selectedClusterId); | |
const clusterList = useFetchClusterListQuery({}); | |
return (clusterList.data?.data?.items ?? []).find((cluster) => cluster.id === selectedClusterId)?.discount; | |
}; |
crane/pkg/web/src/pages/Dashboard/Base/components/TopPanel.tsx
Lines 10 to 67 in 087dc98
const craneDiscount: any = useCraneDiscount(); | |
const PANE_LIST: Array<IBoardProps> = [ | |
{ | |
title: t('当月总成本'), | |
countPrefix: '¥ ', | |
lineColor: '#fff', | |
query: `sum ( | |
avg( | |
sum_over_time(node:node_total_hourly_cost:avg[30d]) | |
* on (node) group_left() max(kube_node_labels{label_beta_kubernetes_io_instance_type!~"eklet", label_node_kubernetes_io_instance_type!~"eklet"}) by (node) | |
) | |
by (node)) * (${craneDiscount}/100.0)`, | |
timeType: TimeType.Range, | |
tips: t('过去一个月集群总成本。从安装Crane时间开始,按小时累加集群成本'), | |
}, | |
{ | |
title: t('预估每月成本'), | |
countPrefix: '¥ ', | |
query: `sum ( | |
avg( | |
avg_over_time(node_total_hourly_cost[1h]) | |
* on (node) group_left() max(kube_node_labels{label_beta_kubernetes_io_instance_type!~"eklet", label_node_kubernetes_io_instance_type!~"eklet"}) by (node) | |
) | |
by (node)) * 730 * (${craneDiscount}/100.0)`, | |
timeType: TimeType.Range, | |
tips: t('以最近一小时成本估算未来一个月的成本。每小时成本 * 24 * 30'), | |
}, | |
{ | |
title: t('预估CPU总成本'), | |
query: `sum( | |
sum(kube_pod_container_resource_requests{resource="cpu", unit="core"}) by (container, pod, node, namespace) | |
* on (node) group_left() | |
avg( | |
avg_over_time(node_cpu_hourly_cost[1h]) * on (node) group_left() max(kube_node_labels{label_beta_kubernetes_io_instance_type!~"eklet",label_node_kubernetes_io_instance_type!~"eklet"} | |
) by (node) | |
) by (node) | |
) * 730 * (${craneDiscount}/100.)`, | |
countPrefix: '¥ ', | |
timeType: TimeType.Range, | |
tips: t('以最近一小时CPU成本估算未来一个月的CPU成本。每小时CPU成本 * 24 * 30'), | |
}, | |
{ | |
title: t('预估Memory总成本'), | |
query: `sum( | |
sum(kube_pod_container_resource_requests{resource="memory", unit="byte", namespace!=""} / 1024./ 1024. / 1024.) by (container, pod, node, namespace) * on (node) group_left() | |
avg( | |
avg_over_time(node_ram_hourly_cost[1h]) * on (node) group_left() max(kube_node_labels{label_beta_kubernetes_io_instance_type!~"eklet", label_node_kubernetes_io_instance_type!~"eklet"} | |
) by (node) | |
) by (node) | |
) * 730 * (${craneDiscount}/100.)`, | |
countPrefix: '¥ ', | |
timeType: TimeType.Range, | |
tips: t('以最近一小时Memory成本估算未来一个月的Memory成本。每小时Memory成本 * 24 * 30'), | |
}, | |
]; |
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.
也就是取值范围 不能小于0 就可以了是吧 , 还是说取值范围 在 0-100 之间
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.
重新修复了一下 折扣不可为负数
@RuoChengF can you make the PR description as English, especially make the commit message as English. |
The Pr content submitted this time is to modify the discount input content shall not be lower than 0 |
@@ -338,8 +338,12 @@ export const EditClusterModal = React.memo(() => { | |||
value={cluster.discount} | |||
onChange={(value: InputValue) => { | |||
let discount = value; | |||
let reg = /^\d+(\.{0,1}\d+){0,1}$/ |
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.
Not a good way to implement it.
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.
Of course, this is definitely not a good way to implement it. There are two main reasons why I write regular expressions directly inside components.
- The web side has a low utilization rate for its own encapsulation method, and it seems to have multiple files, which is rather messy, which is one of the reasons why I put forward the improvement of "READE.MD" in the issue
- My implementation idea is based on the current code style. If I repackage this thing into a method for import verification, the amount of code generated is too much.
针对 issues 中
#754
#757
bug 的修复
详细描述:
折扣这里 会存在负数的问题