mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-17 17:44:09 +01:00
feat: retain bounded failed-request reproduction context
This commit is contained in:
1 parent
3a1d013b11
commit
5dbf3e7829
22 files changed
+198
-67
No files matched your search
@@ -35,8 +35,8 @@ for_each(["errorStack", "causeStack"]) -> |_index, key| {
|
||||
if is_string(value) && length(string!(value)) <= 1024 {
|
||||
frames = []
|
||||
for_each(split(string!(value), "\\n", limit: 9)) -> |index, frame| {
|
||||
parts, err = parse_regex(frame, r'^at (?P<function>[A-Za-z_$][A-Za-z0-9_$]*|<anonymous>) \\((?P<file>(?:src|build)/[A-Za-z0-9_/-]+\\.(?:ts|js)):(?P<line>[1-9][0-9]{0,5}):(?P<column>[1-9][0-9]{0,4})\\)$')
|
||||
allowed = get(source_functions, [to_string(parts.file)]) ?? []
|
||||
parts, err = parse_regex(frame, r'^at (?P<function>[A-Za-z_$][A-Za-z0-9_$]*|<anonymous>) \\((?P<file>(?:src|build)/[A-Za-z0-9_./-]+\\.(?:ts|js)):(?P<line>[1-9][0-9]{0,5}):(?P<column>[1-9][0-9]{0,4})\\)$')
|
||||
allowed = array(get(source_functions, [to_string(parts.file)]) ?? null) ?? []
|
||||
if index < 8 && err == null && includes(array!(allowed), parts.function) { frames = push(frames, frame) }
|
||||
}
|
||||
if length(frames) > 0 { out = set!(out, [key], join!(frames, "\\n")) }
|
||||
|
||||
@@ -25,7 +25,7 @@ app.use('/api', async (req, res) => {
|
||||
{service:'streamer',module:'download',event:'request_aborted',severity:'warn',requestId:id},
|
||||
{service:'api',module:'route',event:'request_failed',errorCode:'repository_unavailable',severity:'error',status:503,requestId:id},
|
||||
];
|
||||
if (scenario === 'diagnostics') samples = [{service:'api',module:'route',event:'application_log',severity:'error',httpStatus:500,requestId:id,method:'GET',route:'/api/repo/:repoId/file/:path',errorType:'TypeError',errorStack:'at printError (build/server/routes/route-utils.js:200:7)\nat <anonymous> (build/server/routes/repository-public.js:312:11)',causeType:'RangeError',causeStack:'at <anonymous> (build/core/repository.js:410:9)'},{service:'api',module:'requests',event:'request_completed',severity:'info',status:500,requestId:id,method:'GET',route:'/api/repo/:repoId/file/:path',ms:283}];
|
||||
if (scenario === 'diagnostics') samples = [{service:'api',module:'route',event:'application_log',severity:'error',httpStatus:500,requestId:id,method:'GET',route:'/api/repo/:repoId/file/:path',repoId:'demo-123',requestPath:'/api/repo/demo-123/file/docs/reproduce%20issue.md',errorType:'TypeError',errorStack:'at printError (build/server/routes/route-utils.js:200:7)\nat <anonymous> (build/server/routes/repository-public.js:312:11)',causeType:'RangeError',causeStack:'at <anonymous> (build/core/repository.js:410:9)'},{service:'api',module:'requests',event:'request_completed',severity:'info',status:500,requestId:id,method:'GET',route:'/api/repo/:repoId/file/:path',ms:283}];
|
||||
if (scenario === 'occurrences') samples = Array.from({length:50}, (_,i) => ({service:'api',module:'route',event:'application_log',severity:'error',httpStatus:500,requestId:id,...(i%2?{method:'GET',route:'/api/repo/:repoId/file/:path'}:{})}));
|
||||
if (scenario === 'many') samples = Array.from({length:50}, (_,i) => ({...samples[i%4],errorCode:'synthetic_event_'+(i+1)}));
|
||||
if (req.path === '/admin/errors/investigation') return res.json({state:scenario === 'unreachable' ? 'unreachable' : scenario === 'disabled' ? 'disabled' : scenario === 'empty' ? 'empty':'ready',window:req.query.window||'1h',start,end:scenario==='stale'?start:now,captured:['disabled','unreachable','empty'].includes(scenario)?0:samples.reduce((sum,_,i)=>sum+[18,9,5,2][i%4],0),groups:['disabled','unreachable','empty'].includes(scenario)?[]:samples.map((sample,i)=>({fingerprint:String(i),sample:{...sample,release:'abcdef1234567'},count:[18,9,5,2][i%4],first:start,last:now})),telemetry:{missing:[],instances:[{service:'api',instance:'synthetic-api',last:now,dropped:0}],collector:{state:'reachable',dropped:0}}});
|
||||
|
||||
@@ -71,17 +71,25 @@ const sleep = ms => new Promise(resolve=>setTimeout(resolve,ms));
|
||||
try { requestRoute(null,'api'); } catch (failure) { error=failure; } // real synthetic TypeError in application code
|
||||
assert(error instanceof TypeError);
|
||||
error.message='https://user:'+secret+'@example.test/private?token='+secret;
|
||||
error.cause=new RangeError(secret);error.cause.stack=error.stack;
|
||||
const diagnostic=logContext.run({requestId:diagnosticId,route:'/api/repo/:repoId/file/:path',method:'GET'},()=>logRecord('error','route',['', {...serializeError(error),httpStatus:500}]));
|
||||
error.stack+='\n at async '+require('node:path').resolve('src/server/routes/repository-public.ts')+':224:23';
|
||||
error.cause=new RangeError(secret);error.cause.stack='RangeError: '+secret+'\n at '+require('node:path').resolve('src/core/model/owner-alert-lifecycle.schema.ts')+':12:3';
|
||||
const diagnostic=logContext.run({requestId:diagnosticId,requestPath:'/api/repo/demo-123/file/docs/reproduce%20issue.md',route:'/api/repo/:repoId/file/:path',method:'GET'},()=>logRecord('error','route',['', {...serializeError(error),httpStatus:500}]));
|
||||
const rawSource={file:'/host/docker/fixture/log.json',message:JSON.stringify({attrs:{tag:'api'},log:JSON.stringify({...diagnostic,url:secret,stack:secret,errorStack:diagnostic.errorStack+'\n at '+secret+' (/private/'+secret+':1:2)'})})};
|
||||
const projected=execFileSync('docker',['run','--rm','-i','--network','none','--memory','256m',vectorImage,'vrl','-i','/dev/stdin',fs.readFileSync('deploy/logging/sanitize.vrl','utf8')+'\nencode_json(.)'],{encoding:'utf8',input:JSON.stringify(rawSource)+'\n'}).trim().split('\n').map(line=>JSON.parse(JSON.parse(line)))[0];
|
||||
assert.equal(projected.errorType,'TypeError');assert.equal(projected.causeType,'RangeError');
|
||||
assert.equal(projected.requestPath,diagnostic.requestPath);assert.equal(projected.repoId,'demo-123');assert.equal(projected.errorType,'TypeError');assert.equal(projected.causeType,'RangeError');
|
||||
assert.equal(projected.causeStack,'at <anonymous> (src/core/model/owner-alert-lifecycle.schema.ts:12:3)');
|
||||
assert(projected.errorStack.includes('at <anonymous> (src/server/routes/repository-public.ts:224:23)'));
|
||||
assert.match(projected.errorStack,/at requestRoute \(src\/core\/request-monitoring.ts:\d+:\d+\)/);
|
||||
assert(!JSON.stringify(projected).includes(secret));
|
||||
const invalidPaths=['/api/repo/demo-123/file/a?token='+secret,'/api/repo/demo-123/file/%0a'+secret,'/api/repo/demo-123/file/../'+secret,'/api/repo/demo-123/file/%252e%252e/'+secret,'https://user:'+secret+'@example.test/file'];
|
||||
const invalidSources=invalidPaths.map(requestPath=>({...rawSource,message:JSON.stringify({attrs:{tag:'api'},log:JSON.stringify({...diagnostic,requestPath,errorStack:'at <anonymous> (src/core/model/private.schema.ts:1:2)'})})}));
|
||||
const rejected=execFileSync('docker',['run','--rm','-i','--network','none','--memory','256m',vectorImage,'vrl','-i','/dev/stdin',fs.readFileSync('deploy/logging/sanitize.vrl','utf8')+'\nencode_json(.)'],{encoding:'utf8',input:invalidSources.map(JSON.stringify).join('\n')+'\n'}).trim().split('\n').map(line=>JSON.parse(JSON.parse(line)));
|
||||
assert(rejected.every(row=>!row.requestPath && !row.repoId && !row.errorStack));
|
||||
assert(!JSON.stringify(rejected).includes(secret));
|
||||
const ingested=await fetch(process.env.ADMIN_LOG_URL+'/insert/jsonline?_time_field=timestamp',{method:'POST',body:JSON.stringify(projected),headers:{'Content-Type':'application/stream+json'}});assert(ingested.ok);await sleep(2000);
|
||||
const traced=await investigateLogs(logOptions({kind:'requestId',id:diagnosticId},true),true);
|
||||
const redis=safeRedisLog({ts:diagnostic.timestamp,level:'error',module:'route',raw:[diagnostic]});
|
||||
for(const row of [traced.events[0],redis.raw[0]]) {assert.equal(row.route,diagnostic.route);assert.equal(row.method,'GET');assert.equal(row.errorStack,projected.errorStack);assert.equal(row.causeType,'RangeError');assert(!JSON.stringify(row).includes(secret));}
|
||||
for(const row of [traced.events[0],redis.raw[0]]) {assert.equal(row.requestPath,diagnostic.requestPath);assert.equal(row.repoId,'demo-123');assert.equal(row.route,diagnostic.route);assert.equal(row.method,'GET');assert.equal(row.errorStack,projected.errorStack);assert.equal(row.causeType,'RangeError');assert(!JSON.stringify(row).includes(secret));}
|
||||
console.log('PASS synthetic exception logger → pinned collector → VictoriaLogs/Redis safe API with normalized route and bounded frames');
|
||||
docker('stop',name);
|
||||
const unavailable=await investigateLogs(logOptions({})); assert.equal(unavailable.state,'unreachable');
|
||||
|
||||
Reference in new issue
Block a user