Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 3bd3752

Browse files
authored
Feature/nr 263403 nr code errors (#447)
* NR-263403 Spike3: Retrieve and display code errors without using mongodb WIP * NR-263403 Spike3: Retrieve and display code errors without using mongodb Detect codeError posts delete via stream since we don't have codeError in mongo anymore * NR-263403 Spike3: Retrieve and display code errors without using mongodb Some backward compatability * NR-263403 Spike3: Retrieve and display code errors without using mongodb Fix more backward compatability * NR-263403 Spike3: Retrieve and display code errors without using mongodb minor fixes * NR-263403 Spike3: Retrieve and display code errors without using mongodb Use attributes to access this.codeError * NR-263403 Spike3: Retrieve and display code errors without using mongodb - Restore codeErrorId * NR-263403 Spike3: Retrieve and display code errors without using mongodb - Delete unused associate_code_error * NR-263403 Spike3: Retrieve and display code errors without using mongodb - Remove TODOs that don't need to be. * NR-263403 Spike3: Retrieve and display code errors without using mongodb - Cleanup
1 parent a0073d5 commit 3bd3752

13 files changed

+223
-136
lines changed

.idea/misc.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/api_ser_js_local.xml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/api_server_js_local.xml

-38
This file was deleted.

api_server/bin/api_server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const DataCollections = {
3939
entities: require(ModuleDirectory + '/entities/entity')
4040
};
4141

42-
// establish our mongo collections, these include our DataCollections, but
42+
// establish our mongo collections, these include our DataCollections, but
4343
// may also include other collections that we speak to directly
4444
// through mongo, we don't abstract them out into DataCollections
4545
const MongoCollections = Object.keys(DataCollections).concat([
@@ -100,7 +100,7 @@ const MongoCollections = Object.keys(DataCollections).concat([
100100
await MyAPICluster.start();
101101
}
102102
catch (error) {
103-
console.error('Failed to start: ' + error); // eslint-disable-line no-console
103+
console.error('Failed to start: ', error); // eslint-disable-line no-console
104104
process.exit(1);
105105
}
106106
})();

api_server/lib/grok/grok_client.js

+41-20
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,32 @@ class GrokClient {
5353
throw this.errorHandler.error('notFound', { info: 'topmostPost' });
5454
}
5555

56-
this.codeError = await this.data.codeErrors.getById(this.topmostPost.get('codeErrorId'));
56+
const codeErrorId = this.topmostPost.get('codeErrorId');
57+
if (codeErrorId) {
58+
this.api.logger.warn(`analyzeErrorWithGrok - looking up codeError ${codeErrorId}`);
59+
this.codeError = await this.data.codeErrors.getById(codeErrorId);
60+
} else {
61+
this.newMode = true;
62+
}
5763

58-
if (!this.codeError) {
64+
if (!this.codeError && !this.topmostPost.get('errorGuid')) {
5965
// We need to find a way to send this issue back down so
6066
// the clients know there was an issue - otherwise, infinite spin.
6167
throw this.errorHandler.error('notFound', { info: 'codeError' });
6268
}
63-
this.accountId = new NerdGraphOps().accountIdFromErrorGroupGuid(this.codeError.get('objectId'));
69+
if (this.newMode) {
70+
// codeErrors passed in on request, not in mongo but we need the attributes
71+
this.codeError = { attributes: this.request.body.codeError }
72+
}
73+
// Legacy get accountId - from codeError
74+
this.accountId = this.codeError?.attributes ? this.codeError.attributes.accountId : undefined;
75+
this.api.logger.warn(`got account id ${this.accountId} from codeError `);
76+
if (!this.accountId) {
77+
// Newer method - accountId from entityGuid
78+
const errorGuid = this.topmostPost.get('errorGuid');
79+
this.api.logger.warn(`getting accountId from errorGuid ${errorGuid}`);
80+
this.accountId = new NerdGraphOps().accountIdFromErrorGroupGuid(errorGuid);
81+
}
6482

6583
const grokConversation = this.topmostPost.get('grokConversation');
6684

@@ -141,12 +159,12 @@ class GrokClient {
141159
// Store Grok response as new Post - text will be populated via streaming -> pubnub
142160
const grokResponsePost = await postCreator.createPost({
143161
forGrok: true,
144-
streamId: this.codeError.get('streamId'),
162+
streamId: this.topmostPost.get('streamId'),
145163
teamId: this.team.get('id'),
146164
text: '',
147165
promptRole: 'system',
148166
parentPostId: this.topmostPost.get('id'),
149-
codeError: this.codeError.get('id')
167+
codeError: this.codeError?.attributes?.id
150168
},
151169
{
152170
overrideCreatorId: grokUserId
@@ -197,7 +215,7 @@ class GrokClient {
197215

198216
async startNewConversation (grokUserId) {
199217
// get the last stack trace we have - text is full stack trace, split it into lines
200-
const stackTraceLines = (this.codeError.get('stackTraces') || [])
218+
const stackTraceLines = (this.codeError.attributes.stackTraces || [])
201219
.slice(-1)
202220
.pop()
203221
.text
@@ -219,7 +237,7 @@ class GrokClient {
219237
const code = this.request.body.codeBlock;
220238
const language = this.request.body.language;
221239

222-
const errorText = `${this.codeError.get('title')} ${this.codeError.get('text')}`;
240+
const errorText = `${this.codeError.attributes.title} ${this.codeError.attributes.text}`;
223241

224242
let content = '';
225243

@@ -250,15 +268,18 @@ class GrokClient {
250268
});
251269

252270
// Store Grok response as new Post - text will be populated via streaming -> pubnub
253-
const grokResponsePost = await postCreator.createPost({
254-
forGrok: true,
255-
streamId: this.codeError.get('streamId'),
256-
teamId: this.team.get('id'),
257-
text: '',
258-
promptRole: 'system',
259-
parentPostId: this.topmostPost.get('id'),
260-
codeError: this.codeError.get('id')
261-
},
271+
const targetStreamId = this.topmostPost.get('streamId');
272+
const targetParentPostId = this.topmostPost.get('id');
273+
const grokRequest = {
274+
forGrok: true,
275+
streamId: targetStreamId,
276+
teamId: this.team.get('id'),
277+
text: '',
278+
promptRole: 'system',
279+
parentPostId: targetParentPostId,
280+
codeError: this.codeError?.attributes?.id
281+
};
282+
const grokResponsePost = await postCreator.createPost(grokRequest,
262283
{
263284
overrideCreatorId: grokUserId
264285
});
@@ -518,7 +539,7 @@ class GrokClient {
518539
},
519540
extra: {
520541
topmostPostId: this.topmostPost.get('id'),
521-
codeErrorId: this.codeError.get('id'),
542+
codeErrorId: this.codeError?.attributes?.id,
522543
postId: post.get('id'),
523544
streamId: post.get('streamId'),
524545
}
@@ -530,7 +551,7 @@ class GrokClient {
530551
grokStream: {
531552
extra: {
532553
topmostPostId: this.topmostPost.get('id'),
533-
codeErrorId: this.codeError.get('id'),
554+
codeErrorId: this.codeError?.attributes?.id,
534555
postId: post.get('id'),
535556
streamId: post.get('streamId'),
536557
done: true
@@ -566,7 +587,7 @@ class GrokClient {
566587
const trackData = {
567588
event_type: 'response',
568589
account_id: this.accountId,
569-
meta_data: `item_guid: ${this.codeError.get('objectId')}`
590+
meta_data: `item_guid: ${this.topmostPost.get('errorGuid')}`
570591
};
571592

572593
await this.api.services.analytics.trackWithSuperProperties(
@@ -580,7 +601,7 @@ class GrokClient {
580601

581602
async logExceptionAndDispatch (message, postId, streamId) {
582603
const topmostPostId = this.topmostPost.get('id');
583-
const codeErrorId = this.codeError.get('id');
604+
const codeErrorId = this.codeError ? this.codeError.attributes.id : this.topmostPost.get('errorGuid');
584605

585606
const trackData = {
586607
'Parent ID': topmostPostId,

api_server/modules/posts/indexes.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// these database indexes are in place for the posts module, all fetch queries
2-
// must use one of these
2+
// must use one of these
33

44
'use strict';
55

66
module.exports = {
7-
7+
88
// WARNING -- DO NOT CHANGE OR REMOVE THIS INDEX
99
// IT IS USED BY THE OUTBOUND EMAIL SERVER, VERBATIM,
1010
// BUT WITHOUT SIGNIFICANT STRUCTURAL CHANGES TO OUR
@@ -14,7 +14,7 @@ module.exports = {
1414
teamId: 1,
1515
_id: -1
1616
},
17-
17+
1818
byParentPostId: {
1919
parentPostId: 1,
2020
_id: -1
@@ -25,5 +25,11 @@ module.exports = {
2525
},
2626
byShareIdentifiers: {
2727
shareIdentifiers: 1
28+
},
29+
byCodeErrorId: {
30+
codeErrorId: 1
31+
},
32+
byErrorGuid: {
33+
errorGuid: 1
2834
}
2935
};

api_server/modules/posts/post_attributes.js

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ module.exports = {
9494
type: 'id',
9595
description: 'ID of the code error attached to this post, if any'
9696
},
97+
errorGuid: {
98+
type: 'string',
99+
description: 'NR entity guid of the error attached to this post, if any'
100+
},
97101
grokConversation: {
98102
type: 'arrayOfObjects',
99103
description: 'The initial conversation to Grok',

0 commit comments

Comments
 (0)