-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/51974 ps report logging (#2162)
* start building out components * build out message generator * implement log generator * implement writer * use existing blob service and enhance it * renames * create orchestrator * fixes after testing * add cleanup for queue messages * implement log levels * log levels as string union instead of enum * implement into list schools function * working version * inject ps report logger into all ps functions * changes needed to write in batches and append due to volume constraints * working version with blob append * opt for receive and delete mode due to performance considerations * remove comment * rename method * set schedule * docs * info Co-authored-by: Mohsen Qureshi <[email protected]>
- Loading branch information
1 parent
c15ce57
commit 4e5de6d
Showing
38 changed files
with
758 additions
and
42 deletions.
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
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,13 @@ | ||
# util-gen-ps-report-logs | ||
|
||
generates fake log messages onto the `ps-report-log` service bus queue for the purpose of testing the log writer function (ps-report-log-writer). | ||
|
||
You can override the default message count by providing the following request body in `JSON`... | ||
|
||
``` | ||
{ | ||
messageCount: 100000 | ||
} | ||
``` | ||
|
||
Execute a `HTTP GET` at http://localhost:7071/api/util-gen-ps-report-logs to invoke the util function. |
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,21 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"authLevel": "function", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get" | ||
] | ||
}, | ||
{ | ||
"direction": "out", | ||
"type": "serviceBus", | ||
"name": "psReportLogQueue", | ||
"queueName": "ps-report-log", | ||
"connection": "AZURE_SERVICE_BUS_CONNECTION_STRING" | ||
} | ||
], | ||
"scriptFile": "../dist/functions/util-gen-ps-report-logs/index.js" | ||
} |
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
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
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,15 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "psReport5LogWriter", | ||
"type": "timerTrigger", | ||
"direction": "in", | ||
"timerDescription": "{second} {minute} {hour} {day} {month} {day-of-week}", | ||
"dev-schedule": "0 */5 * * * *", | ||
"prod-schedule": "0 0 7 * * 3", | ||
"prod-description": "Every Wednesday at 7am", | ||
"schedule": "0 0 7 * * 3" | ||
} | ||
], | ||
"scriptFile": "../dist/functions-ps-report/ps-report-5-log-writer/index.js" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ILogger } from './logger' | ||
|
||
/** | ||
* @description same signature as Azure Function ContextBindings | ||
*/ | ||
export interface IContextBindingsLike { | ||
[name: string]: any | ||
} | ||
|
||
/** | ||
* @description Azure Function Context Like object that supports members required | ||
* by the Ps Report Logger | ||
*/ | ||
export interface IContextLike { | ||
bindings: IContextBindingsLike | ||
log: ILogger | ||
} |
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
17 changes: 17 additions & 0 deletions
17
tslib/src/functions-ps-report/common/ps-report-log-entry.ts
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,17 @@ | ||
import moment from 'moment' | ||
|
||
export interface IPsReportLogEntry { | ||
message: string | ||
level: PsReportLogLevel | ||
source: PsReportSource | ||
generatedAt: moment.Moment | ||
} | ||
|
||
export enum PsReportSource { | ||
SchoolGenerator = 'ps-report-1-list-schools', | ||
PupilGenerator = 'ps-report-2-pupil-data', | ||
Transformer = 'ps-report-3-transformer', | ||
Writer = 'ps-report-4-writer' | ||
} | ||
|
||
export type PsReportLogLevel = 'info' | 'warning' | 'verbose' | 'error' |
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,51 @@ | ||
import moment from 'moment' | ||
import { IContextLike } from '../../common/ContextLike' | ||
import { ILogger } from '../../common/logger' | ||
import { PsLogEntryFormatter } from '../ps-report-5-log-writer/log-entry-formatter' | ||
import { IPsReportLogEntry, PsReportLogLevel, PsReportSource } from './ps-report-log-entry' | ||
|
||
const formatter = new PsLogEntryFormatter() | ||
|
||
export class PsReportLogger implements ILogger { | ||
private readonly context: IContextLike | ||
private readonly source: PsReportSource | ||
|
||
constructor (context: IContextLike, sourceFunction: PsReportSource) { | ||
this.context = context | ||
this.source = sourceFunction | ||
} | ||
|
||
private log (message: string, level: PsReportLogLevel): string { | ||
const entry: IPsReportLogEntry = { | ||
generatedAt: moment(), | ||
message: message, | ||
source: this.source, | ||
level: level | ||
} | ||
if (this.context.bindings.logs === undefined) { | ||
this.context.bindings.logs = [] | ||
} | ||
this.context.bindings.logs.push(entry) | ||
return formatter.formatEntry(entry) | ||
} | ||
|
||
info (message: string): void { | ||
const formatted = this.log(message, 'info') | ||
this.context.log.info(formatted) | ||
} | ||
|
||
verbose (message: string): void { | ||
const formatted = this.log(message, 'verbose') | ||
this.context.log.verbose(formatted) | ||
} | ||
|
||
warn (message: string): void { | ||
const formatted = this.log(message, 'warning') | ||
this.context.log.warn(formatted) | ||
} | ||
|
||
error (message: string): void { | ||
const formatted = this.log(message, 'error') | ||
this.context.log.error(formatted) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
tslib/src/functions-ps-report/ps-report-1-list-schools/list-schools-service.spec.ts
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
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
Oops, something went wrong.