-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add structured logging and Prometheus events #1767
Merged
nambrot
merged 9 commits into
master
from
nambrot/attestation-service-logging-monitoring
Nov 20, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f14365d
Add structured logging and Prometheus events
nambrot b8557da
PR comments
nambrot 616e977
Fix lint
nambrot 26e28d1
Merge branch 'master' into nambrot/attestation-service-logging-monito…
nambrot 71abe3a
Merge refs/heads/master into nambrot/attestation-service-logging-moni…
26db8d1
Merge refs/heads/master into nambrot/attestation-service-logging-moni…
8e251ee
Merge refs/heads/master into nambrot/attestation-service-logging-moni…
bc576fb
Add types
nambrot e5ef328
Merge refs/heads/master into nambrot/attestation-service-logging-moni…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
declare module 'nexmo' | ||
declare module 'express-request-id' |
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,11 +1,19 @@ | ||
import * as dotenv from 'dotenv' | ||
|
||
if (process.env.CONFIG) { | ||
dotenv.config({ path: process.env.CONFIG }) | ||
} | ||
|
||
export function fetchEnv(name: string): string { | ||
if (process.env[name] === undefined) { | ||
if (process.env[name] === undefined || process.env[name] === '') { | ||
console.error(`ENV var '${name}' was not defined`) | ||
throw new Error(`ENV var '${name}' was not defined`) | ||
} | ||
return process.env[name] as string | ||
} | ||
|
||
export function fetchEnvOrDefault(name: string, defaultValue: string): string { | ||
return process.env[name] === undefined ? defaultValue : (process.env[name] as string) | ||
return process.env[name] === undefined || process.env[name] === '' | ||
? defaultValue | ||
: (process.env[name] as string) | ||
} |
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 Logger, { createLogger, levelFromName, LogLevelString, stdSerializers } from 'bunyan' | ||
import { createStream } from 'bunyan-gke-stackdriver' | ||
import { fetchEnvOrDefault } from './env' | ||
|
||
const logLevel = fetchEnvOrDefault('LOG_LEVEL', 'info') as LogLevelString | ||
const logFormat = fetchEnvOrDefault('LOG_FORMAT', 'default') | ||
|
||
const stream = | ||
logFormat === 'stackdriver' | ||
? createStream(levelFromName[logLevel]) | ||
: { stream: process.stdout, level: logLevel } | ||
|
||
export const rootLogger: Logger = createLogger({ | ||
name: 'attestation-service', | ||
serializers: stdSerializers, | ||
streams: [stream], | ||
}) |
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,45 @@ | ||
import { Counter } from 'prom-client' | ||
|
||
export const Counters = { | ||
attestationRequestsTotal: new Counter({ | ||
name: 'attestation_requests_total', | ||
help: 'Counter for the number of attestation requests', | ||
}), | ||
attestationRequestsAlreadySent: new Counter({ | ||
name: 'attestation_requests_already_sent', | ||
help: 'Counter for the number of attestation requests that were already sent', | ||
}), | ||
attestationRequestsWrongIssuer: new Counter({ | ||
name: 'attestation_requests_wrong_issuer', | ||
help: 'Counter for the number of attestation requests that specified the wrong issuer', | ||
}), | ||
attestationRequestsWOIncompleteAttestation: new Counter({ | ||
name: 'attestation_requests_without_incomplete_attestation', | ||
help: | ||
'Counter for the number of attestation requests for which no incomplete attestations could be found', | ||
}), | ||
attestationRequestsValid: new Counter({ | ||
name: 'attestation_requests_valid', | ||
help: 'Counter for the number of requests involving valid attestation requests', | ||
}), | ||
attestationRequestsAttestationErrors: new Counter({ | ||
name: 'attestation_requests_attestation_errors', | ||
help: 'Counter for the number of requests for which producing the attestation failed', | ||
}), | ||
attestationRequestsUnableToServe: new Counter({ | ||
name: 'attestation_requests_unable_to_serve', | ||
help: 'Counter for the number of requests that could not be served', | ||
}), | ||
attestationRequestsSentSms: new Counter({ | ||
name: 'attestation_requests_sent_sms', | ||
help: 'Counter for the number of sms sent', | ||
}), | ||
attestationRequestsFailedToSendSms: new Counter({ | ||
name: 'attestation_requests_failed_to_send_sms', | ||
help: 'Counter for the number of sms that failed to send', | ||
}), | ||
attestationRequestUnexpectedErrors: new Counter({ | ||
name: 'attestation_requests_unexpected_errors', | ||
help: 'Counter for the number of unexpected errrors', | ||
}), | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this couple the service tightly with GCloud? Validators may want to host this on AWS/Azure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bunyan-gke-stackdriver
by @mcortesi is a plugin tobunyan
to create an alternatively formatted output stream, it does not require any GCP specific functionality to build/run, and can be configured withLOG_FORMAT=stackdriver
, so is opt-in