Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ export const observability = createQueryKeys('observability', {
return response.data.metrics && (JSON.parse(response.data.metrics).data[0] as string)
},
}),
httpRouteName: ({
clusterId,
serviceId,
startDate,
endDate,
}: {
clusterId: string
serviceId: string
startDate: string
endDate: string
}) => ({
queryKey: ['httpPortName', clusterId, serviceId],
async queryFn() {
const endpoint = `api/v1/label/httproute_name/values?match[]=kube_httproute_labels{qovery_com_associated_service_id="${serviceId}"}`
const response = await clusterApi.getClusterMetrics(
clusterId,
endpoint,
endpoint,
'',
startDate,
endDate,
undefined,
undefined,
undefined,
'True',
'True',
undefined,
'prometheus',
'false',
'service_overview',
'httpRouteName'
)
return response.data.metrics && (JSON.parse(response.data.metrics).data[0] as string)
},
}),
hpaName: ({
clusterId,
serviceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ErrorBoundary, FunnelFlow } from '@qovery/shared/ui'
import { useContainerName } from '../../hooks/use-container-name/use-container-name'
import { useCreateAlertRule } from '../../hooks/use-create-alert-rule/use-create-alert-rule'
import { useHpaName } from '../../hooks/use-hpa-name/use-hpa-name'
import { useHttpRouteName } from '../../hooks/use-http-route-name/use-http-route-name'
import { useIngressName } from '../../hooks/use-ingress-name/use-ingress-name'
import { generateConditionDescription } from '../../util-alerting/generate-condition-description'
import { type AlertConfiguration, type MetricCategory } from './alerting-creation-flow.types'
Expand All @@ -16,7 +17,9 @@ import {
QUERY_CPU,
QUERY_HPA_ISSUE,
QUERY_HTTP_ERROR,
QUERY_HTTP_ERROR_COMBINED,
QUERY_HTTP_LATENCY,
QUERY_HTTP_LATENCY_COMBINED,
QUERY_INSTANCE_RESTART,
QUERY_MEMORY,
QUERY_MISSING_INSTANCE,
Expand All @@ -43,6 +46,7 @@ interface AlertingCreationFlowContextInterface {
totalSteps: number
containerName?: string
ingressName?: string
httpRouteName?: string
onNavigateToMetric: (index: number) => void
onComplete: (alerts: AlertConfiguration[]) => Promise<void>
isLoading: boolean
Expand Down Expand Up @@ -103,13 +107,22 @@ export function AlertingCreationFlow({
endDate: now.toISOString(),
})

// NGINX: Fetch nginx ingress name (to remove when migrating to envoy)
const { data: ingressName } = useIngressName({
clusterId: environment.cluster_id,
serviceId: service.id,
startDate: oneHourAgo.toISOString(),
endDate: now.toISOString(),
})

// ENVOY: Fetch envoy HTTPRoute name
const { data: httpRouteName } = useHttpRouteName({
clusterId: environment.cluster_id,
serviceId: service.id,
startDate: oneHourAgo.toISOString(),
endDate: now.toISOString(),
})

const hasAutoscaling =
(service?.serviceType === 'APPLICATION' || service?.serviceType === 'CONTAINER') &&
service?.min_running_instances !== service?.max_running_instances
Expand Down Expand Up @@ -155,7 +168,8 @@ export function AlertingCreationFlow({
service?.min_running_instances !== service?.max_running_instances

if (!containerName) return
if (hasPublicPort && !ingressName) return
// For HTTP alerts, require at least one of nginx or envoy to be present
if (hasPublicPort && !ingressName && !httpRouteName) return
if (hasAutoscaling && !hpaName) return

try {
Expand Down Expand Up @@ -201,8 +215,26 @@ export function AlertingCreationFlow({
.with('memory', () => QUERY_MEMORY(containerName))
.with('missing_instance', () => QUERY_MISSING_INSTANCE(containerName))
.with('instance_restart', () => QUERY_INSTANCE_RESTART(containerName))
.with('http_error', () => (ingressName ? QUERY_HTTP_ERROR(ingressName) : ''))
.with('http_latency', () => (ingressName ? QUERY_HTTP_LATENCY(ingressName) : ''))
.with('http_error', () => {
// Use combined query if both sources available, otherwise fallback to single source
if (ingressName && httpRouteName) {
return QUERY_HTTP_ERROR_COMBINED(ingressName, httpRouteName)
}
if (ingressName) {
return QUERY_HTTP_ERROR(ingressName)
}
return ''
})
.with('http_latency', () => {
// Use combined query if both sources available, otherwise fallback to single source
if (ingressName && httpRouteName) {
return QUERY_HTTP_LATENCY_COMBINED(ingressName, httpRouteName)
}
if (ingressName) {
return QUERY_HTTP_LATENCY(ingressName)
}
return ''
})
.with('hpa_limit', () => (hpaName ? QUERY_HPA_ISSUE(hpaName) : ''))
.otherwise(() => ''),
},
Expand Down Expand Up @@ -237,6 +269,7 @@ export function AlertingCreationFlow({
totalSteps,
containerName,
ingressName,
httpRouteName,
onNavigateToMetric: handleNavigateToMetric,
onComplete: handleComplete,
isLoading,
Expand Down
Loading