Skip to content

Commit

Permalink
fix drilldown, encode filters, padding to detail modal, remove filter…
Browse files Browse the repository at this point in the history
…s on Breakdown change
  • Loading branch information
wolfeaustin committed Dec 8, 2023
1 parent f31446c commit 5949b21
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ui/.parcel-cache
ui/.cache
ui/dist
ui/.env
ui/node_modules/
cmd/costmodel/costmodel
cmd/costmodel/costmodel-amd64
Expand Down
4 changes: 2 additions & 2 deletions ui/src/cloudCost/cloudCostDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CloudCostDetails = ({

const nextFilters = [
...(filters ?? []),
{ property: "providerIds", value: selectedProviderId },
{ property: "providerID", value: selectedProviderId },
];

async function fetchData() {
Expand Down Expand Up @@ -122,7 +122,7 @@ const CloudCostDetails = ({
title={`Costs over the last ${window}`}
style={{ margin: "10%" }}
>
<Paper>
<Paper style={{ padding: 20 }}>
<Typography style={{ marginTop: "1rem" }} variant="body1">
{selectedItem}
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/cloudCostReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ const CloudCostReports = () => {
return {
property,
value,
name: aggMap[property] || property,
};
});
setFilters(newFilters);
Expand Down Expand Up @@ -267,6 +266,7 @@ const CloudCostReports = () => {
aggregationOptions={aggregationOptions}
aggregateBy={aggregateBy}
setAggregateBy={(agg) => {
setFilters([])
searchParams.set("agg", agg);
routerHistory.push({
search: `?${searchParams.toString()}`,
Expand Down
5 changes: 2 additions & 3 deletions ui/src/services/cloudCostDayTotals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import { getCloudFilters } from "../util";
import { parseFilters } from "../util";
import { costMetricToPropName } from "../cloudCost/tokens";

function formatItemsForCost({ data, costType }) {
Expand All @@ -21,12 +21,11 @@ class CloudCostDayTotalsService {
if (this.BASE_URL.includes("PLACEHOLDER_BASE_URL")) {
this.BASE_URL = `http://localhost:9090/model`;
}

if (aggregate.includes("item")) {
const resp = await axios.get(
`${
this.BASE_URL
}/cloudCost?window=${window}&costMetric=${costMetric}${getCloudFilters(
}/cloudCost?window=${window}&costMetric=${costMetric}&filter=${parseFilters(
filters
)}`
);
Expand Down
6 changes: 3 additions & 3 deletions ui/src/services/cloudCostTop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import { getCloudFilters, formatSampleItemsForGraph } from "../util";
import { formatSampleItemsForGraph, parseFilters } from "../util";

class CloudCostTopService {
BASE_URL = process.env.BASE_URL || "{PLACEHOLDER_BASE_URL}";
Expand All @@ -13,15 +13,15 @@ class CloudCostTopService {
window,
aggregate,
costMetric,
filters,
filter: parseFilters(filters ?? []),
limit: 1000,
};

if (aggregate.includes("item")) {
const resp = await axios.get(
`${
this.BASE_URL
}/cloudCost?window=${window}&costMetric=${costMetric}${getCloudFilters(
}/cloudCost?window=${window}&costMetric=${costMetric}&filter=${parseFilters(
filters
)}`
);
Expand Down
79 changes: 32 additions & 47 deletions ui/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,35 +344,6 @@ export function checkCustomWindow(window) {
return customDateRegex.test(window);
}

export function getCloudFilters(filters) {
const filterNamesMap = {
"invoice entity": "filterInvoiceEntityIDs",
provider: "filterProviders",
providerids: "filterProviderIDs",
service: "filterServices",
account: "filterAccountIDs",
};
const params = new URLSearchParams();
const labelFilters = [];

for (let filter of filters) {
const mapped = filterNamesMap[filter.property.toLowerCase()];

if (mapped) {
params.set(mapped, filter.value);
} else if (filter.property === "Labels") {
labelFilters.push(filter.value);
} else if (filter.property.startsWith(":")) {
labelFilters.push(`${filter.property.slice(6)}:${filter.value}`);
}
}
if (labelFilters.length) {
params.set("filterLabels", labelFilters.join(","));
}

return `&${params.toString()}`;
}

export function formatSampleItemsForGraph({ data, costMetric }) {
const costMetricPropName = costMetric
? costMetricToPropName[costMetric]
Expand Down Expand Up @@ -412,29 +383,31 @@ export function formatSampleItemsForGraph({ data, costMetric }) {
cloudCostItem[costMetricPropName].kubernetesPercent;
});
});
const tableRows = Object.entries(accumulator).map(
([
name,
{
const tableRows = Object.entries(accumulator)
.map(
([
name,
{
cost,
start,
end,
providerID,
kubernetesCost,
kubernetesPercent,
labelName,
},
]) => ({
cost,
name,
kubernetesCost,
kubernetesPercent,
start,
end,
providerID,
kubernetesCost,
kubernetesPercent,
labelName,
},
]) => ({
cost,
name,
kubernetesCost,
kubernetesPercent,
start,
end,
providerID,
labelName,
})
);
})
)
.sort((a, b) => (a.cost > b.cost ? -1 : 1));

const tableTotal = tableRows.reduce(
(tr1, tr2) => ({
Expand All @@ -457,6 +430,18 @@ export function formatSampleItemsForGraph({ data, costMetric }) {
return { graphData, tableRows, tableTotal };
}

export function parseFilters(filters) {
if (typeof filters === "string") {
return filters;
}
// remove dups (via context ) and format
return (
[...new Set(filters.map((f) => `${f.property}:"${f.value}"`))].join(
encodeURIComponent("+")
) || ""
);
}

export default {
rangeToCumulative,
cumulativeToTotals,
Expand Down

0 comments on commit 5949b21

Please sign in to comment.