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

[CORE-354] - Add tracking for market availability in order to alert in datadog #706

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

clemire
Copy link
Contributor

@clemire clemire commented Oct 25, 2023

Changelist

Track availability of market symbols in each exchange for alerting purposes.

Test Plan

Existing tests, this is a telemetry change.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

@linear
Copy link

linear bot commented Oct 25, 2023

CORE-354 monitor unavailable symbols from exchanges

once this is done, we can reduce sensitivity of Pricefeed daemon encoder failed to encode for reasons that could not be traced to an exchange alert.

see thread

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2023

Walkthrough

The changes introduce telemetry tracking for market availability on exchanges in the price fetcher daemon. A new function emitMarketAvailabilityMetrics is added to emit these metrics. The runSubTask function is updated to call this new function. New constants related to these metrics are also added.

Changes

File Path Summary
.../pricefeed/client/price_fetcher/price_fetcher.go Introduced a new function emitMarketAvailabilityMetrics for telemetry tracking of market availability. Updated runSubTask function to call this new function. Added import statements for telemetry and random number generation.
.../lib/metrics/constants.go Added new constants PriceFetcherQueryForMarket and AvailableMarketsSampleRate. Updated the value of LatencyMetricSampleRate.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f1c7a9d and e29a863.
Files selected for processing (2)
  • protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go (4 hunks)
  • protocol/lib/metrics/constants.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go
  • protocol/lib/metrics/constants.go

pf.writeToBufferedChannel(exchangeId, price, err)
}

// Emit metrics on this exchange's market availability.
for marketId, available := range availableMarkets {
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding what is the cadence of this logic? Is it per runSubTask run? How often is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's run once every time a price fetcher makes a query.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e29a863 and e02ca60.
Files selected for processing (1)
  • protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go (4} hunks)
Additional comments: 4
protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go (4)
  • 3-9: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [6-10]

The import of the telemetry package is new. Ensure that this package is installed and available in the project dependencies.

  • 187-206: The emitMarketAvailabilityMetrics function is a new addition. It emits telemetry data about the availability of a market on an exchange. The function takes an exchange ID, market ID, and a boolean indicating availability as parameters. It uses the telemetry.IncrCounterWithLabels function to increment a counter with specific labels. This function seems to be well-structured and follows good practices.

  • 264-277: The code now emits telemetry data when a query fails. It iterates over all market IDs and calls emitMarketAvailabilityMetrics with false for availability. This is a good practice as it provides visibility into market availability during failures. However, ensure that the emitMarketAvailabilityMetrics function handles errors properly and does not cause the runSubTask function to fail.

  • 306-315: The code now tracks which markets were available when queried. It uses a map to store the availability of each market and emits telemetry data for each market. This is a good practice as it provides visibility into market availability. However, ensure that the emitMarketAvailabilityMetrics function handles errors properly and does not cause the runSubTask function to fail.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e02ca60 and fa2a274.
Files selected for processing (2)
  • protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go (4} hunks)
  • protocol/lib/metrics/constants.go (2} hunks)
Files skipped from review due to trivial changes (1)
  • protocol/lib/metrics/constants.go
Additional comments: 4
protocol/daemons/pricefeed/client/price_fetcher/price_fetcher.go (4)
  • 6-8: The new imports github.com/cosmos/cosmos-sdk/telemetry and math/rand are introduced to support telemetry metrics and random sampling respectively. Ensure that these packages are used appropriately in the code.

  • 188-207: The new function emitMarketAvailabilityMetrics is introduced to emit telemetry metrics that track the availability of a market when queried on an exchange. The function takes in exchangeId, id (marketId), and available as parameters. It uses the telemetry.IncrCounterWithLabels function from the cosmos-sdk/telemetry package to increment a counter with labels. The labels include the PricefeedDaemon, PriceFetcherQueryForMarket, and success (which can be either metrics.Success or metrics.Error depending on the available parameter). The function seems to be well-structured and logically sound.

  • 263-284: The runSubTask function is updated to include telemetry metrics. If an error occurs during the price fetching process, the function will report all markets as unavailable. It also creates a map availableMarkets to track which markets were available when queried. Ensure that these changes do not affect the overall functionality of the runSubTask function.

  • 312-323: The runSubTask function is further updated to mark a market as available in the availableMarkets map if a price is successfully fetched for it. It also emits metrics on the exchange's market availability according to the sampling rate. These changes seem to be logically sound and should improve the system's ability to monitor and alert on market availability issues.

telemetry.IncrCounterWithLabels(
[]string{
metrics.PricefeedDaemon,
metrics.PriceFetcherQueryForMarket,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: perhaps update the metrics name with a suffix like _sampled so it's clear that this is a sampled metric

@clemire clemire added the backport/protocol/v1.x Backport v1.x label Oct 26, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fa2a274 and bd0a227.
Files selected for processing (1)
  • protocol/lib/metrics/constants.go (2} hunks)
Files skipped from review due to trivial changes (1)
  • protocol/lib/metrics/constants.go

@clemire clemire merged commit eb1e497 into main Oct 26, 2023
14 of 16 checks passed
@clemire clemire deleted the crystal/CORE-354-monitor-unavailable-symbols branch October 26, 2023 20:41
mergify bot pushed a commit that referenced this pull request Oct 26, 2023
clemire added a commit that referenced this pull request Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants