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

fix:修复bug 折扣为负数的问题 并且设置了折扣的取值范围 #760

Closed
wants to merge 6 commits into from

Conversation

RuoChengF
Copy link

针对 issues 中
#754
#757
bug 的修复

详细描述:
折扣这里 会存在负数的问题

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

🎉 Successfully Build Images.
Now Support ARM Platforms.
Comment Post Time: 2023-05-09 18:49
Git Version: 5de6951

Docker Registry

Overview: https://hub.docker.com/u/gocrane

Image Pull Command
crane-agent:pr-760-5de6951 docker pull gocrane/crane-agent:pr-760-5de6951
dashboard:pr-760-5de6951 docker pull gocrane/dashboard:pr-760-5de6951
metric-adapter:pr-760-5de6951 docker pull gocrane/metric-adapter:pr-760-5de6951
craned:pr-760-5de6951 docker pull gocrane/craned:pr-760-5de6951

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 Registry

Overview: https://finops.coding.net/public-artifacts/gocrane/crane/packages

Image Pull Command
crane-agent:pr-760-5de6951 docker pull finops-docker.pkg.coding.net/gocrane/crane/crane-agent:pr-760-5de6951
dashboard:pr-760-5de6951 docker pull finops-docker.pkg.coding.net/gocrane/crane/dashboard:pr-760-5de6951
metric-adapter:pr-760-5de6951 docker pull finops-docker.pkg.coding.net/gocrane/crane/metric-adapter:pr-760-5de6951
craned:pr-760-5de6951 docker pull finops-docker.pkg.coding.net/gocrane/crane/craned:pr-760-5de6951

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 Registry

Overview: https://github.com/orgs/gocrane/packages?repo_name=crane

Image Pull Command
crane-agent:pr-760-5de6951 docker pull ghcr.io/gocrane/crane/crane-agent:pr-760-5de6951
dashboard:pr-760-5de6951 docker pull ghcr.io/gocrane/crane/dashboard:pr-760-5de6951
metric-adapter:pr-760-5de6951 docker pull ghcr.io/gocrane/crane/metric-adapter:pr-760-5de6951
craned:pr-760-5de6951 docker pull ghcr.io/gocrane/crane/craned:pr-760-5de6951

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

@qmhu qmhu requested a review from zsnmwy May 6, 2023 08:30
* @Author: 若城
* @Date: 2023-05-04 22:20:52
* @LastEditTime: 2023-05-04 22:23:49
*/
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this

Copy link
Author

Choose a reason for hiding this comment

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

好的

Copy link
Author

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,
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

折扣的取值范围是 1-9.9

Copy link
Member

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.

image

export const useCraneDiscount = () => {
const selectedClusterId = useSelector((state) => state.insight.selectedClusterId);
const clusterList = useFetchClusterListQuery({});
return (clusterList.data?.data?.items ?? []).find((cluster) => cluster.id === selectedClusterId)?.discount;
};

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'),
},
];

Copy link
Author

Choose a reason for hiding this comment

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

也就是取值范围 不能小于0 就可以了是吧 , 还是说取值范围 在 0-100 之间

Copy link
Author

Choose a reason for hiding this comment

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

重新修复了一下 折扣不可为负数

@mfanjie
Copy link
Contributor

mfanjie commented May 8, 2023

@RuoChengF can you make the PR description as English, especially make the commit message as English.

@RuoChengF
Copy link
Author

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}$/
Copy link
Member

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.

Copy link
Author

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.

  1. 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
  2. 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.

@RuoChengF RuoChengF closed this May 25, 2023
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.

None yet

4 participants