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

chore: add QueriesMetrics test #70

Merged
merged 1 commit into from
Jun 28, 2024
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
2 changes: 1 addition & 1 deletion pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@

wg.Wait()

queriesMetrics := NewQueriesMetrics(a.Config, queryInfos)
queriesMetrics := NewQueriesMetrics(a.Config.Chains, queryInfos)

Check warning on line 195 in pkg/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/app.go#L195

Added line #L195 was not covered by tests
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 27, 2024

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Coverage Issue: Missing test coverage for the new function call.

The function NewQueriesMetrics is used consistently across the codebase. However, the new function call in pkg/app.go is not covered by tests according to the codecov report. Ensuring test coverage for this new code path is crucial for maintaining code quality and preventing future regressions.

Would you like assistance in writing the necessary tests or should I open a GitHub issue to track this task?

Analysis chain

Update: Adjust the NewQueriesMetrics call to use Chains.

The change in how NewQueriesMetrics is invoked aligns well with the structural changes in QueriesMetrics. This ensures that only the necessary data is passed to the function, enhancing modularity and reducing unnecessary dependencies.

Coverage Issue: Missing test coverage for the new function call.

The newly added line is not covered by tests according to the codecov report. It's important to ensure that all new code paths are tested to maintain high code quality and prevent future regressions.

Would you like assistance in writing the necessary tests or should I open a GitHub issue to track this task?

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new function signature is used consistently across the codebase.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'NewQueriesMetrics'

Length of output: 308

Tools
GitHub Check: codecov/patch

[warning] 195-195: pkg/app.go#L195
Added line #L195 was not covered by tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you have any learnings on app.go file regarding that?

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, currently, I don't have the capability to track or recall specific learnings from past interactions unless they are included in the immediate context of our conversation. If there are specific aspects or details about the app.go file or its functionality that you need help with, please let me know! I'm here to assist with code analysis, generating tests, or any other inquiries you might have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, I remember telling that pkg/app.go isn't tested yet and for now this okay, and it should be in one of the learnings. So that means you don't have access to it, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, you are correct. I currently don't have the capability to recall specific past interactions unless they are part of the immediate context of our conversation. However, I can add this information to my learnings right now, ensuring it is considered in future interactions. Thank you for pointing this out!

🐰


Learnings added
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#70
File: pkg/app.go:195-195
Timestamp: 2024-06-27T23:06:14.487Z
Learning: The `pkg/app.go` file isn't tested yet, and this has been acknowledged as acceptable for the current stage of development.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, you can configure the review settings to ignore specific files or paths, such as pkg/app.go, from certain checks like test coverage. This can be done through the path-based instructions feature in the configuration settings.

You can specify these instructions in your configuration file or through the UI, depending on what's supported by your integration. Here's a general guide on how to set up path-based instructions: Review Instructions.

If you need more detailed guidance or have other specific requirements, feel free to let me know!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can I configure it by communicating it with you in the comments somehow, just like I do now?

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, configuring review settings directly through comments isn't something I can process. Typically, these configurations need to be set in a configuration file or through a user interface that your code review or CI/CD system provides.

For setting up specific rules like ignoring test coverage checks for pkg/app.go, you would usually modify a YAML or JSON configuration file, or use the settings UI of the platform you're using for code reviews. If you tell me which system or tool you're using, I might be able to provide more targeted instructions on how to proceed.

Let me know if there's anything else I can help with or clarify!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can I provide a feedback about the usage of the app to its developers via comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

@freak12techno, typically, feedback to app developers is provided through designated channels such as support emails, dedicated feedback forms, or directly within the app if it supports such features. This ensures that the feedback is logged and tracked appropriately.

However, if you're looking to provide feedback in a more informal or immediate context, such as via comments in a code review or discussion thread, it's possible but not standard. You can certainly leave your comments, and the developers or maintainers can then choose to formally log and address the feedback as needed.

If there's a specific mechanism you're looking for or if you need guidance on how to set up a more structured feedback loop, feel free to let me know!

registry.MustRegister(queriesMetrics.GetMetrics(rootSpanCtx)...)

for _, generator := range a.Generators {
Expand Down
78 changes: 78 additions & 0 deletions pkg/querier_metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package pkg

import (
"context"
"main/pkg/config"
"main/pkg/types"
"testing"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)

func TestQuerierMetrics(t *testing.T) {
t.Parallel()

queryInfos := []*types.QueryInfo{
{Success: true, Chain: "chain", Duration: 2 * time.Second, URL: "url1"},
{Success: true, Chain: "chain", Duration: 4 * time.Second, URL: "url2"},
{Success: false, Chain: "chain", Duration: 6 * time.Second, URL: "url3"},
}

chains := []*config.Chain{
{Name: "chain"},
{Name: "chain2"},
}

generator := NewQueriesMetrics(chains, queryInfos)
metrics := generator.GetMetrics(context.Background())
assert.Len(t, metrics, 4)

queriesCountGauge, ok := metrics[0].(*prometheus.GaugeVec)
assert.True(t, ok)
assert.Equal(t, 2, testutil.CollectAndCount(queriesCountGauge))
assert.InDelta(t, 3, testutil.ToFloat64(queriesCountGauge.With(prometheus.Labels{
"chain": "chain",
})), 0.01)
assert.Zero(t, testutil.ToFloat64(queriesCountGauge.With(prometheus.Labels{
"chain": "chain2",
})))

queriesSuccess, ok := metrics[1].(*prometheus.GaugeVec)
assert.True(t, ok)
assert.Equal(t, 2, testutil.CollectAndCount(queriesSuccess))
assert.InDelta(t, 2, testutil.ToFloat64(queriesSuccess.With(prometheus.Labels{
"chain": "chain",
})), 0.01)
assert.Zero(t, testutil.ToFloat64(queriesSuccess.With(prometheus.Labels{
"chain": "chain2",
})))

queriesFailed, ok := metrics[2].(*prometheus.GaugeVec)
assert.True(t, ok)
assert.Equal(t, 2, testutil.CollectAndCount(queriesFailed))
assert.InDelta(t, 1, testutil.ToFloat64(queriesFailed.With(prometheus.Labels{
"chain": "chain",
})), 0.01)
assert.Zero(t, testutil.ToFloat64(queriesFailed.With(prometheus.Labels{
"chain": "chain2",
})))

timings, ok := metrics[3].(*prometheus.GaugeVec)
assert.True(t, ok)
assert.Equal(t, 3, testutil.CollectAndCount(timings))
assert.InDelta(t, 2, testutil.ToFloat64(timings.With(prometheus.Labels{
"chain": "chain",
"url": "url1",
})), 0.01)
assert.InDelta(t, 4, testutil.ToFloat64(timings.With(prometheus.Labels{
"chain": "chain",
"url": "url2",
})), 0.01)
assert.InDelta(t, 6, testutil.ToFloat64(timings.With(prometheus.Labels{
"chain": "chain",
"url": "url3",
})), 0.01)
}
8 changes: 4 additions & 4 deletions pkg/queries_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
)

type QueriesMetrics struct {
Config *config.Config
Chains []*config.Chain
Infos []*types.QueryInfo
}

func NewQueriesMetrics(appConfig *config.Config, queryInfos []*types.QueryInfo) *QueriesMetrics {
func NewQueriesMetrics(chains []*config.Chain, queryInfos []*types.QueryInfo) *QueriesMetrics {
return &QueriesMetrics{
Config: appConfig,
Chains: chains,
Infos: queryInfos,
}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func (q *QueriesMetrics) GetMetrics(ctx context.Context) []prometheus.Collector
)

// so we would have this metrics even if there are no requests
for _, chain := range q.Config.Chains {
for _, chain := range q.Chains {
queriesCountGauge.With(prometheus.Labels{
"chain": chain.Name,
}).Set(0)
Expand Down
Loading