Skip to content

Commit f2e533b

Browse files
jul-danclaude
andauthored
feat(keda): add posthog events (#2340)
* feat(keda): add posthog event when KEDA is enabled at cluster level Track cluster-keda-enabled event with organization_id, cluster_id, and cloud_provider properties when users activate KEDA feature in cluster settings. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * feat(keda): add posthog events for KEDA autoscaling mode selection and scaler management Track three new PostHog events for KEDA autoscaling: - service-autoscaling-keda-selected: When user selects KEDA autoscaling mode - service-keda-scaler-added: When user adds a new scaler - service-keda-scaler-type-set: When user sets the scaler type All events include organization_id, environment_id, service_id, service_type, min_running_instances, and max_running_instances. The scaler events also include scaler-specific properties. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * refactor(keda): remove unnecessary tracking properties and comments from posthog events Remove organization_id, environment_id, service_id, and service_type from all KEDA PostHog events. Remove code comments. Keep only essential properties: cloud_provider, min/max instances, scaler_type, and scaler_count. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix(keda): resolve typescript errors in posthog event tracking Fix onBlur handler to use onChange instead (InputText doesn't support onBlur prop) and remove unused imports from keda-settings. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * chore: update qovery-typescript-axios to v1.1.821 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c7b4c25 commit f2e533b

6 files changed

Lines changed: 47 additions & 11 deletions

File tree

libs/domains/clusters/feature/src/lib/hooks/use-edit-cluster/use-edit-cluster.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMutation, useQueryClient } from '@tanstack/react-query'
2+
import posthog from 'posthog-js'
23
import { mutations } from '@qovery/domains/clusters/data-access'
34
import { queries } from '@qovery/state/util-queries'
45
import { useDeployCluster } from '../use-deploy-cluster/use-deploy-cluster'
@@ -8,13 +9,19 @@ export function useEditCluster() {
89
const { mutateAsync: deployCluster } = useDeployCluster()
910

1011
return useMutation(mutations.editCluster, {
11-
onSuccess(_, { organizationId, clusterId }) {
12+
onSuccess(_, { organizationId, clusterId, clusterRequest }) {
1213
queryClient.invalidateQueries({
1314
queryKey: queries.clusters.list({ organizationId }).queryKey,
1415
})
1516
queryClient.invalidateQueries({
1617
queryKey: queries.clusters.kubeconfig({ organizationId, clusterId }).queryKey,
1718
})
19+
20+
if (clusterRequest.keda?.enabled) {
21+
posthog.capture('cluster-keda-enabled', {
22+
cloud_provider: clusterRequest.cloud_provider,
23+
})
24+
}
1825
},
1926
meta: {
2027
notifyOnSuccess(_: unknown, variables: unknown) {

libs/domains/services/feature/src/lib/keda/components/keda-scalers-fields.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { type Control, Controller, type UseFieldArrayReturn } from 'react-hook-form'
1+
import posthog from 'posthog-js'
2+
import { type Control, Controller, type UseFieldArrayReturn, useFormContext } from 'react-hook-form'
23
import { Button, CodeEditor, InputText } from '@qovery/shared/ui'
34

45
export interface KedaScalersFieldsProps {
@@ -17,9 +18,19 @@ export function KedaScalersFields({
1718
cooldownPeriod,
1819
}: KedaScalersFieldsProps) {
1920
const { fields: scalers, append, remove } = scalersFieldArray
21+
const { watch } = useFormContext()
22+
23+
const minRunningInstances = watch('min_running_instances')
24+
const maxRunningInstances = watch('max_running_instances')
2025

2126
const handleAddScaler = () => {
2227
append({ type: '', config: '', triggerAuthentication: '' })
28+
29+
posthog.capture('service-keda-scaler-added', {
30+
min_running_instances: minRunningInstances,
31+
max_running_instances: maxRunningInstances,
32+
scaler_count: scalers.length + 1,
33+
})
2334
}
2435

2536
const handleRemoveScaler = (index: number) => {
@@ -105,7 +116,16 @@ export function KedaScalersFields({
105116
name={field.name}
106117
label="Scaler Type"
107118
value={field.value ?? ''}
108-
onChange={field.onChange}
119+
onChange={(e) => {
120+
field.onChange(e)
121+
if (e.target.value) {
122+
posthog.capture('service-keda-scaler-type-set', {
123+
scaler_type: e.target.value,
124+
min_running_instances: minRunningInstances,
125+
max_running_instances: maxRunningInstances,
126+
})
127+
}
128+
}}
109129
disabled={disabled}
110130
hint="Type: 'cpu', 'memory', 'prometheus', 'aws-sqs', etc."
111131
error={error?.message}

libs/domains/services/feature/src/lib/keda/components/keda-settings.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Control, type UseFieldArrayReturn } from 'react-hook-form'
2-
import { Callout, Icon } from '@qovery/shared/ui'
32
import { InstancesRangeInputs } from './instances-range-inputs'
43
import { KedaScalersFields } from './keda-scalers-fields'
54

libs/shared/console-shared/src/lib/application-settings/ui/application-settings-resources/application-settings-resources.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import posthog from 'posthog-js'
12
import { useFeatureFlagVariantKey } from 'posthog-js/react'
23
import { useEffect, useRef } from 'react'
34
import { Controller, useFieldArray, useFormContext } from 'react-hook-form'
@@ -329,7 +330,16 @@ export function ApplicationSettingsResources({
329330
<InputSelect
330331
label="Autoscaling mode"
331332
options={options}
332-
onChange={field.onChange}
333+
onChange={(value) => {
334+
field.onChange(value)
335+
336+
if (value === 'KEDA') {
337+
posthog.capture('service-autoscaling-keda-selected', {
338+
min_running_instances: minRunningInstances,
339+
max_running_instances: maxRunningInstances,
340+
})
341+
}
342+
}}
333343
value={field.value || 'NONE'}
334344
hint="Choose how instances should scale"
335345
/>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"mermaid": "^11.6.0",
7070
"monaco-editor": "0.53.0",
7171
"posthog-js": "^1.260.1",
72-
"qovery-typescript-axios": "^1.1.816",
72+
"qovery-typescript-axios": "^1.1.821",
7373
"react": "18.3.1",
7474
"react-country-flag": "^3.0.2",
7575
"react-datepicker": "^4.12.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,7 +5679,7 @@ __metadata:
56795679
prettier: ^3.2.5
56805680
prettier-plugin-tailwindcss: ^0.5.14
56815681
pretty-quick: ^4.0.0
5682-
qovery-typescript-axios: ^1.1.816
5682+
qovery-typescript-axios: ^1.1.821
56835683
qovery-ws-typescript-axios: ^0.1.420
56845684
react: 18.3.1
56855685
react-country-flag: ^3.0.2
@@ -24520,12 +24520,12 @@ __metadata:
2452024520
languageName: node
2452124521
linkType: hard
2452224522

24523-
"qovery-typescript-axios@npm:^1.1.816":
24524-
version: 1.1.816
24525-
resolution: "qovery-typescript-axios@npm:1.1.816"
24523+
"qovery-typescript-axios@npm:^1.1.821":
24524+
version: 1.1.821
24525+
resolution: "qovery-typescript-axios@npm:1.1.821"
2452624526
dependencies:
2452724527
axios: 1.12.2
24528-
checksum: 092da0eceed47a368f26abe069bda9817cd4c943963f276d3744fa9407bb4d2d4ba095ecf4c041be4ca2d412473711f03e20432985552490f1af3de4f9e7fe39
24528+
checksum: e51d1d3b1d96d8f55e6e9522efbb86d47994c63bcf11b8fb6240e45b9d396d2c198255ec2e43c6a7a15b8c0bbcd9c442aaaa3daeb51f117e9f2cd338ddf024dd
2452924529
languageName: node
2453024530
linkType: hard
2453124531

0 commit comments

Comments
 (0)