Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): use client timezone for plots #1224

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
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
Loading