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

Revert Add SEARCH_RESPONSE_TIME analytics event to searches (#3632) #3779

Merged
merged 1 commit into from
Feb 10, 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
49 changes: 0 additions & 49 deletions frontend/src/data/media-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import type {
import type { ApiService } from "~/data/api-service"
import type { DetailFromMediaType, Media } from "~/types/media"
import { AUDIO, type SupportedMediaType } from "~/constants/media"
import { useAnalytics } from "~/composables/use-analytics"
import type { EventName } from "~/types/analytics"

import type { AxiosResponse } from "axios"

Expand All @@ -24,52 +22,10 @@ export interface MediaResult<
class MediaService<T extends Media> {
private readonly apiService: ApiService
private readonly mediaType: T["frontendMediaType"]
private readonly searchEvent: EventName

constructor(apiService: ApiService, mediaType: T["frontendMediaType"]) {
this.apiService = apiService
this.mediaType = mediaType
this.searchEvent =
`${this.mediaType.toUpperCase()}_SEARCH_RESPONSE_TIME` as EventName
}

/**
* Processes AxiosResponse from a search query to
* construct SEARCH_RESPONSE_TIME analytics event.
* @param response - Axios response
* @param requestDatetime - datetime before request was sent
*/
recordSearchTime(response: AxiosResponse, requestDatetime: Date) {
const REQUIRED_HEADERS = ["date", "cf-cache-status", "cf-ray"]

const responseHeaders = response.headers
if (!REQUIRED_HEADERS.every((header) => header in responseHeaders)) {
return
}

const responseDatetime = new Date(responseHeaders["date"])
if (responseDatetime < requestDatetime) {
// response returned was from the local cache
return
}

const cfRayIATA = responseHeaders["cf-ray"].split("-")[1]
if (cfRayIATA === undefined) {
return
}

const elapsedSeconds = Math.floor(
(responseDatetime.getTime() - requestDatetime.getTime()) / 1000
)
const url = new URL(response.request?.responseURL)

const { sendCustomEvent } = useAnalytics()
sendCustomEvent(this.searchEvent, {
cfCacheStatus: responseHeaders["cf-cache-status"],
cfRayIATA: cfRayIATA,
elapsedTime: elapsedSeconds,
queryString: url.search,
})
}

/**
Expand Down Expand Up @@ -103,16 +59,11 @@ class MediaService<T extends Media> {
params.peaks = "true"
}

const requestDatetime = new Date()

const res = await this.apiService.query<MediaResult<T[]>>(
this.mediaType,
slug,
params as unknown as Record<string, string>
)

this.recordSearchTime(res, requestDatetime)

return this.transformResults(res.data)
}

Expand Down
28 changes: 0 additions & 28 deletions frontend/src/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,34 +412,6 @@ export type Events = {
/** the reasons for why this result is considered sensitive */
sensitivities: string
}

/**
* Description: Time client-side search responses. Gives us observability into
* real user experience of search timings.
* Questions:
* - How long does it take for the client to receive a response to search requests?
*/
IMAGE_SEARCH_RESPONSE_TIME: {
/** the Cloudflare cache status, denoting whether the request hit Cloudflare or went all the way to our servers */
cfCacheStatus: string
/** the IATA location identifier as part of the `cf-ray` header, indicating the data centre the request passed through */
cfRayIATA: string
/** how many seconds it took to receive a response for the request */
elapsedTime: number
/** full query string */
queryString: string
}

AUDIO_SEARCH_RESPONSE_TIME: {
/** the Cloudflare cache status, denoting whether the request hit Cloudflare or went all the way to our servers */
cfCacheStatus: string
/** the IATA location identifier as part of the `cf-ray` header, indicating the data centre the request passed through */
cfRayIATA: string
/** how many seconds it took to receive a response for the request */
elapsedTime: number
/** full query string */
queryString: string
}
}

/**
Expand Down
147 changes: 0 additions & 147 deletions frontend/test/unit/specs/data/media-service.spec.ts

This file was deleted.

Loading