-
Notifications
You must be signed in to change notification settings - Fork 369
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
[faucet] Add custom metrics #1143
Merged
Merged
Changes from all commits
Commits
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
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,52 @@ | ||
import { Logging } from '@google-cloud/logging' | ||
|
||
// See https://firebase.google.com/docs/functions/config-env | ||
const ProjectID = process.env.GCLOUD_PROJECT || 'celo-faucet' | ||
|
||
const logging = new Logging({ | ||
projectId: ProjectID, | ||
}) | ||
const log = logging.log('faucetMetrics') | ||
|
||
const METADATA = { | ||
resource: { | ||
labels: { | ||
function_name: 'faucetMetrics', | ||
project_id: ProjectID, | ||
region: 'us-central1', | ||
}, | ||
type: 'cloud_function', | ||
}, | ||
} | ||
|
||
export enum ExecutionResult { | ||
Ok = 'Ok', | ||
/** Enqued Faucet Request has invalid type */ | ||
InvalidRequestErr = 'InvalidRequestErr', | ||
/** Failed to obtain a free acount to faucet from */ | ||
NoFreeAccountErr = 'NoFreeAccountErr', | ||
/** Faucet Action timed out */ | ||
ActionTimedOutErr = 'ActionTimedOutErr', | ||
OtherErr = 'OtherErr', | ||
} | ||
|
||
/** | ||
* Sends an entry but doesn't block | ||
* (we don't want to block waiting for a metric to be sent) | ||
*/ | ||
function noBlockingSendEntry(entryData: Record<string, any>) { | ||
const entry = log.entry(METADATA, entryData) | ||
log.write(entry).catch((err: any) => { | ||
console.error('EventLogger: error sending entry', err) | ||
}) | ||
} | ||
|
||
export function logExecutionResult(snapKey: string, result: ExecutionResult) { | ||
noBlockingSendEntry({ | ||
event: 'celo/faucet/result', | ||
executionResult: result, | ||
failed: result !== ExecutionResult.Ok, | ||
snapKey, | ||
message: `${snapKey}: Faucet result was ${result}`, | ||
}) | ||
} |
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.
So of course we do not have any standardization so to speak, but I generally would prefer for us not to directly log to GCP. Instead, GCP already aggregates the logs for us from STDOUT/STDERR and deals with doing so in a performant manner, batch, etc.
It also avoids us having to configure the client below, give the appropriate labels like project/region, and many more useful information such as execution id, severity etc.
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.
In general, I agree. But this is different.
The reason I'm using this library is to create my own
LogEntry
for stackdriver.See that I'm using:
See the screenshot of an actual log:
This allow to easily create new metric with metric labels using structured fields.