Skip to content

Commit

Permalink
#89: Addressed termination due to false negative on schema validation…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
darnjo committed Apr 5, 2024
1 parent 91590e8 commit ee2e7f0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 60 deletions.
4 changes: 1 addition & 3 deletions lib/replication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ const replicate = async ({
startTimeIsoTimestamp = startTime.toISOString(),
shouldSaveResults = !!outputPath;

// TODO - add support for multiple strategies

// Each resource and expansion will have its separate set of requests
for await (const request of requests) {
const { requestUri: initialRequestUri, resourceName } = request;
Expand Down Expand Up @@ -244,7 +242,7 @@ const replicate = async ({

if (shouldGenerateReports) {
try {
if (jsonSchemaValidation && Object.values(schemaValidationResults)?.length) {
if (jsonSchemaValidation && schemaValidationResults?.errorMap?.totalErrors > 0) {
await writeSchemaValidationErrorReport(schemaValidationResults);
} else {
await writeAnalyticsReports({
Expand Down
113 changes: 56 additions & 57 deletions lib/replication/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ const processSpecialFields = ({ availabilityMap, fieldName, dateField, value } =
const isObjectOrArrayOrPrimitive = value => {
const isObject = typeof value === 'object',
isArray = Array.isArray(value),
isPrimitive = value === null || (!isObject && !isArray);
isPrimitive = value === null || !(isObject || isArray);

return {
isObject,
Expand Down Expand Up @@ -698,33 +698,33 @@ const calculateResponseStats = ({ resourceAvailabilityMap = {}, responses = [] }

const expansionStats = expansions?.length
? expansions.map(({ resourceName: expandedResourceName, ...remainingExpandedData }) => {
const expandedResponseBytes = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.responseBytes ?? [],
expandedResponseTimes = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.responseTimes ?? [],
expandedRecordCounts = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.expandedRecordCounts ?? [];

return {
resourceName: expandedResourceName,
...remainingExpandedData,

// payload size
averageResponseBytes: calculateMean(expandedResponseBytes),
medianResponseBytes: calculateMedian(expandedResponseBytes),
stdDevResponseBytes: calculateStdDev(expandedResponseBytes),

// response times
averageResponseTimeMs: calculateMean(expandedResponseTimes),
averageResponseTimeMillis: calculateMean(resourceResponseTimes) /* support old value for now */,
medianResponseTimeMs: calculateMedian(expandedResponseTimes),
stdDevResponseTimeMs: calculateStdDev(expandedResponseTimes),

// record counts
numRecordsFetched: calculateSum(resourceRecordCounts),
numExpandedRecordsFetched: calculateSum(expandedRecordCounts),

// pages fetched - expanded is the same as the parent resource
numSamples: resourcePagesFetched
};
})
const expandedResponseBytes = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.responseBytes ?? [],
expandedResponseTimes = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.responseTimes ?? [],
expandedRecordCounts = tallies?.[resourceName]?.expansions?.[expandedResourceName]?.expandedRecordCounts ?? [];

return {
resourceName: expandedResourceName,
...remainingExpandedData,

// payload size
averageResponseBytes: calculateMean(expandedResponseBytes),
medianResponseBytes: calculateMedian(expandedResponseBytes),
stdDevResponseBytes: calculateStdDev(expandedResponseBytes),

// response times
averageResponseTimeMs: calculateMean(expandedResponseTimes),
averageResponseTimeMillis: calculateMean(resourceResponseTimes) /* support old value for now */,
medianResponseTimeMs: calculateMedian(expandedResponseTimes),
stdDevResponseTimeMs: calculateStdDev(expandedResponseTimes),

// record counts
numRecordsFetched: calculateSum(resourceRecordCounts),
numExpandedRecordsFetched: calculateSum(expandedRecordCounts),

// pages fetched - expanded is the same as the parent resource
numSamples: resourcePagesFetched
};
})
: undefined;

return {
Expand Down Expand Up @@ -775,7 +775,10 @@ const createRuntimeAvailabilityStats = (resourceAvailabilityMap = {}) =>
* @param {Object} errorMap a map containing JSON Schema validation errors
*/
const writeSchemaValidationErrorReport = async (errorMap = {}) => {
if (errorMap && Object.values(errorMap)?.length) {
const {
stats: { totalErrors = 0 }
} = errorMap ?? {};
if (totalErrors > 0) {
await writeFile(SCHEMA_VALIDATION_REPORT_FILENAME, JSON.stringify(combineErrors(errorMap)));
console.log(`Schema validation errors written to: ${SCHEMA_VALIDATION_REPORT_FILENAME}`);
}
Expand All @@ -796,25 +799,21 @@ const writeAnalyticsReports = async ({ version, serviceRootUri, replicationState
// write responses report
await writeFile(
AVAILABILITY_RESPONSES_FILENAME,
JSON.stringify(
{
description: 'RESO Data Availability Responses',
version,
generatedOn,
serviceRootUri,
responses: REPLICATION_STATE_SERVICE.getResponses().map(({ requestUri, ...otherResponseInfo }) => {
return {
requestUri: requestUri.replace(serviceRootUri, ''),
...otherResponseInfo
};
})
},
null,
' '
)
JSON.stringify({
description: 'RESO Data Availability Responses',
version,
generatedOn,
serviceRootUri,
responses: REPLICATION_STATE_SERVICE.getResponses().map(({ requestUri, ...otherResponseInfo }) => {
return {
requestUri: requestUri.replace(serviceRootUri, ''),
...otherResponseInfo
};
})
})
);

console.log(`Response info written to ${AVAILABILITY_REPORT_FILENAME}`);
console.log(`Response info written to ${AVAILABILITY_RESPONSES_FILENAME}`);

// write DA report
await writeFile(
Expand Down Expand Up @@ -1086,11 +1085,11 @@ const createRequestFromParameters = ({ serviceRootUri, resourceName, expansions
const expansionInfo =
expansions && expansions?.length
? expansions.map(fieldName => {
return {
fieldName
/* TODO: look up type info from reference metadata, when possible */
};
})
return {
fieldName
/* TODO: look up type info from reference metadata, when possible */
};
})
: undefined;

return {
Expand Down Expand Up @@ -1212,9 +1211,9 @@ const buildRequestUrlString = ({
preparedFilter =
$filter && $filter?.length
? $filter
.split('and')
.flatMap(part => (part?.includes(timestampField) ? [] : part.trim()))
.join(' and ')
.split('and')
.flatMap(part => (part?.includes(timestampField) ? [] : part.trim()))
.join(' and ')
: null;

return new URL(
Expand All @@ -1228,9 +1227,9 @@ const buildRequestUrlString = ({
preparedFilter =
$filter && $filter?.length
? $filter
.split('and')
.flatMap(part => (part?.includes(timestampField) ? [] : part.trim()))
.join(' and ')
.split('and')
.flatMap(part => (part?.includes(timestampField) ? [] : part.trim()))
.join(' and ')
: null;

return new URL(
Expand Down

0 comments on commit ee2e7f0

Please sign in to comment.