smart scanner metrics

This commit is contained in:
Chase Tucker
2025-06-06 09:30:18 -07:00
parent 803f946c7e
commit ebd8b36d13
19 changed files with 551 additions and 59 deletions

View File

@ -45,9 +45,9 @@ $insert RDS_EQUATES
$insert SCAN_SETUP
Declare Function Scan_Services, Database_Services, QA_Services, Datetime, RDS_Services, SRP_Array, SRP_Stopwatch
Declare function Logging_Services, Environment_Services
Declare function Logging_Services, Environment_Services, GetTickCount
Declare Subroutine Scan_Services, Database_Services, QA_Services, obj_WO_Mat_Log, SRP_Stopwatch
Declare Subroutine Logging_Services
Declare Subroutine Logging_Services, Mona_Services
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\ScanAPI\APIResponseTime'; //Define the directory where the log will be saved to. This happens the first time of the day that the log is written to.
LogDate = Oconv(Date(), 'D4/')
@ -57,6 +57,13 @@ LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' ScanAPIResponseTimes.csv'; //Define the file name that will get created.
Headers = 'Logging DTM' : @FM : 'API' : @FM : 'ResponseTime' : @FM : 'ScanID' : @FM : 'ScanData' : @VM : 'StatusCode' ; //Define the column names in the log file, delimited by a Field Mark.
objLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$); //Actually creates the log.
IsProd = Environment_Services('IsProd')
If IsProd EQ True$ then
MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_SCANAPI'
end else
MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_SCANAPI'
end
GoToAPI else
// The specific resource endpoint doesn't have a API handler yet.
@ -72,16 +79,25 @@ Return Response OR ''
API scan.POST
StartTick = GetTickCount()
MetricName = 'SCAN_POST'
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'SCAN_POST_RESPONSE_TIME')
ScanID = Scan_Services('CreateScansRow')
If Error_Services('NoError') then
StatusCode = 201
GoSub CreateHALItem
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 500, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'CRITICAL')
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_POST_RESPONSE_TIME')
TotalPostResponseTime = SRP_Stopwatch('GetData', 'SCAN_POST_RESPONSE_TIME')
LogData = ''
@ -100,6 +116,9 @@ end api
API scan.ID.POST
StartTick = GetTickCount()
MetricName = 'SCAN_ID_POST'
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'SCAN_ID_POST_RESPONSE_TIME')
ScanID = EndpointSegment
@ -112,13 +131,20 @@ API scan.ID.POST
If Error_Services('NoError') then
StatusCode = 200
GoSub CreateHALItem
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 400, Message)
HTTP_Services('SetResponseStatus', 400, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'CRITICAL')
end
end else
HTTP_Services('SetResponseStatus', 400, 'JSON object is missing from the request.')
end
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_ID_POST_RESPONSE_TIME')
TotalPostResponseTime = SRP_Stopwatch('GetData', 'SCAN_ID_POST_RESPONSE_TIME')
LogData = ''
@ -143,11 +169,19 @@ end api
API scan.ID.HEAD
API scan.ID.GET
StartTick = GetTickCount()
MetricName = 'SCAN_ID_GET'
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'SCAN_ID_GET_RESPONSE_TIME')
ScanID = EndpointSegment
StatusCode = 200
GoSub CreateHALItem
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_ID_POST_RESPONSE_TIME')
TotalGetResponseTime = SRP_Stopwatch('GetData', 'SCAN_ID_GET_RESPONSE_TIME')
LogData = ''
@ -166,6 +200,9 @@ end api
API scan.ID.DELETE
StartTick = GetTickCount()
MetricName = 'SCAN_ID_DELETE'
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'SCAN_ID_DELETE_RESPONSE_TIME')
ScanID = EndpointSegment
@ -176,17 +213,25 @@ API scan.ID.DELETE
Database_Services('DeleteDataRow', 'SCANS', ScanID, True$, False$)
If Error_Services('NoError') then
HTTP_Services('SetResponseStatus', 200)
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 500, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'CRITICAL')
end
end else
HTTP_Services('SetResponseStatus', 403, 'This scan is already accepted and cannot be deleted.')
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 404, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_ID_DELETE_RESPONSE_TIME')
TotalDeleteResponseTime = SRP_Stopwatch('GetData', 'SCAN_ID_DELETE_RESPONSE_TIME')
LogData = ''
@ -205,7 +250,9 @@ end api
API scan.ID.PATCH
StartTick = GetTickCount()
MetricName = 'SCAN_ID_PATCH'
// This is where scans are ultimately accepted for final processing. We will need to determine which type
// of scan this is (i.e. Location, Pre-Epi + Load, or Unload). This will be determined by the data coming in and the
// current status of the lot. For example a Location scan would only have an RDS, location code, and username.
@ -232,14 +279,17 @@ API scan.ID.PATCH
If Error_Services('NoError') then
StatusCode = 200
GoSub CreateHALItem
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 500, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'CRITICAL')
end
SRP_JSON(hBody, 'Release')
end else
HTTP_Services('SetResponseStatus', 400, 'JSON object is missing from the request.')
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
end else
ScanNotAcceptableReason = SRP_JSON(objResource, 'GetValue', 'scan.notAcceptableReason')
@ -249,11 +299,17 @@ API scan.ID.PATCH
end else
Message = 'Unable to parse the JSON scan resource.'
HTTP_Services('SetResponseStatus', 400, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 404, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_ID_PATCH_RESPONSE_TIME')
TotalPatchResponseTime = SRP_Stopwatch('GetData', 'SCAN_ID_PATCH_RESPONSE_TIME')
LogData = ''
@ -272,6 +328,8 @@ end api
API scan.ID.PUT
StartTick = GetTickCount()
MetricName = 'SCAN_ID_PUT'
SRP_Stopwatch('Reset')
SRP_Stopwatch('Start', 'SCAN_ID_PUT_RESPONSE_TIME')
@ -314,17 +372,25 @@ API scan.ID.PUT
Database_Services('WriteDataRow', 'SCANS', ScanID, ScanRow, True$, False$, True$)
If Error_Services('NoError') then
GoSub CreateHALItem
Mona_Services('SendStatus', MonaResource, MetricName, 'OK')
end else
Message = Error_Services('GetMessage')
HTTP_Services('SetResponseStatus', 500, Message)
Mona_Services('SendStatus', MonaResource, MetricName, 'CRITICAL')
end
SRP_JSON(hBody, 'Release')
end else
HTTP_Services('SetResponseStatus', 400, 'Unable to parse the scanData JSON.')
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
end else
HTTP_Services('SetResponseStatus', 400, 'JSON object is missing from the request.')
Mona_Services('SendStatus', MonaResource, MetricName, 'WARNING')
end
EndTick = GetTickCount()
Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)
SRP_Stopwatch('Stop', 'SCAN_ID_PUT_RESPONSE_TIME')
TotalPutResponseTime = SRP_Stopwatch('GetData', 'SCAN_ID_PUT_RESPONSE_TIME')
LogData = ''
@ -339,7 +405,6 @@ API scan.ID.PUT
end
LogData<6> = ResponseStatusCode
Logging_Services('AppendLog', objLog, LogData, @RM, @FM, False$)
end api
@ -378,3 +443,4 @@ CreateHALItem:
end
return