-
Notifications
You must be signed in to change notification settings - Fork 4
SPKS Redis: Add extra haproxy config for metrics backends #543
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
Closed
Closed
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
76 changes: 76 additions & 0 deletions
76
pkg/comp-functions/functions/spks/spksredis/haproxy_metrics.go
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,76 @@ | ||
| package spksredis | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| xfnproto "github.com/crossplane/function-sdk-go/proto/v1" | ||
| helmv1beta1 "github.com/vshn/appcat/v4/apis/helm/release/v1beta1" | ||
| spksv1alpha1 "github.com/vshn/appcat/v4/apis/syntools/v1alpha1" | ||
| "github.com/vshn/appcat/v4/pkg/comp-functions/functions/common" | ||
| "github.com/vshn/appcat/v4/pkg/comp-functions/runtime" | ||
| ) | ||
|
|
||
| func HaproxyMetrics(ctx context.Context, comp *spksv1alpha1.CompositeRedisInstance, svc *runtime.ServiceRuntime) *xfnproto.Result { | ||
| err := svc.GetObservedComposite(comp) | ||
| if err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("failed to parse composite: %w", err)) | ||
| } | ||
|
|
||
| release := &helmv1beta1.Release{} | ||
| err = svc.GetDesiredComposedResourceByName(release, redisRelease) | ||
| if err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("cannot get redis release from desired iof: %w", err)) | ||
| } | ||
|
|
||
| values, err := common.GetReleaseValues(release) | ||
| if err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("cannot parse release values from desired release: %w", err)) | ||
| } | ||
|
|
||
| haproxyExtraConfig := fmt.Sprintf(` | ||
| backend filterproxy | ||
| mode http | ||
| http-request set-query namespace=%s | ||
| server filter exporter-filterproxy.syn-exporter-filterproxy.svc.cluster.local:8080 | ||
|
|
||
| frontend redisMetrics | ||
| mode http | ||
| bind *:9090 | ||
| option httplog | ||
| use_backend redis-node-metrics-0 if { path_beg /redis/0 } | ||
| use_backend redis-node-metrics-1 if { path_beg /redis/1 } | ||
| use_backend redis-node-metrics-2 if { path_beg /redis/2 } | ||
| use_backend filterproxy | ||
|
|
||
| backend redis-node-metrics-0 | ||
| mode http | ||
| http-request set-path /metrics | ||
| server node-0 redis-announce-0:9121 init-addr none check | ||
| backend redis-node-metrics-1 | ||
| mode http | ||
| http-request set-path /metrics | ||
| server node-1 redis-announce-1:9121 init-addr none check | ||
| backend redis-node-metrics-2 | ||
| mode http | ||
| http-request set-path /metrics | ||
| server node-2 redis-announce-2:9121 init-addr none check`, comp.GetName()) | ||
|
|
||
| if err := common.SetNestedObjectValue(values, []string{"haproxy", "extraConfig"}, haproxyExtraConfig); err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("cannot set helm values: %w", err)) | ||
| } | ||
|
|
||
| vb, err := json.Marshal(values) | ||
| if err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("cannot marshal release values: %w", err)) | ||
| } | ||
|
|
||
| release.Spec.ForProvider.Values.Raw = vb | ||
|
|
||
| if err := svc.SetDesiredComposedResourceWithName(release, redisRelease); err != nil { | ||
| return runtime.NewFatalResult(fmt.Errorf("cannot set new release: %w", err)) | ||
| } | ||
|
|
||
| return 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.
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.
Couldn't we just do this with a string format PnT patch? https://docs.crossplane.io/latest/guides/function-patch-and-transform/#string-format
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes but that would result in a huge unreadable patch. Would you prefer doing it with pnt patch?
Uh oh!
There was an error while loading. Please reload this page.
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.
We could build the patch via Jsonnet, so only when it's rendered out it's not readable.
I would prefer to minimize the amount of comp functions for SPKS and only use it if there's no other way. Because the comp functions add another layer of complexity.
But let's see what @mdnix and @zugao think.
Uh oh!
There was an error while loading. Please reload this page.
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.
I thought we decided on that, we use comp-functions for SPKS only when necessary, we keep PnT as base as it used to be!
Update: One thing that I am investigating with our comp function architecture is to get out all the code that we can be configured either with project syn or another configuration manager such as KCL. So this approach here might be true for our appcat comp-functions as well.
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.
Ok. Thanks for the input. I'll close this PR as I've integrated this logic directly into PnT.