Skip to content

Commit

Permalink
added functions.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mamari90 committed Jan 22, 2024
1 parent 59fc378 commit f744e47
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.tfstate
*.tfstate.*

.vscode

# Crash log files
crash.log
Expand Down Expand Up @@ -49,3 +48,4 @@ __*.sh
**/libs
__import_apim
/pagopa-infra.iml
/node_modules
84 changes: 81 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/functions/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bindings": [
{
"type": "timerTrigger",
"direction": "in",
"name": "timer",
"schedule": "0 * * * 8 *"
}
]
}
13 changes: 5 additions & 8 deletions src/functions/synthetic-monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ const monitoringConfiguration = [


module.exports = async function (context, myTimer) {



let tests = []
for(idx in monitoringConfiguration){
tests.push(testIt(monitoringConfiguration[idx], context).catch((error) => {
Expand Down Expand Up @@ -189,7 +186,7 @@ function telemetrySender(client, context){
context.log(`tracking api telemetry for ${metricContext.testId} : ${JSON.stringify(apiTelemetryData)}`)
client.trackAvailability(apiTelemetryData);
}

if (metricContext.certMetrics){
let certTelemetryData = enrichData(metricContext.baseTelemetryData, metricContext.certMetrics, keysForTelemetry);
context.log(`tracking cert telemetry for ${metricContext.testId}: ${JSON.stringify(certTelemetryData)}`)
Expand All @@ -206,7 +203,7 @@ function certChecker(context){
return async function checkCert(metricContext){
context.log(`checking certificate for ${metricContext.testId}? ${metricContext.monitoringConfiguration.checkCertificate}`)
let url = new URL(metricContext.monitoringConfiguration.url)

metricContext.certMetrics = {
domain: url.host,
checkCert: metricContext.monitoringConfiguration.checkCertificate
Expand All @@ -229,7 +226,7 @@ function certResponseElaborator(metricContext, context){
let validTo = new Date(certResponse.valid_to);
const millisToExpiration = validTo - Date.now();
metricContext.certMetrics['success'] = millisToExpiration > 604800000; //7 days in millis
metricContext.certMetrics['certSuccess'] =
metricContext.certMetrics['certSuccess'] =
metricContext.certMetrics['targetExpireInDays'] = Math.floor(millisToExpiration / 86400000); //convert in days
metricContext.certMetrics['targetExpirationTimestamp'] = validTo.getTime();
metricContext.certMetrics['runLocation'] = `${metricContext.monitoringConfiguration.type}-cert`
Expand Down Expand Up @@ -279,7 +276,7 @@ function apiErrorElaborator(metricContext, context){
return async function(error){
context.log(`api error for ${metricContext.testId}: ${JSON.stringify(error)}`)
let elapsedMillis = Date.now() - metricContext['startTime'];

let apiMetrics = {}
apiMetrics['message'] = error.message
apiMetrics['duration'] = elapsedMillis;
Expand Down Expand Up @@ -311,7 +308,7 @@ function extractTlsVersion(versionString){
}

}


function buildRequest(monitoringConfiguration){
let request = {
Expand Down

0 comments on commit f744e47

Please sign in to comment.