-
Notifications
You must be signed in to change notification settings - Fork 427
[DRAFT]: feat: use pooled http transport for grafana client #1982
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Draft
eyazici90
wants to merge
9
commits into
grafana:master
Choose a base branch
from
eyazici90:local/pool-client
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c3d5cb
feat: use pooled http transport for grafana client
eyazici90 afc8f14
chore: keep using default transport for instrumentedroundtripper
eyazici90 b3a86c4
chore: convert grafanaAdminCreds to value semantic
eyazici90 e6846ca
chore: remove duplicated func in the pkg
eyazici90 30fe158
refactor: inline sny.cMap usage for generated grafana client
eyazici90 3ff0800
test: add a simple benchmark for NewGeneratedGrafanaClient
eyazici90 1792da1
fix: use pooling for transit structs instead of complete gen-grafana-…
eyazici90 a0db739
chore: wrap defer explicitly to avoid some weird bug
eyazici90 d40d632
chore: add errnocheck s for linting
eyazici90 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/grafana/grafana-operator/v5/api/v1beta1" | ||
v1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type fakeClient struct { | ||
client.Client | ||
} | ||
|
||
func (c fakeClient) Get(_ context.Context, _ client.ObjectKey, ref client.Object, _ ...client.GetOption) error { | ||
s := ref.(*v1.Secret) //nolint:errcheck | ||
s.Data = map[string][]byte{ | ||
"fake": []byte("something"), | ||
} | ||
return nil | ||
} | ||
|
||
func Benchmark_GenGrafanaClient(b *testing.B) { | ||
ctx := context.TODO() | ||
var ( | ||
fc fakeClient | ||
grf = &v1beta1.Grafana{ | ||
Spec: v1beta1.GrafanaSpec{ | ||
External: &v1beta1.External{ | ||
APIKey: &v1.SecretKeySelector{ | ||
LocalObjectReference: v1.LocalObjectReference{ | ||
Name: "secret", | ||
}, | ||
Key: "fake", | ||
}, | ||
TLS: &v1beta1.TLSConfig{ | ||
InsecureSkipVerify: true, | ||
}, | ||
}, | ||
}, | ||
Status: v1beta1.GrafanaStatus{ | ||
AdminURL: "https://grafana.example.com", | ||
}, | ||
} | ||
) | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
cl, err := NewGeneratedGrafanaClient(ctx, fc, grf) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
if cl == nil { | ||
b.Fatal("client is nil") | ||
} | ||
} | ||
} |
This file contains hidden or 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.
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.
This is coming from a limited understanding of
sync.Pool
, so take it with some salt.But this
defer
looks "off".Every example I see for using
sync.Pool
always finishes the work before returning the object to the pool.But here the object is returned to the pool before the client and the containing transports are used.
Could another Goroutine
Get()
thehttpTransport
andcfg
during a preemption outside ofNewGeneratedGrafanaClient
and overwrite both?We have multiple controllers making more than one request during a single reconcile resulting in a lot of preemption opportunities.
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.
Very good point. Thanks for noticing that. I reckon, I didn't completely check the control flows and solely focused on my use case. Which was
maxConcurrentReconcilation:1
for datasources that was simply serialized execution 🤦I totally forgot about we can set
maxConcurrentReconcilation
to more or even different control flows from diff resources here.I will go for a long weekend vacation and will work on this pooling(sync.Pool) more seriously(not the part for http transport that is pretty much necessary) when I back. Will ping u later on.
Thank u so much for spending ur time on the review, appreciated 🙏