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(condo):INFRA-296 logging pipeline adjustments #4756

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
41a9f88
fix(keystone): INFRA-296 add log for every incoming request
sitozzz May 21, 2024
a6f41d6
fix(keystone): INFRA-296 move gql response log output to the last cal…
sitozzz May 21, 2024
07de979
fix(global): INFRA-296 completely disable auto-logging
sitozzz Jun 3, 2024
5e5a77d
fix(global): INFRA-296 pass request id from ingress to app & add test…
sitozzz Jun 3, 2024
a7d57f6
fix(condo): INFRA-296 try to pass nginx req_id to the app
sitozzz Jun 4, 2024
54ae7ca
fix(condo): INFRA-296 try to pass nginx req_id to the app
sitozzz Jun 4, 2024
0c6c668
fix(condo): INFRA-296 try to pass nginx req_id to the app
sitozzz Jun 4, 2024
add1a7b
fix(global): INFRA-296 try to get req.id from ingress headers
sitozzz Jun 4, 2024
60aeee9
fix(global): INFRA-296 try to increase ephemeral-storage for pg review
sitozzz Jun 5, 2024
ce8db31
fix(global): INFRA-296 try to increase ephemeral-storage for pg review
sitozzz Jun 5, 2024
80094c2
fix(global): INFRA-296 try to get req.id from ingress headers
sitozzz Jun 5, 2024
4d04a7b
fix(global): INFRA-296 try to get req.id from ingress headers
sitozzz Jun 5, 2024
38cb0c2
fix(global): INFRA-296 try to get req.id from ingress headers
sitozzz Jun 5, 2024
0012f12
fix(global): INFRA-296 try to get req.id from ingress headers
sitozzz Jun 5, 2024
e01f7c2
fix(global): INFRA-296 remove test logs
sitozzz Jun 5, 2024
1026ede
fix(global): INFRA-296 restore original app side reqId passing scenario
sitozzz Jun 5, 2024
af009aa
fix(global): INFRA-296 provide more info at gql operation timings
sitozzz Jun 6, 2024
8342c90
fix(global): INFRA-296 add initial log for gql request was received b…
sitozzz Jun 6, 2024
85f3be0
fix(global): INFRA-296 update all ingresses
sitozzz Jun 7, 2024
7fe21d5
fix(global): INFRA-296 update helm submodule to master
sitozzz Jun 7, 2024
d17e539
refactor(keystone): INFRA-296 use native rounding & rename time calcu…
sitozzz Jun 7, 2024
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 .helm
Submodule .helm updated from a151f9 to 554061
3 changes: 1 addition & 2 deletions packages/keystone/KSv5v6/v5/prepareKeystone.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const { parseCorsSettings } = require('@open-condo/keystone/cors.utils')
const { _internalGetExecutionContextAsyncLocalStorage } = require('@open-condo/keystone/executionContext')
const { IpBlackListMiddleware } = require('@open-condo/keystone/ipBlackList')
const { registerSchemas } = require('@open-condo/keystone/KSv5v6/v5/registerSchema')
const { getLogger } = require('@open-condo/keystone/logging')
const { getKeystonePinoOptions, GraphQLLoggerPlugin } = require('@open-condo/keystone/logging')
const { getKeystonePinoOptions, GraphQLLoggerPlugin, getLogger } = require('@open-condo/keystone/logging')
const { expressErrorHandler } = require('@open-condo/keystone/logging/expressErrorHandler')
const metrics = require('@open-condo/keystone/metrics')
const { schemaDocPreprocessor, adminDocPreprocessor, escapeSearchPreprocessor, customAccessPostProcessor } = require('@open-condo/keystone/preprocessors')
Expand Down
55 changes: 36 additions & 19 deletions packages/keystone/logging/GraphQLLoggerApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,50 @@ function renderExecutableDefinitionNode (node) {
return ''
}

/**
* Get current time in nanoseconds and return diff between
* @param time {bigint} start time of the operation
* @returns {number} Operation elapsed time in milliseconds
*/
function endTimer (time) {
sitozzz marked this conversation as resolved.
Show resolved Hide resolved
function roundTo (decimalPlaces, numberToRound) {
sitozzz marked this conversation as resolved.
Show resolved Hide resolved
const factorOfTen = Math.pow(10, decimalPlaces)
return +(Math.round(numberToRound * factorOfTen) / factorOfTen)
}
const diff = process.hrtime.bigint() - time
const elapsed = Number(diff) / 1000000

return roundTo(4, elapsed)
}

/**
* @type {import('apollo-server-plugin-base').ApolloServerPlugin}
*/
class GraphQLLoggerPlugin {
/**
* @param { import('apollo-server-types').GraphQLRequestContext } requestContext
* @returns {Promise<void>}
*/
requestDidStart (requestContext) {
const startTime = process.hrtime.bigint()
let timeUntilExecution = null
const requestStartTime = process.hrtime.bigint()
graphqlLogger.info({
state: 'requestDidStart',
...getGraphQLReqLoggerContext(requestContext),
})

return {
/**
* The responseForOperation event is fired immediately before GraphQL execution would take place.
* If its return value resolves to a non-null GraphQLResponse, that result is used instead of executing the query.
* Hooks from different plugins are invoked in series, and the first non-null response is used.
* @param {import('apollo-server-types').WithRequired<import('apollo-server-types').GraphQLRequestContext<TContext>, 'metrics' | 'source' | 'document' | 'operationName' | 'operation' | 'logger'>} requestContext
* @returns {Promise<import('apollo-server-types').GraphQLResponse | null>}
*/
async responseForOperation (requestContext) {
const operationId = get(requestContext, 'operationId') || cuid()
// NOTE(pahaz): log correlation id for cases where not reqId
requestContext.operationId = operationId

const logData = getGraphQLReqLoggerContext(requestContext)
graphqlLogger.info({ ...logData, responseTime: Number(process.hrtime.bigint() - startTime) / 1000000 })
},
async executionDidStart () {
timeUntilExecution = endTimer(requestStartTime)
},
async willSendResponse (requestContext) {
graphqlLogger.info({
...getGraphQLReqLoggerContext(requestContext),
responseTime: endTimer(requestStartTime),
timeUntilExecution,
state: 'willSendResponse',
})
},

/**
Expand All @@ -74,17 +92,16 @@ class GraphQLLoggerPlugin {
async didEncounterErrors (requestContext) {
const logData = getGraphQLReqLoggerContext(requestContext)
const errors = get(requestContext, 'errors', [])
const responseTime = Number(process.hrtime.bigint() - startTime) / 1000000
SavelevMatthew marked this conversation as resolved.
Show resolved Hide resolved

try {
for (const error of errors) {
error.uid = get(error, 'uid') || get(error, 'originalError.uid') || cuid()
graphqlErrorLogger.info({ apolloFormatError: safeFormatError(error), ...logData, responseTime })
graphqlErrorLogger.info({ apolloFormatError: safeFormatError(error), ...logData })
}
} catch (formatErrorError) {
// NOTE(pahaz): Something went wrong with formatting above, so we log the errors
graphqlErrorLogger.error({ formatErrorError: serializeError(ensureError(formatErrorError)), ...logData, responseTime })
graphqlErrorLogger.error({ serializedErrors: errors.map(error => serializeError(ensureError(error))), ...logData, responseTime })
graphqlErrorLogger.error({ formatErrorError: serializeError(ensureError(formatErrorError)), ...logData })
graphqlErrorLogger.error({ serializedErrors: errors.map(error => serializeError(ensureError(error))), ...logData })
}
},
}
Expand Down
5 changes: 1 addition & 4 deletions packages/keystone/logging/getKeystonePinoOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ const { getLogger } = require('./getLogger')
const { getReqLoggerContext } = require('./getReqLoggerContext')

const logger = getLogger('http')
const IGNORE_PATH = new Set(['/api/features', '/api/version', '/favicon.ico'])

function getKeystonePinoOptions () {
// NOTE(pahaz): https://github.com/pinojs/pino-http#pinohttpopts-stream
return {
logger,
autoLogging: {
ignore: (req) => IGNORE_PATH.has(req.url),
},
autoLogging: false,
customProps: (req, res) => {
return getReqLoggerContext(req)
},
Expand Down
Loading