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

feat: Moved sdkClient reset metrics into the metricService #3120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ebadiere
Copy link
Collaborator

Description:
Moved sdkClient reset metrics into the metricService and replaced labels with prometheus counters.

Related issue(s):

Fixes #3075

Notes for reviewer:
The old client reset counter was not used and was problematic.

Labels Are Not Meant for Numerical Data: In Prometheus, labels are designed for categorical data used to identify or group metrics (e.g., by host, region, or service). They are not intended for storing numerical data that you want to plot or perform calculations on.

Inability to Perform Calculations: Since label values are strings, you cannot perform arithmetic operations on them in Prometheus queries.

Visualization Challenges: Grafana relies on numerical data points over time to generate graphs. With the current setup, it's difficult to extract and plot the numerical values from labels.

This change replaces the labels with counters.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

labels with prometheus counters.

Signed-off-by: ebadiere <[email protected]>
@ebadiere ebadiere added the enhancement New feature or request label Oct 17, 2024
@ebadiere ebadiere added this to the 0.59.0 milestone Oct 17, 2024
@ebadiere ebadiere self-assigned this Oct 17, 2024
Copy link

sonarcloud bot commented Oct 17, 2024

Copy link

github-actions bot commented Oct 17, 2024

🚨 Memory Leak Detected 🚨

A potential memory leak has been detected in the test titled validates enforcement of request id. This may impact the application's performance and stability.

Details

📊 Memory Leak Detection Report 📊

GC Type: MarkSweepCompact
Cost: 33,318 ms

Heap Statistics (before vs after executing the test):

  • Total Heap Size: increased with 1.46 MB
  • Total Heap Size Executable: no changes
  • Total Physical Size: decreased with 348.16 KB
  • Total Available Size: increased with 3.39 MB
  • Total Global Handles Size: no changes
  • Used Global Handles Size: decreased with 64.00 bytes
  • Used Heap Size: decreased with 3.51 MB
  • Heap Size Limit: no changes
  • Malloced Memory: decreased with 41.74 KB
  • External Memory: no changes
  • Peak Malloced Memory: no changes

Heap Space Statistics (before vs after executing the test):

  • Old Space:

    • Space Size: increased with 1.84 MB
    • Space Used Size: increased with 2.01 MB
    • Space Available Size: increased with 70.77 KB
    • Physical Space Size: increased with 1.84 MB
  • Large Object Space:

    • Space Size: increased with 835.58 KB
    • Space Used Size: increased with 813.50 KB
    • Space Available Size: no changes
    • Physical Space Size: increased with 835.58 KB

Recommendations

Please investigate the memory allocations in this test, focusing on objects that are not being properly deallocated.

Copy link

Tests

       3 files     399 suites   18s ⏱️
1 433 tests 1 432 ✔️ 1 💤 0
1 442 runs  1 441 ✔️ 1 💤 0

Results for commit 3ffc3b2.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 82.85714% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.14%. Comparing base (daf2aef) to head (3ffc3b2).

Files with missing lines Patch % Lines
...ay/src/lib/services/metricService/metricService.ts 77.77% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3120      +/-   ##
==========================================
- Coverage   83.19%   83.14%   -0.05%     
==========================================
  Files          63       63              
  Lines        4242     4267      +25     
  Branches      830      830              
==========================================
+ Hits         3529     3548      +19     
- Misses        470      476       +6     
  Partials      243      243              
Flag Coverage Δ
relay 85.52% <82.85%> (-0.08%) ⬇️
server 83.48% <ø> (ø)
ws-server 36.15% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/relay/src/lib/constants.ts 92.00% <ø> (ø)
packages/relay/src/lib/relay.ts 87.14% <100.00%> (ø)
.../relay/src/lib/services/hapiService/hapiService.ts 79.31% <100.00%> (-0.69%) ⬇️
packages/relay/src/lib/types/index.ts 100.00% <100.00%> (ø)
...ay/src/lib/services/metricService/metricService.ts 86.15% <77.77%> (-6.35%) ⬇️

Copy link

Acceptance Tests

  20 files  305 suites   31m 17s ⏱️
602 tests 590 ✔️ 4 💤   8
877 runs  859 ✔️ 6 💤 12

Results for commit 3ffc3b2.

Copy link
Collaborator

@konstantinabl konstantinabl left a comment

Choose a reason for hiding this comment

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

Few comments

* @readonly
* @private
*/
private readonly hapiService: HAPIService;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This class property is not actually used so you can remove it

mirrorNodeClient: MirrorNodeClient,
hbarLimiter: HbarLimit,
register: Registry,
eventEmitter: EventEmitter,
) {
this.logger = logger;
this.sdkClient = sdkClient;
this.hapiService = hapiService;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we remove the class property this line should be removed we only need the hapiService instance to get the sdk client in the line below

mirrorNodeClient: MirrorNodeClient,
hbarLimiter: HbarLimit,
register: Registry,
eventEmitter: EventEmitter,
) {
this.logger = logger;
this.sdkClient = sdkClient;
this.hapiService = hapiService;
this.sdkClient = hapiService.getSDKClient();
Copy link
Collaborator

Choose a reason for hiding this comment

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

But do we really need this, not sure we need the metric service to depend on the sdkClient. The sdkClient is used here to get details from the transaction record in the captureTransactionMetrics. However, arent they passed when emitting the event in the sdkClient?

Copy link
Member

@quiet-node quiet-node Oct 22, 2024

Choose a reason for hiding this comment

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

This is a really good point! Perhaps we can passed the transactionRecordMetrics in when emitting the event along with other arguments, this way we can make the metric service to be independent from the sdkClient. But I guess it's gonna be out of the scope for this PR we can create a ticket for it. Great point!

@@ -220,6 +275,20 @@ export default class MetricService {
this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed, callerName, interactingEntity);
};

public incrementConsensusClientDurationResets = ({ duration }: IExecuteConsenusClientResetDurationPayload): void => {
Copy link
Member

Choose a reason for hiding this comment

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

let's try to include JSDocs for these methods

this.consensusClientResetsDuration.inc(1);
};

public incrementConsensusClientErrorResets = ({ errorCodes }: IExecuteConsenusClientResetErrorPayload): void => {
Copy link
Member

Choose a reason for hiding this comment

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

let's try to include JSDocs for these methods

this.consensusClientResetsError.inc(1);
};

public incrementConsensusClientTransactionResets = ({
Copy link
Member

Choose a reason for hiding this comment

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

let's try to include JSDocs for these methods

* @param {Registry} register
* @returns {Counter} Consensus node client reset metric
*/
private initConsensusClientResetDurationMetric(register: Registry): Counter {
Copy link
Member

Choose a reason for hiding this comment

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

The methods initConsensusClientResetDurationMetric(), initConsensusClientResetErrorCodeMetric(), and initConsensusClientResetTransactionMetric() are essentially the same. It might be better to group them into a more general method to avoid code repetition. We could place this general method in ./packages/relay/src/utils.ts, making it reusable in other areas as well.

@@ -123,6 +163,21 @@ export default class MetricService {
this.eventEmitter.on(constants.EVENTS.EXECUTE_QUERY, (args: IExecuteQueryEventPayload) => {
this.addExpenseAndCaptureMetrics(args);
});

this.eventEmitter.on(constants.EVENTS.RESET_CLIENT_DURATION, (args: IExecuteConsenusClientResetDurationPayload) => {
this.incrementConsensusClientDurationResets(args);
Copy link
Member

Choose a reason for hiding this comment

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

Also let's make sure to add tests to cover these execution

});

this.eventEmitter.on(constants.EVENTS.RESET_CLIENT_ERRORS, (args: IExecuteConsenusClientResetErrorPayload) => {
this.incrementConsensusClientErrorResets(args);
Copy link
Member

Choose a reason for hiding this comment

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

Also let's make sure to add tests to cover these execution

this.eventEmitter.on(
constants.EVENTS.RESET_CLIENT_TRANSACTIONS,
(args: IExecuteConsenusClientResetTransactionPayload) => {
this.incrementConsensusClientTransactionResets(args);
Copy link
Member

Choose a reason for hiding this comment

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

Also let's make sure to add tests to cover these execution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

Enhance the hapiService.ts the connection reset metrics to show meaningful metrics in grafana
3 participants