Skip to content

Commit

Permalink
Merge pull request #2388 from devtron-labs/fix/app-metrics-time-range
Browse files Browse the repository at this point in the history
fix: time range selector issue in app metrics
  • Loading branch information
eshankvaish authored Jan 22, 2025
2 parents 9c680c0 + a6f33dd commit 60985dc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/components/app/details/appDetails/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ export function addChartNameExtensionToBaseURL(
return url
}

// Need to send either the relative time like: now-5m or the timestamp to grafana
// Assuming format is 'DD-MM-YYYY hh:mm:ss'
const getTimestampFromDateIfAvailable = (dateString: string): string => {
try {
const [day, month, yearAndTime] = dateString.split('-')
const [year, time] = yearAndTime.split(' ')
const formattedDate = `${year}-${month}-${day}T${time}`
const parsedDate = new Date(formattedDate).getTime()

return isNaN(parsedDate) ? dateString : parsedDate.toString()
} catch {
return dateString
}
}

export function addQueryParamToGrafanaURL(
url: string,
appId: string | number,
Expand All @@ -343,8 +358,8 @@ export function addQueryParamToGrafanaURL(
statusCode?: StatusTypes,
latency?: number,
): string {
const startTime: string = calendarInputs.startDate
const endTime: string = calendarInputs.endDate
const startTime: string = getTimestampFromDateIfAvailable(calendarInputs.startDate)
const endTime: string = getTimestampFromDateIfAvailable(calendarInputs.endDate)
url += `?orgId=${window.__GRAFANA_ORG_ID__}`
url += `&refresh=10s`
url += `&var-app=${appId}`
Expand Down

0 comments on commit 60985dc

Please sign in to comment.