Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

expose prometheus metrics + cloudrun compatible #24

Merged
merged 35 commits into from Dec 5, 2022

Conversation

roshaans
Copy link
Contributor

@roshaans roshaans commented Nov 17, 2022

This PR enables us to look into the performance of the micro-indexers and makes them compatible with GCP's Cloud Run service.

  • Works in Cloudrun
  • Prometheus metrics /metrics
    - Block Processing Speed
    - Latest Block Height indexed by Indexer
  • Nonblocking JSON logs

src/configs.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/metrics_server.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

Please address the comments and I'll make the review
My idealism and tediousness don't allow me to concentrate on the main things

src/configs.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
Cargo.lock Show resolved Hide resolved
Copy link
Collaborator

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

I haven't seen this in action. After you address the comments, please help @ecp88 to launch this

Cargo.toml Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/metrics_server.rs Outdated Show resolved Hide resolved
src/metrics_server.rs Outdated Show resolved Hide resolved
src/tracing_utils.rs Show resolved Hide resolved
src/metrics_server.rs Outdated Show resolved Hide resolved
src/metrics_server.rs Outdated Show resolved Hide resolved
@roshaans roshaans changed the title prometheus metrics exporter + json formatting of logs prometheus metrics exporter Nov 29, 2022
@roshaans roshaans mentioned this pull request Nov 29, 2022
1 task
@roshaans roshaans force-pushed the roshaan/prometheus-metrics-exporter branch from 8c6404c to c05f926 Compare November 29, 2022 12:05
@roshaans roshaans changed the title prometheus metrics exporter expose prometheus metrics + cloudrun compatible Nov 30, 2022
@roshaans roshaans requested review from telezhnaya and removed request for telezhnaya November 30, 2022 09:27
Copy link
Collaborator

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

Could you please re-check the messages that we already have in the PR?
E.g., this one is ignored
https://github.com/near/near-indexer-events/pull/24/files#r1031328820
After you fix the issue, please mark the message as resolved. If you doubt in the proposed solution, leave the thread unresolved and ask any questions/leave the comments in the same thread

Also, please have a look at khorolets/near-indexer-for-explorer#14 , it's better to use the same approach

@roshaans
Copy link
Contributor Author

roshaans commented Nov 30, 2022

Could you please re-check the messages that we already have in the PR? E.g., this one is ignored https://github.com/near/near-indexer-events/pull/24/files#r1031328820 After you fix the issue, please mark the message as resolved. If you doubt in the proposed solution, leave the thread unresolved and ask any questions/leave the comments in the same thread

Also, please have a look at khorolets/near-indexer-for-explorer#14 , it's better to use the same approach

Thank you @telezhnaya! I'll keep this in mind for future PRs. Unfortunately, I do not think we can use the same approach as in this PR. The Default provider searches in .aws/credentials for credential details, while we need to be able to pass in these details as environment variables so we can configure it from Cloud Run for example.

I pushed another update to this PR which hides setting up configuration details from the main.rs file. You can view that change here -> https://github.com/near/near-indexer-events/pull/24/files#r1035819281

Update: Yes we can use this approach. We just need to make sure the env variables comply with what the AWS credentials provider expects.
"The default credentials provider will also source from the environment, but it looks for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, the sourcing process is described here https://docs.aws.amazon.com/sdk-for-rust/latest/dg/credentials.html." - Morgan

@telezhnaya
Copy link
Collaborator

In this case, we have to revert khorolets/near-indexer-for-explorer#14 as well, right? We will have the same deploy process anyway
cc @morgsmccauley

src/main.rs Outdated Show resolved Hide resolved
@roshaans
Copy link
Contributor Author

In this case, we have to revert khorolets/near-indexer-for-explorer#14 as well, right? We will have the same deploy process anyway cc @morgsmccauley

Yes, that is correct

@morgsmccauley
Copy link

morgsmccauley commented Nov 30, 2022

The Default provider searches in .aws/credentials for credential details, while we need to be able to pass in these details as environment variables

@telezhnaya @roshaans The default credentials provider will also source from the environment, but note that it looks for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as described here

Copy link
Collaborator

@telezhnaya telezhnaya left a comment

Choose a reason for hiding this comment

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

Thank you for smaller set of changes!

I kindly ask you further not to ignore the comments I'm leaving. I'm waiting that you either

  • fix the issue (and try to remember the idea and not to repeat such issues further)
    OR
  • argue and explain your approach (I highly welcome this)

As any other reviewer, I feel demotivated when I have to repeat the same comments, especially in the same review at the same lines.

Dockerfile Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/configs.rs Outdated Show resolved Hide resolved
src/configs.rs Outdated Show resolved Hide resolved
src/main.rs Outdated
}

async fn handle_streamer_message(
streamer_message: near_indexer_primitives::StreamerMessage,
pool: &sqlx::Pool<sqlx::Postgres>,
) -> anyhow::Result<u64> {
metrics::BLOCK_PROCESSED_TOTAL.inc();
metrics::LATEST_BLOCK_HEIGHT.set(streamer_message.block.header.height.try_into().unwrap());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've already told you about unwrap in general and this cast in particular.
It gives unreadable error, we won't be able to investigate this in production.
Moreover, here you silently do the cast that we actually can't do because u64 could not be safely casted to i64.
I asked you to leave the comment why we have to do this, and I'm asking you again. Please be more careful to the comments in the review.

Copy link
Contributor Author

@roshaans roshaans Dec 2, 2022

Choose a reason for hiding this comment

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

I should have waited for your feedback before resolving the conversation -> #24 (comment)

I've added a comment and converted it in a way that it will propagate a meaningful error.
@morgsmccauley you might want to take care of this later
https://github.com/khorolets/near-indexer-for-explorer/blob/0bdd70e919c3781df9bf2dc900b2e2d73b5257cb/indexer/src/main.rs#L26

Copy link
Collaborator

Choose a reason for hiding this comment

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

src/metrics.rs Outdated Show resolved Hide resolved
src/metrics.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
lazy_static! {
pub static ref BLOCK_PROCESSED_TOTAL: IntCounter = try_create_int_counter(
"indexer_events_total_blocks_processed",
"Total number of blocks processed by indexer regardless of restarts. Used to calculate Block Processing Rate(BPS)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Much better, thank you!

src/main.rs Outdated Show resolved Hide resolved
@telezhnaya telezhnaya merged commit f98ca21 into main Dec 5, 2022
@roshaans roshaans deleted the roshaan/prometheus-metrics-exporter branch December 7, 2022 12:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants