Skip to content
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

DPLT-1044 Expose context method for writing custom Grafana metrics #126

Merged
merged 2 commits into from
Jul 16, 2023

Conversation

morgsmccauley
Copy link
Collaborator

@morgsmccauley morgsmccauley commented Jul 13, 2023

This PR exposes a new context method (context.putMetric()) to allow writing of arbitrary metrics to CloudWatch Metrics, and eventually Grafana.

The main driver for this change is to expose the 'latest post block height lag' of the Feed Indexer. This requires comparing the latest block height in Postgres/GraphQL, to the latest block height from api.social.near. To do this we could use a scheduled Lambda, but it would be extremely tailored to this one Indexer. This PR provides the necessary tools to do this within the Feed Indexer itself.

After merging and adding the metrics writing to the Feed Indexer, I'll remove the existing scheduled Lambda which writes an incorrect block height lag.

@morgsmccauley morgsmccauley marked this pull request as ready for review July 13, 2023 00:34
@morgsmccauley morgsmccauley requested a review from a team as a code owner July 13, 2023 00:34
Copy link
Contributor

@roshaans roshaans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really neat work! The current implementation ties us to Cloud Watch logs but that is probably fine since we are still using Lambda for now, but later we most likely want to abstract it out with an interface for a more general metrics collection library like Prometheus as you mentioned.

indexer-js-queue-handler/metrics.js Show resolved Hide resolved
@@ -254,7 +254,16 @@ export default class Indexer {
},
log: async (log) => {
return await this.writeLog(functionName, block_height, log);
}
},
putMetric: (name, value) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are graphql, set, and log present in buildFunctionalContextForFunction as well as buildImperativeContextForFunction whereas the new putMetric is only present in the latter?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. We don't use the functional mode anymore. The place we would potentially resurrect it is to parallelize historical processing. That would be for a scenario where we want to execute against blocks in parallel, accumulating mutations to be run, and then running those mutations sequentially. For that sort of disjointed processing metrics might end up weird.
Still, we should probably add it, or we could remove "functional" mode until it's needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add it because functional is essentially unused now.

Like you said @gabehamilton, metrics could end up weird in functional because of the deferred execution, unless there is someway to pass the timestamp directly 🤔. Probably not worth spending too much time on this though since it's not really used. Happy to remove it in a follow up PR if everyone agrees.

@morgsmccauley morgsmccauley merged commit 5a026f3 into main Jul 16, 2023
1 check passed
@morgsmccauley morgsmccauley deleted the DPLT-1044-custom-metrics branch July 16, 2023 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants