Skip to content

Commit

Permalink
Merge pull request #153 from DEFRA/BAU-remove-metrics-for-http
Browse files Browse the repository at this point in the history
BAU: remove duplicate metrics
  • Loading branch information
hughfdjackson authored Jan 24, 2025
2 parents 57a2110 + 317956d commit 753b021
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 70 deletions.
35 changes: 2 additions & 33 deletions src/server/common/controller/generic-page-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import { createLogger } from '../../helpers/logging/logger.js'
* export @interface PageController {
* handleGet: (req: Request, h: ResponseToolkit) => ResponseObject
* }
*
* export @typedef {{
* request ?: boolean;
* response ?: boolean;
* }} Metrics
*
* export @typedef {{
* get ?: Metrics;
* post ?: Metrics;
* }} MetricReports
*/

const logger = createLogger()
Expand All @@ -35,21 +25,14 @@ export default class GenericPageController {
}

getHandler(req, h) {
this.sendLog('get', 'request')
const result = this.handleGet(req, h)
this.sendLog('get', 'response')
return result
return this.handleGet(req, h)
}

postHandler(req, h) {
this.sendLog('post', 'request')
const result = this.handlePost(req, h)
this.sendLog('post', 'response')
return result
return this.handlePost(req, h)
}

/**
*
* @param {import('../../model/answer/validation.js').AnswerErrors} errors
*/
recordErrors(errors) {
Expand All @@ -59,20 +42,6 @@ export default class GenericPageController {
}

/**
*
* @param {string} method
* @param {string} event
*/
sendLog(method, event) {
const sendMetric = this.page.reportMetrics?.[method]?.[event]

if (sendMetric) {
this.logger.info(`${method}::${event}-${this.page.urlPath}`)
}
}

/**
*
* @param {string} field
* @param {string} error
*/
Expand Down
24 changes: 0 additions & 24 deletions src/server/common/controller/generic-page-controller/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ describe('#GenericPageController', () => {
expect(() => controller.postHandler()).toThrow()
})

it('should send metric on getHandler', () => {
jest.spyOn(controller, 'handleGet').mockImplementation(() => {
return 'get success'
})
const logger = jest.spyOn(controller.logger, 'info')

const metricSpy = jest.spyOn(controller, 'sendLog')
controller.getHandler()
expect(controller.sendLog).toHaveBeenCalledWith('get', 'response')
expect(metricSpy).toHaveBeenCalledTimes(2)
expect(logger).toHaveBeenCalledTimes(1)
})

it('should send metric on postHandler', () => {
jest.spyOn(controller, 'handlePost').mockImplementation(() => {
return 'get success'
})

const metricSpy = jest.spyOn(controller, 'sendLog')
controller.postHandler()
expect(controller.sendLog).toHaveBeenCalledWith('post', 'response')
expect(metricSpy).toHaveBeenCalledTimes(2)
})

afterEach(() => {
jest.clearAllMocks()
})
Expand Down
13 changes: 0 additions & 13 deletions src/server/common/model/page/page-model.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import { NotImplementedError } from '../../helpers/not-implemented-error.js'
/** @import { AnswerModel } from '../answer/answer-model.js' */
/** @import { MetricReports, Metrics } from '../../controller/generic-page-controller/index.js' */

export class Page {
/** @type {MetricReports} */
reportMetrics = {
get: {
request: false,
response: false
},
post: {
request: false,
response: false
}
}

/** @type {string} */
urlPath

Expand Down

0 comments on commit 753b021

Please sign in to comment.