Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Dec 20, 2024
2 parents 96962dd + 4e07188 commit 40d31cc
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 69 deletions.
2 changes: 1 addition & 1 deletion AGENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.0
v0.5.3
12 changes: 5 additions & 7 deletions assets/src/components/cost-management/CostManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from './ClusterUsagesTableCols'
import {
CostManagementTreeMap,
nodeCostByCluster,
cpuCostByCluster,
memoryCostByCluster,
} from './CostManagementTreeMap'

Expand Down Expand Up @@ -100,14 +100,14 @@ export function CostManagement() {
content: (
<Flex gap="small">
<CpuIcon />
<OverlineH1 as="h3">node cost by cluster</OverlineH1>
<OverlineH1 as="h3">CPU cost by cluster</OverlineH1>
</Flex>
),
}}
>
<CostManagementTreeMap
colorScheme="blue"
data={nodeCostByCluster(usages)}
data={cpuCostByCluster(usages)}
dataSize={usages.length}
/>
</Card>
Expand Down Expand Up @@ -135,7 +135,7 @@ export function CostManagement() {
</Card>
</Flex>
<Card
css={{ overflow: 'hidden' }}
css={{ overflow: 'hidden', maxHeight: 300 }}
header={{
content: (
<Flex gap="small">
Expand Down Expand Up @@ -174,13 +174,11 @@ export function CostManagement() {
}

const WrapperSC = styled.div(({ theme }) => ({
height: '100%',
width: '100%',
padding: theme.spacing.large,
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.large,
overflow: 'hidden',
gap: theme.spacing.medium,
}))

const cols = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,23 @@ const WrapperSC = styled.div(({ theme }) => ({
},
}))

export function nodeCostByCluster(usages: ClusterUsageTinyFragment[]) {
export function cpuCostByCluster(usages: ClusterUsageTinyFragment[]) {
const avg =
usages.reduce((acc, usage) => acc + (usage.nodeCost ?? 0), 0) /
usages.length
const projectMap: Record<string, TreeMapData> = {}

for (const usage of usages) {
if (!usage.nodeCost || !usage.cluster?.project) continue
if (!usage.cpuCost || !usage.cluster?.project) continue

const project = usage.cluster.project.name
if (!projectMap[project])
projectMap[project] = { name: project, children: [] }

if (usage.nodeCost / avg > MIN_COST_PERCENTAGE)
if (usage.cpuCost / avg > MIN_COST_PERCENTAGE)
projectMap[project].children?.push({
name: usage.cluster?.name ?? usage.id,
amount: usage.nodeCost,
amount: usage.cpuCost,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ export function CostManagementDetails() {
const PageWrapperSC = styled.div(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing.large,
gap: theme.spacing.medium,
padding: theme.spacing.large,
height: '100%',
width: '100%',
overflow: 'hidden',
}))

const HeaderWrapperSC = styled.div({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function CostManagementDetailsNamespaces() {
return (
<Flex
direction="column"
gap="large"
overflow="hidden"
gap="medium"
paddingBottom={theme.spacing.large}
>
<Flex gap="large">
<Card
Expand Down Expand Up @@ -116,7 +116,7 @@ export function CostManagementDetailsNamespaces() {
onChange={(e) => setNamespaceQ(e.target.value)}
/>
<Card
css={{ overflow: 'hidden' }}
css={{ overflow: 'hidden', maxHeight: 300 }}
header={{
content: (
<Flex gap="small">
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/kubernetes/rbac/Rbac.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const directory = [
{ path: ROLE_BINDINGS_REL_PATH, label: 'Role bindings' },
{ path: CLUSTER_ROLES_REL_PATH, label: 'Cluster roles' },
{ path: CLUSTER_ROLE_BINDINGS_REL_PATH, label: 'Cluster role bindings' },
{ path: SERVICE_ACCOUNTS_REL_PATH, label: 'Service Accounts' },
{ path: SERVICE_ACCOUNTS_REL_PATH, label: 'Service accounts' },
] as const

export default function Rbac() {
Expand Down
47 changes: 29 additions & 18 deletions assets/src/components/pr/automations/CreatePrModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { Body1BoldP, Body1P } from 'components/utils/typography/Text'

import { PrConfigurationFields } from './PrConfigurationFields'
import { validateAndFilterConfig } from './prConfigurationUtils'
import { isEmpty } from 'lodash'

function CreateSuccess({ pr }: { pr: PullRequestFragment }) {
const theme = useTheme()
Expand Down Expand Up @@ -60,7 +61,10 @@ function CreatePrModalBase({
onClose: Nullable<() => void>
}) {
const configuration = prAutomation.configuration || []
const [currentStep, setCurrentStep] = useState<StepKey>('config')
const hasConfiguration = !isEmpty(configuration)
const [currentStep, setCurrentStep] = useState<StepKey>(
hasConfiguration ? 'config' : 'review'
)
const stepIndex = steps.findIndex((s) => s.key === currentStep)
const [configVals, setConfigVals] = useState(
Object.fromEntries(
Expand Down Expand Up @@ -128,6 +132,7 @@ function CreatePrModalBase({
})
}
}}
size="large"
open={open}
onClose={onClose || undefined}
header={
Expand Down Expand Up @@ -184,12 +189,14 @@ function CreatePrModalBase({
>
Create
</Button>
<Button
secondary
onClick={() => setCurrentStep('config')}
>
Back
</Button>
{hasConfiguration && (
<Button
secondary
onClick={() => setCurrentStep('config')}
>
Back
</Button>
)}
<Button
secondary
onClick={() => onClose?.()}
Expand Down Expand Up @@ -225,7 +232,7 @@ function CreatePrModalBase({
gap: theme.spacing.large,
}}
>
{currentStep !== 'success' && (
{currentStep !== 'success' && hasConfiguration && (
<div css={{ display: 'flex' }}>
<Stepper
compact
Expand Down Expand Up @@ -274,21 +281,24 @@ function CreatePrModalBase({
</Card>
)}

<FormField
label="Configuration review"
name="configuration"
>
<Code
language="json"
showHeader={false}
{hasConfiguration && (
<FormField
label="Configuration review"
name="configuration"
>
{configJson || ''}
</Code>
</FormField>
<Code
language="json"
showHeader={false}
>
{configJson || ''}
</Code>
</FormField>
)}
<FormField
label="Repository"
required
name="repository"
hint={'Repository slug, i.e. username/infra-repo.'}
>
<Input2
value={identifier}
Expand All @@ -299,6 +309,7 @@ function CreatePrModalBase({
label="Branch"
required
name="branch"
hint="Pull request source branch name. Avoid using existing branches."
>
<Input2
value={branch}
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/utils/KickButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function KickButton({
} & ButtonProps) {
const [mutation, { loading, error }] = kickMutationHook({ variables })
const [lastSync, setLastSync] = useState<Date | undefined>(undefined)
const { disabled, secondsRemaining } = useSyncCooldown(lastSync, 5 * 1000)
const { disabled, secondsRemaining } = useSyncCooldown(lastSync, 15 * 1000)
const onClick = useCallback(() => {
setLastSync(new Date())
mutation()
Expand Down
7 changes: 7 additions & 0 deletions assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,7 @@ export type DeploymentSettingsAttributes = {
createBindings?: InputMaybe<Array<InputMaybe<PolicyBindingAttributes>>>;
deployerRepositoryId?: InputMaybe<Scalars['ID']['input']>;
gitBindings?: InputMaybe<Array<InputMaybe<PolicyBindingAttributes>>>;
logging?: InputMaybe<LoggingSettingsAttributes>;
/** connection details for a loki instance to use */
lokiConnection?: InputMaybe<HttpConnectionAttributes>;
mgmtRepo?: InputMaybe<Scalars['String']['input']>;
Expand Down Expand Up @@ -3378,6 +3379,12 @@ export type LoggingSettings = {
victoria?: Maybe<HttpConnection>;
};

export type LoggingSettingsAttributes = {
driver?: InputMaybe<LogDriver>;
enabled?: InputMaybe<Scalars['Boolean']['input']>;
victoria?: InputMaybe<HttpConnectionAttributes>;
};

export type LoginInfo = {
__typename?: 'LoginInfo';
external?: Maybe<Scalars['Boolean']['output']>;
Expand Down
11 changes: 9 additions & 2 deletions go/client/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion lib/console/cost/ingester.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ defmodule Console.Cost.Ingester do
alias Console.Repo
import Console.Services.Base
import Console.Cost.Utils, only: [batch_insert: 2]
alias Console.Schema.{Cluster, ClusterUsage, ClusterNamespaceUsage, ClusterScalingRecommendation}
alias Console.Deployments.Settings
alias Console.Schema.{DeploymentSettings, Cluster, ClusterUsage, ClusterNamespaceUsage, ClusterScalingRecommendation}

def ingest(attrs, %Cluster{id: id}) do
settings = Settings.cached()
start_transaction()
|> add_operation(:cluster, fn _ ->
case Repo.get_by(ClusterUsage, cluster_id: id) do
Expand Down Expand Up @@ -34,6 +36,8 @@ defmodule Console.Cost.Ingester do
|> add_operation(:scaling, fn _ ->
(Map.get(attrs, :recommendations) || [])
|> Stream.map(&cluster_timestamped(&1, id))
|> Stream.map(&infer_recommendation(&1, settings))
|> Stream.filter(& &1)
|> batch_insert(ClusterScalingRecommendation)
|> ok()
end)
Expand All @@ -48,4 +52,16 @@ defmodule Console.Cost.Ingester do
timestamped(map)
|> Map.put(:cluster_id, cluster_id)
end

defp infer_recommendation(map, %DeploymentSettings{cost: %DeploymentSettings.Cost{recommendation_cushion: cush}})
when is_integer(cush) do
case map do
%{memory_request: mr, cpu_request: cr} = map when is_float(mr) and is_float(cr) ->
Map.merge(map, %{memory_recommendation: cushioned(mr, cush), cpu_recommendation: cushioned(mr, cush)})
_ -> nil
end
end
defp infer_recommendation(_, _), do: nil

defp cushioned(val, cushion), do: val * ((cushion + 100) / 100)
end
3 changes: 3 additions & 0 deletions lib/console/deployments/clusters.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ defmodule Console.Deployments.Clusters do
end
end

@spec cached_cluster_metrics(Cluster.t) :: {:ok, term} | Console.error
def cached_cluster_metrics(%Cluster{id: id}), do: @local_adapter.get({:cluster_metrics, id})

@doc """
Fetches the node metrics for a cluster, this query is heavily cached for performance
"""
Expand Down
1 change: 1 addition & 0 deletions lib/console/graphql/deployments/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Console.GraphQl.Deployments.Settings do
field :stacks, :stack_settings_attributes, description: "global configuration for stack execution"
field :prometheus_connection, :http_connection_attributes, description: "connection details for a prometheus instance to use"
field :loki_connection, :http_connection_attributes, description: "connection details for a loki instance to use"
field :logging, :logging_settings_attributes
field :mgmt_repo, :string

field :smtp, :smtp_settings_attributes, description: "configuration for smtp message delivery"
Expand Down
2 changes: 1 addition & 1 deletion lib/console/graphql/resolvers/deployments/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ defmodule Console.GraphQl.Resolvers.Deployments.Cluster do
end

def metrics_summary(cluster, _args, _) do
case Clusters.cluster_metrics(cluster) do
case Clusters.cached_cluster_metrics(cluster) do
{:ok, %Kube.MetricsAggregate{status: %Kube.MetricsAggregate.Status{} = metrics}} ->
{:ok, %{
cpu_available: cores(metrics.cpu_available_millicores),
Expand Down
8 changes: 8 additions & 0 deletions schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ input DeploymentSettingsAttributes {
"connection details for a loki instance to use"
lokiConnection: HttpConnectionAttributes

logging: LoggingSettingsAttributes

mgmtRepo: String

"configuration for smtp message delivery"
Expand Down Expand Up @@ -1149,6 +1151,12 @@ input CostSettingsAttributes {
recommendationCushion: Int
}

input LoggingSettingsAttributes {
enabled: Boolean
driver: LogDriver
victoria: HttpConnectionAttributes
}

input AiSettingsAttributes {
enabled: Boolean

Expand Down
Loading

0 comments on commit 40d31cc

Please sign in to comment.