-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 inpkg/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 inQueriesMetrics
. 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:
Length of output: 308
Tools
GitHub Check: codecov/patch
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!