[8.12] [Synthetics] Remove legacy screenshot image codepath (#172684) (#172980)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Synthetics] Remove legacy screenshot image codepath
(#172684)](https://github.com/elastic/kibana/pull/172684)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Justin
Kambic","email":"jk@elastic.co"},"sourceCommit":{"committedDate":"2023-12-08T17:13:45Z","message":"[Synthetics]
Remove legacy screenshot image codepath (#172684)\n\n##
Summary\r\n\r\nWe have not used full screenshot image data since early
alpha versions\r\nof Synthetics, and there is no reason to _not_ use
screenshot blocks\r\ninstead as they make far more efficient storage
performance.\r\n\r\nRemoves the route that returns full image data. I
may later include\r\nchanges to remove references to this on the client
as well, or do that\r\nin a
follow-up.","sha":"8d3e8cd838ad80f8955c986fe830a9e6590a60de","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v8.12.0","Team:obs-ux-infra_services","Team:uptime","v8.13.0"],"number":172684,"url":"https://github.com/elastic/kibana/pull/172684","mergeCommit":{"message":"[Synthetics]
Remove legacy screenshot image codepath (#172684)\n\n##
Summary\r\n\r\nWe have not used full screenshot image data since early
alpha versions\r\nof Synthetics, and there is no reason to _not_ use
screenshot blocks\r\ninstead as they make far more efficient storage
performance.\r\n\r\nRemoves the route that returns full image data. I
may later include\r\nchanges to remove references to this on the client
as well, or do that\r\nin a
follow-up.","sha":"8d3e8cd838ad80f8955c986fe830a9e6590a60de"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172684","number":172684,"mergeCommit":{"message":"[Synthetics]
Remove legacy screenshot image codepath (#172684)\n\n##
Summary\r\n\r\nWe have not used full screenshot image data since early
alpha versions\r\nof Synthetics, and there is no reason to _not_ use
screenshot blocks\r\ninstead as they make far more efficient storage
performance.\r\n\r\nRemoves the route that returns full image data. I
may later include\r\nchanges to remove references to this on the client
as well, or do that\r\nin a
follow-up.","sha":"8d3e8cd838ad80f8955c986fe830a9e6590a60de"}}]}]
BACKPORT-->

Co-authored-by: Justin Kambic <jk@elastic.co>
This commit is contained in:
Kibana Machine 2023-12-08 15:49:17 -05:00 committed by GitHub
parent ed5fd5a735
commit c72d0570ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 115 deletions

View file

@ -9,10 +9,12 @@ import {
getJourneyScreenshot,
ScreenshotReturnTypesUnion,
} from '../legacy_uptime/lib/requests/get_journey_screenshot';
import { isFullScreenshot, isRefResult, RefResult } from '../../common/runtime_types';
import { isRefResult, RefResult } from '../../common/runtime_types';
import { RouteContext, UptimeRouteContext } from '../routes/types';
export type ClientContract = Buffer | { screenshotRef: RefResult };
export interface ClientContract {
screenshotRef: RefResult;
}
function getSharedHeaders(stepName: string, totalSteps: number) {
return {
@ -35,15 +37,7 @@ export const journeyScreenshotHandler = async ({
stepIndex,
});
if (isFullScreenshot(result) && typeof result.synthetics?.blob !== 'undefined') {
return response.ok({
body: Buffer.from(result.synthetics.blob, 'base64'),
headers: {
'content-type': result.synthetics.blob_mime || 'image/png', // falls back to 'image/png' for earlier versions of synthetics
...getSharedHeaders(result.synthetics.step.name, result.totalSteps),
},
});
} else if (isRefResult(result)) {
if (isRefResult(result)) {
return response.ok({
body: {
screenshotRef: result,

View file

@ -105,94 +105,6 @@ describe('journey screenshot route', () => {
expect(response.body.screenshotRef).toEqual(mock);
});
it('returns full screenshot blob', async () => {
const mock = {
synthetics: {
blob: 'a blob',
blob_mime: 'image/jpeg',
step: {
name: 'a step name',
},
type: 'step/screenshot',
},
};
handlerContext.uptimeEsClient.search = jest.fn().mockResolvedValue({
body: {
hits: {
total: {
value: 3,
},
hits: [],
},
aggregations: { step: { image: { hits: { hits: [{ _source: mock }] } } } },
},
});
const route = createJourneyScreenshotRoute({
requests: {
getJourneyScreenshot: jest.fn().mockReturnValue(mock),
},
} as unknown as UMServerLibs);
expect(await route.handler(handlerContext as any)).toMatchInlineSnapshot(`
Object {
"body": Object {
"data": Array [
105,
185,
104,
],
"type": "Buffer",
},
"headers": Object {
"cache-control": "max-age=600",
"caption-name": "a step name",
"content-type": "image/jpeg",
"max-steps": "3",
},
"message": "Ok",
"status": 200,
}
`);
});
it('defaults to png when mime is undefined', async () => {
const mock = {
synthetics: {
blob: 'a blob',
step: {
name: 'a step name',
},
type: 'step/screenshot',
},
};
handlerContext.uptimeEsClient.search = jest.fn().mockResolvedValue({
body: {
hits: {
total: {
value: 3,
},
hits: [],
},
aggregations: { step: { image: { hits: { hits: [{ _source: mock }] } } } },
},
});
const route = createJourneyScreenshotRoute({
requests: {
getJourneyScreenshot: jest.fn().mockReturnValue(mock),
},
} as unknown as UMServerLibs);
const response = (await route.handler(
handlerContext as any
)) as IKibanaResponse<ClientContract>;
expect(response.status).toBe(200);
// @ts-expect-error incomplete implementation for testing
expect(response.headers['content-type']).toBe('image/png');
});
it('returns 404 for screenshot missing blob', async () => {
const route = createJourneyScreenshotRoute({
requests: {

View file

@ -6,11 +6,7 @@
*/
import { IKibanaResponse } from '@kbn/core-http-server';
import { schema } from '@kbn/config-schema';
import {
isRefResult,
isFullScreenshot,
RefResult,
} from '../../../../common/runtime_types/ping/synthetics';
import { isRefResult, RefResult } from '../../../../common/runtime_types/ping/synthetics';
import { UMServerLibs } from '../../lib/lib';
import {
getJourneyScreenshot,
@ -19,7 +15,9 @@ import {
import { RouteContext, UMRestApiRouteFactory, UptimeRouteContext } from '../types';
import { API_URLS } from '../../../../common/constants';
export type ClientContract = Buffer | { screenshotRef: RefResult };
export interface ClientContract {
screenshotRef: RefResult;
}
function getSharedHeaders(stepName: string, totalSteps: number) {
return {
@ -30,7 +28,7 @@ function getSharedHeaders(stepName: string, totalSteps: number) {
}
export const createJourneyScreenshotRoute: UMRestApiRouteFactory<ClientContract> = (
libs: UMServerLibs
_libs: UMServerLibs
) => ({
method: 'GET',
path: API_URLS.JOURNEY_SCREENSHOT,
@ -58,15 +56,7 @@ export const journeyScreenshotHandler = async ({
stepIndex,
});
if (isFullScreenshot(result) && typeof result.synthetics?.blob !== 'undefined') {
return response.ok({
body: Buffer.from(result.synthetics.blob, 'base64'),
headers: {
'content-type': result.synthetics.blob_mime || 'image/png', // falls back to 'image/png' for earlier versions of synthetics
...getSharedHeaders(result.synthetics.step.name, result.totalSteps),
},
});
} else if (isRefResult(result)) {
if (isRefResult(result)) {
return response.ok({
body: {
screenshotRef: result,