This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from applandinc/refactor/options-objects
feat: Scanner are classes with named fields
- Loading branch information
Showing
10 changed files
with
78 additions
and
49 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
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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { Event } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
|
||
export default function (forbiddenLabel = 'mvc.template'): Assertion { | ||
class Options { | ||
constructor(public forbiddenLabel = 'mvc.template') {} | ||
} | ||
|
||
function scanner(options: Options = new Options()): Assertion { | ||
return Assertion.assert( | ||
'query-from-view', | ||
'Queries from view', | ||
'sql_query', | ||
(e: Event) => e.ancestors().every((e: Event) => !e.codeObject.labels.has(forbiddenLabel)), | ||
(e: Event) => | ||
e.ancestors().every((e: Event) => !e.codeObject.labels.has(options.forbiddenLabel)), | ||
(assertion: Assertion): void => { | ||
assertion.description = `SQL query from ${forbiddenLabel}`; | ||
assertion.description = `SQL query from ${options.forbiddenLabel}`; | ||
} | ||
); | ||
} | ||
|
||
export default { Options, scanner }; |
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,15 +1,21 @@ | ||
import { Event } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
|
||
export default function (timeAllowed = 1): Assertion { | ||
class Options { | ||
constructor(public timeAllowed = 1) {} | ||
} | ||
|
||
function scanner(options: Options = new Options()): Assertion { | ||
return Assertion.assert( | ||
'slow-http-server-request', | ||
'Slow HTTP server requests', | ||
'http_server_request', | ||
(e: Event) => e.elapsedTime! < timeAllowed, | ||
(e: Event) => e.elapsedTime! < options.timeAllowed, | ||
(assertion: Assertion): void => { | ||
assertion.where = (e: Event) => e.elapsedTime !== undefined; | ||
assertion.description = `Slow HTTP server request (> ${timeAllowed * 1000}ms)`; | ||
assertion.description = `Slow HTTP server request (> ${options.timeAllowed * 1000}ms)`; | ||
} | ||
); | ||
} | ||
|
||
export default { Options, scanner }; |
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,22 +1,28 @@ | ||
import { Event } from '@appland/models'; | ||
import Assertion from '../assertion'; | ||
|
||
export default function ( | ||
timeAllowed = 1, | ||
queryInclude = [/SELECT/], | ||
queryExclude = [/pg_advisory_xact_lock/] | ||
): Assertion { | ||
class Options { | ||
constructor( | ||
public timeAllowed = 1, | ||
public queryInclude = [/SELECT/i], | ||
public queryExclude = [/pg_advisory_xact_lock/] | ||
) {} | ||
} | ||
|
||
function scanner(options: Options = new Options()): Assertion { | ||
return Assertion.assert( | ||
'slow-query', | ||
'Slow SQL queries', | ||
'sql_query', | ||
(e: Event) => e.elapsedTime! < timeAllowed, | ||
(e: Event) => e.elapsedTime! < options.timeAllowed, | ||
(assertion: Assertion): void => { | ||
assertion.where = (e: Event) => | ||
e.elapsedTime !== undefined && | ||
queryInclude.some((pattern) => e.sqlQuery && e.sqlQuery.match(pattern)) && | ||
!queryExclude.some((pattern) => e.sqlQuery && e.sqlQuery.match(pattern)); | ||
assertion.description = `Slow SQL query (> ${timeAllowed * 1000}ms)`; | ||
options.queryInclude.some((pattern) => e.sqlQuery && e.sqlQuery.match(pattern)) && | ||
!options.queryExclude.some((pattern) => e.sqlQuery && e.sqlQuery.match(pattern)); | ||
assertion.description = `Slow SQL query (> ${options.timeAllowed * 1000}ms)`; | ||
} | ||
); | ||
} | ||
|
||
export default { Options, scanner }; |
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