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

Add the IMAGE_STORAGE_DEBUG_REQUEST_ERRORS env var & default it to false on unauthenticated setups #1836

Merged
merged 2 commits into from
Nov 8, 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
1 change: 1 addition & 0 deletions config/confd/templates/env.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ IMAGE_STORAGE_ENDPOINT={{getenv "IMAGE_STORAGE_ENDPOINT"}}
IMAGE_STORAGE_FORCE_PATH_STYLE={{getenv "IMAGE_STORAGE_FORCE_PATH_STYLE"}}
IMAGE_STORAGE_PREFIX={{getenv "IMAGE_STORAGE_PREFIX"}}
IMAGE_STORAGE_SECRET_KEY={{getenv "IMAGE_STORAGE_SECRET_KEY"}}
IMAGE_STORAGE_DEBUG_REQUEST_ERRORS={{getenv "IMAGE_STORAGE_DEBUG_REQUEST_ERRORS"}}
JSON_WEB_TOKEN_EXPIRY_MINUTES={{getenv "JSON_WEB_TOKEN_EXPIRY_MINUTES"}}
JSON_WEB_TOKEN_SECRET='{{getenv "JSON_WEB_TOKEN_SECRET"}}'
JSON_WEB_TOKEN_LIMIT_EXPIRY_REFRESH='{{getenv "JSON_WEB_TOKEN_LIMIT_EXPIRY_REFRESH"}}'
Expand Down
11 changes: 7 additions & 4 deletions src/features/device-types/device-types-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
DEVICE_TYPES_CACHE_LOCAL_TIMEOUT,
DEVICE_TYPES_CACHE_TIMEOUT,
CONTRACT_ALLOWLIST,
IMAGE_STORAGE_DEBUG_REQUEST_ERRORS,
} from '../../lib/config.js';

export interface DeviceTypeInfo {
Expand Down Expand Up @@ -45,10 +46,12 @@ const getFirstValidBuild = async (
try {
deviceType = await getDeviceTypeJson(slug, buildId);
} catch (err) {
captureException(
err,
`Failed to get device type build data for ${slug}/${buildId}`,
);
if (IMAGE_STORAGE_DEBUG_REQUEST_ERRORS) {
captureException(
err,
`Failed to get device type build data for ${slug}/${buildId}`,
);
}
}
if (deviceType) {
const logoUrl = await getLogoUrl(slug, buildId);
Expand Down
9 changes: 6 additions & 3 deletions src/features/device-types/storage/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IMAGE_STORAGE_ENDPOINT,
IMAGE_STORAGE_FORCE_PATH_STYLE,
IMAGE_STORAGE_SECRET_KEY,
IMAGE_STORAGE_DEBUG_REQUEST_ERRORS,
} from '../../../lib/config.js';

export const getKey = (...parts: string[]): string => parts.join('/');
Expand Down Expand Up @@ -68,9 +69,11 @@ function isUnauthenticatedError(
}

function logUnauthenticated(pathS3: string, err: any): void {
console.warn(
`${err.code} (${err.statusCode}): ${pathS3} belongs to a private device type or has incorrect permissions`,
);
if (IMAGE_STORAGE_DEBUG_REQUEST_ERRORS) {
console.warn(
`${err.code} (${err.statusCode}): ${pathS3} belongs to a private device type or has incorrect permissions`,
);
}
}

async function getFileInfo(s3Path: string) {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ export const IMAGE_STORAGE_FORCE_PATH_STYLE = boolVar(
'IMAGE_STORAGE_FORCE_PATH_STYLE',
false,
);
export const IMAGE_STORAGE_DEBUG_REQUEST_ERRORS = boolVar(
'IMAGE_STORAGE_DEBUG_REQUEST_ERRORS',
// Default to false for unauthenticated setups, so that we reduce
// the number of expected unauthorized request errors that get logged.
IMAGE_STORAGE_ACCESS_KEY != null || IMAGE_STORAGE_SECRET_KEY != null,
);
export const JSON_WEB_TOKEN_EXPIRY_MINUTES = intVar(
'JSON_WEB_TOKEN_EXPIRY_MINUTES',
);
Expand Down
Loading