-
Notifications
You must be signed in to change notification settings - Fork 734
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
Add output for tail being in sampling mode #3146
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
Added output for tail being in "sampling mode" |
This file contains 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 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 |
---|---|---|
|
@@ -14,6 +14,7 @@ import type { | |
ScheduledEvent, | ||
AlarmEvent, | ||
EmailEvent, | ||
TailInfo, | ||
} from "../tail/createTail"; | ||
import type { RequestInit } from "undici"; | ||
import type WebSocket from "ws"; | ||
|
@@ -56,10 +57,10 @@ describe("tail", () => { | |
await runWrangler("tail durable-object--websocket--response"); | ||
expect(std.out).toMatchInlineSnapshot(`""`); | ||
expect(std.warn).toMatchInlineSnapshot(` | ||
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mBeginning log collection requires restarting the Durable Objects associated with durable-object--websocket--response. Any WebSocket connections or other non-persisted state will be lost as part of this restart.[0m | ||
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mBeginning log collection requires restarting the Durable Objects associated with durable-object--websocket--response. Any WebSocket connections or other non-persisted state will be lost as part of this restart.[0m | ||
|
||
" | ||
`); | ||
" | ||
`); | ||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
it("creates and then delete tails", async () => { | ||
|
@@ -503,10 +504,31 @@ describe("tail", () => { | |
) | ||
.replace(mockTailExpiration.toISOString(), "[mock expiration date]") | ||
).toMatchInlineSnapshot(` | ||
"Successfully created tail, expires at [mock expiration date] | ||
Connected to test-worker, waiting for logs... | ||
Email from:${mockEmailEventFrom} to:${mockEmailEventTo} size:${mockEmailEventSize} @ [mock event timestamp] - Ok" | ||
`); | ||
"Successfully created tail, expires at [mock expiration date] | ||
Connected to test-worker, waiting for logs... | ||
Email from:[email protected] to:[email protected] size:45416 @ [mock event timestamp] - Ok" | ||
`); | ||
}); | ||
|
||
it("logs tail overload message", async () => { | ||
const api = mockWebsocketAPIs(); | ||
await runWrangler("tail test-worker --format pretty"); | ||
|
||
const event = generateTailInfo(); | ||
const message = generateMockEventMessage({ event }); | ||
const serializedMessage = serialize(message); | ||
|
||
api.ws.send(serializedMessage); | ||
expect( | ||
std.out.replace( | ||
mockTailExpiration.toISOString(), | ||
"[mock expiration date]" | ||
) | ||
).toMatchInlineSnapshot(` | ||
"Successfully created tail, expires at [mock expiration date] | ||
Connected to test-worker, waiting for logs... | ||
Tail is currently in sampling mode due to the high volume of messages. To prevent messages from being dropped consider adding filters." | ||
`); | ||
}); | ||
|
||
it("should not crash when the tail message has a void event", async () => { | ||
|
@@ -675,6 +697,7 @@ function isRequest( | |
| RequestEvent | ||
| AlarmEvent | ||
| EmailEvent | ||
| TailInfo | ||
| undefined | ||
| null | ||
): event is RequestEvent { | ||
|
@@ -956,3 +979,11 @@ function generateMockEmailEvent(opts?: Partial<EmailEvent>): EmailEvent { | |
rawSize: opts?.rawSize || mockEmailEventSize, | ||
}; | ||
} | ||
|
||
function generateTailInfo(): TailInfo { | ||
return { | ||
message: | ||
"Tail is currently in sampling mode due to the high volume of messages. To prevent messages from being dropped consider adding filters.", | ||
type: "overload", | ||
}; | ||
} |
This file contains 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 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,9 +1,11 @@ | ||
import chalk from "chalk"; | ||
import { logger } from "../logger"; | ||
import type { | ||
AlarmEvent, | ||
EmailEvent, | ||
RequestEvent, | ||
ScheduledEvent, | ||
TailInfo, | ||
TailEventMessage, | ||
} from "./createTail"; | ||
import type { Outcome } from "./filters"; | ||
|
@@ -48,6 +50,10 @@ export function prettyPrintLogs(data: WebSocket.RawData): void { | |
).toLocaleString(); | ||
|
||
logger.log(`Alarm @ ${datetime} - ${outcome}`); | ||
} else if (isTailInfo(eventMessage.event)) { | ||
if (eventMessage.event.type === "overload") { | ||
logger.log(`${chalk.red.bold(eventMessage.event.message)}`); | ||
} | ||
} else { | ||
// Unknown event type | ||
const outcome = prettifyOutcome(eventMessage.outcome); | ||
|
@@ -103,6 +109,10 @@ function isAlarmEvent(event: TailEventMessage["event"]): event is AlarmEvent { | |
return Boolean(event && "scheduledTime" in event && !("cron" in event)); | ||
} | ||
|
||
function isTailInfo(event: TailEventMessage["event"]): event is TailInfo { | ||
return Boolean(event && "message" in event && "type" in event); | ||
} | ||
Comment on lines
+112
to
+114
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. Predicate Type Check, nice. |
||
|
||
function prettifyOutcome(outcome: Outcome): string { | ||
switch (outcome) { | ||
case "ok": | ||
|
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.
A lot of
else if
's starting to getting added, we may want to start thinking about the code design here.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.
Maybe a switch/reducer kind of pattern, or something to define the
event
state.