feat: update auth sign in report query (#37240)

* feat: update auth sign in report query

* fix chart config

* fix type error for custom properties in chart attributes

---------

Co-authored-by: Jordi Enric <jordi.err@gmail.com>
This commit is contained in:
Cemal KılıçandJordi Enric authored and GitHub committed 2025-07-17 15:45:44 +02:00
1 parent eb0106179e
commit 09fc7776b5
3 files changed
+30 -14

No files matched your search

@@ -55,6 +55,7 @@ export type MultiAttribute = {
omitFromTotal?: boolean
tooltip?: string
customValue?: number
[key: string]: any
/**
* Manipulate the value of the attribute before it is displayed on the chart.
* @param value - The value of the attribute.
+4 -4
View File
@@ -29,28 +29,28 @@ export const getAuthReportAttributes = (isFreePlan: boolean) => [
attribute: 'SignInAttempts',
provider: 'logs',
label: 'Password',
grantType: 'password',
login_type_provider: 'password',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'PKCE',
grantType: 'pkce',
login_type_provider: 'pkce',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'Refresh Token',
grantType: 'refresh_token',
login_type_provider: 'token',
enabled: true,
},
{
attribute: 'SignInAttempts',
provider: 'logs',
label: 'ID Token',
grantType: 'id_token',
login_type_provider: 'id_token',
enabled: true,
},
],
+25 -10
View File
@@ -64,14 +64,29 @@ const METRIC_SQL: Record<MetricKey, (interval: AnalyticsInterval) => string> = {
const granularity = analyticsIntervalToGranularity(interval)
return `
--sign-in-attempts
select
SELECT
timestamp_trunc(timestamp, ${granularity}) as timestamp,
json_value(event_message, "$.grant_type") as grant_type,
count(*) as count
from auth_logs
where json_value(event_message, "$.path") = '/token'
group by timestamp, grant_type
order by timestamp desc, grant_type
CASE
WHEN JSON_VALUE(event_message, "$.provider") IS NOT NULL
AND JSON_VALUE(event_message, "$.provider") != ''
THEN CONCAT(
JSON_VALUE(event_message, "$.login_method"),
' (',
JSON_VALUE(event_message, "$.provider"),
')'
)
ELSE JSON_VALUE(event_message, "$.login_method")
END as login_type_provider,
COUNT(*) as count
FROM
auth_logs
WHERE
JSON_VALUE(event_message, "$.action") = 'login'
AND JSON_VALUE(event_message, "$.metering") = "true"
GROUP BY
timestamp, login_type_provider
ORDER BY
timestamp desc, login_type_provider
`
},
PasswordResetRequests: (interval) => {
@@ -196,8 +211,8 @@ const METRIC_FORMATTER: Record<
ActiveUsers: (rawData, attributes) => defaultFormatter(rawData, attributes),
SignInAttempts: (rawData, attributes) => {
const chartAttributes = attributes.map((attr) => {
if (attr.attribute === 'SignInAttempts' && attr.grantType) {
return { ...attr, attribute: `${attr.attribute}_${attr.grantType}` }
if (attr.attribute === 'SignInAttempts' && attr.login_type_provider) {
return { ...attr, attribute: `${attr.attribute}_${attr.login_type_provider}` }
}
return attr
})
@@ -213,7 +228,7 @@ const METRIC_FORMATTER: Record<
})
const matchingPoints = result.filter((p: any) => p.timestamp === timestamp)
matchingPoints.forEach((p: any) => {
point[`SignInAttempts_${p.grant_type}`] = p.count
point[`SignInAttempts_${p.login_type_provider}`] = p.count
})
return point
})