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] Write latest near.org post block height to Grafana #112

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions indexer-js-queue-handler/latest-post-metrics-writer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fetch from "node-fetch";
import AWS from "aws-sdk";

import Metrics from "./metrics";

export const handler = async () => {
const metrics = new Metrics("QueryAPI");

const response = await fetch("https://api.near.social/index", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably helpful to handle the error and log messages accordingly. Unless if the request fails, it bubbles up just fine in the lambda function execution logs.

Copy link
Collaborator Author

@morgsmccauley morgsmccauley Jun 28, 2023

Choose a reason for hiding this comment

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

I've intentionally left these uncaught so that they all bubble up to the execution environment, and are therefore logged. The errors which are thrown from these calls should provide enough detail to debug :)

method: "POST",
body: JSON.stringify({
action: "post",
key: "main",
options: {
limit: 1,
order: "desc",
},
}),
});

const [{ blockHeight }] = await response.json();

await metrics.putBlockHeight("social.near", "posts", blockHeight);
};
4 changes: 4 additions & 0 deletions indexer-js-queue-handler/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ constructs:
timeout: 15 # 1.5 minutes as lift multiplies this value by 6 (https://github.com/getlift/lift/blob/master/docs/queue.md#retry-delay)

functions:
latestPostMetricsWriter:
handler: latest-post-metrics-writer.handler
events:
- schedule: rate(1 minute)

plugins:
- serverless-lift
Expand Down