Skip to content

Commit

Permalink
fix(backend): use client timezone for plots
Browse files Browse the repository at this point in the history
fixes #1215
  • Loading branch information
anupcowkur committed Sep 11, 2024
1 parent 3d47cbd commit e2a1af5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/api/measure/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4338,7 +4338,7 @@ func GetSessionsOverviewPlot(c *gin.Context) {

sessionInstances, err := GetSessionsPlot(ctx, &af)
if err != nil {
msg := `failed to query exception instances`
msg := `failed to query data for sessions overview plot`
fmt.Println(msg, err)
c.JSON(http.StatusInternalServerError, gin.H{
"error": msg,
Expand Down
22 changes: 17 additions & 5 deletions backend/api/measure/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,13 @@ func GetExceptionsWithFilter(ctx context.Context, eventIds []uuid.UUID, af *filt
// GetExceptionPlotInstances queries aggregated exception
// instances and crash free sessions by datetime and filters.
func GetExceptionPlotInstances(ctx context.Context, af *filter.AppFilter) (issueInstances []event.IssueInstance, err error) {
if af.Timezone == "" {
return nil, errors.New("missing timezone filter")
}

base := sqlf.
From("default.events").
Select("formatDateTime(timestamp, '%Y-%m-%d') as datetime").
Select("formatDateTime(toTimeZone(timestamp, ?), '%Y-%m-%d') as datetime", af.Timezone).
Select("concat(toString(attribute.app_version), '', '(', toString(attribute.app_build), ')') as app_version").
Select("type").
Select("session_id").
Expand Down Expand Up @@ -1604,9 +1608,13 @@ func GetANRsWithFilter(ctx context.Context, eventIds []uuid.UUID, af *filter.App
// GetANRPlotInstances queries aggregated ANRs
// instances and ANR free sessions by datetime and filters.
func GetANRPlotInstances(ctx context.Context, af *filter.AppFilter) (issueInstances []event.IssueInstance, err error) {
if af.Timezone == "" {
return nil, errors.New("missing timezone filter")
}

base := sqlf.
From("default.events").
Select("formatDateTime(timestamp, '%Y-%m-%d') as datetime").
Select("formatDateTime(toTimeZone(timestamp, ?), '%Y-%m-%d') as datetime", af.Timezone).
Select("concat(toString(attribute.app_version), ' ', '(', toString(attribute.app_build), ')') as app_version").
Select("type").
Select("session_id").
Expand Down Expand Up @@ -1665,14 +1673,18 @@ func GetANRPlotInstances(ctx context.Context, af *filter.AppFilter) (issueInstan
// GetIssuesPlot queries and prepares aggregated issue instances
// based on datetime and filters.
func GetIssuesPlot(ctx context.Context, eventIds []uuid.UUID, af *filter.AppFilter) (issueInstances []event.IssueInstance, err error) {
if af.Timezone == "" {
return nil, errors.New("missing timezone filter")
}

stmt := sqlf.
From(`default.events`).
Select("formatDateTime(timestamp, '%Y-%m-%d') as datetime").
Select("formatDateTime(toTimeZone(timestamp, ?), '%Y-%m-%d') as datetime", af.Timezone).
Select("concat(toString(attribute.app_version), ' ', '(', toString(attribute.app_build),')') as version").
Select("count(id) as instances").
Where("`id` in (?)", eventIds).
GroupBy("version, formatDateTime(timestamp, '%Y-%m-%d') as datetime").
OrderBy("version, formatDateTime(timestamp, '%Y-%m-%d') as datetime")
GroupBy("version, datetime").
OrderBy("version, datetime")

stmt.Where("timestamp >= ? and timestamp <= ?", af.From, af.To)

Expand Down
10 changes: 6 additions & 4 deletions frontend/dashboard/app/api/api_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,13 @@ export const fetchExceptionsOverviewPlotFromServer = async (appId: string, excep

const serverFormattedStartDate = formatUserInputDateToServerFormat(startDate)
const serverFormattedEndDate = formatUserInputDateToServerFormat(endDate)
const timezone = getTimeZoneForServer()

var url = ""
if (exceptionsType === ExceptionsType.Crash) {
url = `${origin}/apps/${appId}/crashGroups/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}`
url = `${origin}/apps/${appId}/crashGroups/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}&timezone=${timezone}`
} else {
url = `${origin}/apps/${appId}/anrGroups/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}`
url = `${origin}/apps/${appId}/anrGroups/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}&timezone=${timezone}`
}

// Append versions if present
Expand Down Expand Up @@ -1097,12 +1098,13 @@ export const fetchExceptionsDetailsPlotFromServer = async (appId: string, except

const serverFormattedStartDate = formatUserInputDateToServerFormat(startDate)
const serverFormattedEndDate = formatUserInputDateToServerFormat(endDate)
const timezone = getTimeZoneForServer()

var url = ""
if (exceptionsType === ExceptionsType.Crash) {
url = `${origin}/apps/${appId}/crashGroups/${exceptionsGroupdId}/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}`
url = `${origin}/apps/${appId}/crashGroups/${exceptionsGroupdId}/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}&timezone=${timezone}`
} else {
url = `${origin}/apps/${appId}/anrGroups/${exceptionsGroupdId}/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}`
url = `${origin}/apps/${appId}/anrGroups/${exceptionsGroupdId}/plots/instances?from=${serverFormattedStartDate}&to=${serverFormattedEndDate}&timezone=${timezone}`
}

// Append versions if present
Expand Down

0 comments on commit e2a1af5

Please sign in to comment.