-
Notifications
You must be signed in to change notification settings - Fork 9
chore(mock-server): make ui printer optional #165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c4c368
chore(mock-server): make ui printer optional
david-luna 7585492
chore(mock-server): create file printer
david-luna c527c77
chore(mock-server): fix lint issues
david-luna 944ec3c
chore(mock-server): fix trace sorting in UI
david-luna 56d4635
chore(mock-server): add boolean option for ui
david-luna 25f2b3d
Merge branch 'main' into dluna/otlp-server-ui-optin
david-luna 324bd0d
Merge branch 'main' into dluna/otlp-server-ui-optin
david-luna 558321b
chore(mock-server): add file printer when UI is enabled
david-luna 8ef747b
Merge branch 'dluna/otlp-server-ui-optin' of github.com:elastic/elast…
david-luna a2ee356
chore(mock-server): lint fix
david-luna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# UI traces folder | ||
|
||
this folder is to place all the traces data we want to plt in the web ui. | ||
this folder is to place all the traces data we want to plot in the web ui. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,9 @@ | |
* printer.subscribe(); | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const { | ||
diagchSub, | ||
CH_OTLP_V1_LOGS, | ||
|
@@ -153,8 +156,63 @@ class JSONPrinter extends Printer { | |
} | ||
} | ||
|
||
/** | ||
* This printer converts to a possible JSON representation of each service | ||
* request and saves it to a file. **Warning**: Converting OTLP service requests to JSON is fraught. | ||
*/ | ||
class FilePrinter extends Printer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for reviewer: detaching the printer from the UI service makes sense. A possible scenario is to store traces for further analysis with other tools. Also changing the usage of |
||
constructor( | ||
log, | ||
indent, | ||
signals = ['trace'], | ||
dbDir = path.resolve(__dirname, '../db') | ||
) { | ||
super(log); | ||
this._indent = indent || 0; | ||
this._signals = signals; | ||
this._dbDir = dbDir; | ||
} | ||
printTrace(trace) { | ||
if (!this._signals.includes('trace')) return; | ||
const str = jsonStringifyTrace(trace, { | ||
indent: this._indent, | ||
normAttributes: true, | ||
}); | ||
const normTrace = JSON.parse(str); | ||
const tracesMap = new Map(); | ||
normTrace.resourceSpans.forEach((resSpan) => { | ||
resSpan.scopeSpans.forEach((scopeSpan) => { | ||
scopeSpan.spans.forEach((span) => { | ||
let traceSpans = tracesMap.get(span.traceId); | ||
|
||
if (!traceSpans) { | ||
traceSpans = []; | ||
tracesMap.set(span.traceId, traceSpans); | ||
} | ||
traceSpans.push(span); | ||
}); | ||
}); | ||
}); | ||
|
||
// Group all spans from the same trace into an ndjson file. | ||
for (const [traceId, traceSpans] of tracesMap.entries()) { | ||
const filePath = path.join(this._dbDir, `trace-${traceId}.ndjson`); | ||
const stream = fs.createWriteStream(filePath, { | ||
flags: 'a', | ||
encoding: 'utf-8', | ||
}); | ||
|
||
for (const span of traceSpans) { | ||
stream.write(JSON.stringify(span) + '\n'); | ||
} | ||
stream.close(); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
Printer, | ||
JSONPrinter, | ||
InspectPrinter, | ||
FilePrinter, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the
trace-file
"printer" be added theprinters
automatically if--ui
is specified?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One may want to open the UI just to inspect traces from past sessions but I think you question points to the case someone starting the UI but forgetting to put the printer in place, therefore not being able to se traces in the new traces UI. I think is as good point, I'll add it in the next commit