-
Notifications
You must be signed in to change notification settings - Fork 127
Telemetry enhancement #1677
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
Open
minjieqiu
wants to merge
16
commits into
develop
Choose a base branch
from
feature/telemetry1
base: develop
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.
Open
Telemetry enhancement #1677
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
edf2618
Initial commit
minjieqiu 656737b
Add more unit tests
minjieqiu 930784e
fix test
minjieqiu 694e766
Pass test mode as false in testing
minjieqiu a01170d
fix
minjieqiu 7092e25
cleanup
minjieqiu f7c5c88
Set value for test and sokVersion
minjieqiu bcf5434
Address some comments
minjieqiu ddd3186
fix
minjieqiu d0e0f5e
Update deployment telemetry
minjieqiu 2dc1851
Fix unit test
minjieqiu 82480ef
fix
minjieqiu dc08f44
Address comment for renaming sok app and fix
minjieqiu 381df2c
fix int test
minjieqiu 0009f50
fix int test
minjieqiu 9c8dcbd
Set version in make
minjieqiu 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
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,11 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: manager-telemetry | ||
| data: | ||
| status: | | ||
| { | ||
| "lastTransmission": "", | ||
| "test": "true", | ||
| "sokVersion": "" | ||
| } |
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| resources: | ||
| - manager.yaml | ||
| - controller_manager_telemetry.yaml | ||
|
|
||
| generatorOptions: | ||
| disableNameSuffixHash: true | ||
|
|
||
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,113 @@ | ||
| /* | ||
| Copyright (c) 2026 Splunk Inc. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| enterprise "github.com/splunk/splunk-operator/pkg/splunk/enterprise" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "time" | ||
|
|
||
| metrics "github.com/splunk/splunk-operator/pkg/splunk/client/metrics" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller" | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| ) | ||
|
|
||
| const ( | ||
| // Below two contants are defined at kustomizatio*.yaml | ||
| ConfigMapNamePrefix = "splunk-operator-" | ||
| ConfigMapLabelName = "splunk-operator" | ||
|
|
||
| telemetryRetryDelay = time.Second * 600 | ||
| ) | ||
|
|
||
| type TelemetryReconciler struct { | ||
| client.Client | ||
| Scheme *runtime.Scheme | ||
| } | ||
|
|
||
| //+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch | ||
|
|
||
| func (r *TelemetryReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
| metrics.ReconcileCounters.With(metrics.GetPrometheusLabels(req, "Telemetry")).Inc() | ||
| defer recordInstrumentionData(time.Now(), req, "controller", "Telemetry") | ||
|
|
||
| reqLogger := log.FromContext(ctx) | ||
| reqLogger = reqLogger.WithValues("telemetry", req.NamespacedName) | ||
|
|
||
| reqLogger.Info("Reconciling telemetry") | ||
|
|
||
| defer func() { | ||
| if rec := recover(); rec != nil { | ||
| reqLogger.Error(fmt.Errorf("panic: %v", rec), "Recovered from panic in TelemetryReconciler.Reconcile") | ||
| } | ||
| }() | ||
|
|
||
| // Fetch the ConfigMap | ||
| cm := &corev1.ConfigMap{} | ||
| err := r.Get(ctx, req.NamespacedName, cm) | ||
| if err != nil { | ||
| if k8serrors.IsNotFound(err) { | ||
| reqLogger.Info("telemetry configmap not found; requeueing", "period(seconds)", int(telemetryRetryDelay/time.Second)) | ||
| return ctrl.Result{Requeue: true, RequeueAfter: telemetryRetryDelay}, nil | ||
| } | ||
| reqLogger.Error(err, "could not load telemetry configmap; requeueing", "period(seconds)", int(telemetryRetryDelay/time.Second)) | ||
| return ctrl.Result{Requeue: true, RequeueAfter: telemetryRetryDelay}, nil | ||
| } | ||
|
|
||
| if len(cm.Data) == 0 { | ||
| reqLogger.Info("telemetry configmap has no data keys") | ||
| return ctrl.Result{Requeue: true, RequeueAfter: telemetryRetryDelay}, nil | ||
| } | ||
|
|
||
| reqLogger.Info("start", "Telemetry configmap version", cm.GetResourceVersion()) | ||
|
|
||
| result, err := enterprise.ApplyTelemetry(ctx, r.Client, cm) | ||
| if err != nil { | ||
| reqLogger.Error(err, "Failed to send telemetry") | ||
| return ctrl.Result{Requeue: true, RequeueAfter: telemetryRetryDelay}, nil | ||
| } | ||
| if result.Requeue && result.RequeueAfter != 0 { | ||
| reqLogger.Info("Requeued", "period(seconds)", int(result.RequeueAfter/time.Second)) | ||
| } | ||
|
|
||
| return result, err | ||
| } | ||
|
|
||
| // SetupWithManager sets up the controller with the Manager. | ||
| func (r *TelemetryReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
| return ctrl.NewControllerManagedBy(mgr). | ||
| For(&corev1.ConfigMap{}). | ||
| WithEventFilter(predicate.NewPredicateFuncs(func(obj client.Object) bool { | ||
| labels := obj.GetLabels() | ||
| if labels == nil { | ||
| return false | ||
| } | ||
| return obj.GetName() == enterprise.GetTelemetryConfigMapName(ConfigMapNamePrefix) && labels["name"] == ConfigMapLabelName | ||
| })). | ||
| WithOptions(controller.Options{ | ||
| MaxConcurrentReconciles: 1, | ||
| }). | ||
| Complete(r) | ||
| } |
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,69 @@ | ||
| /* | ||
| Copyright (c) 2026 Splunk Inc. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| ) | ||
|
|
||
| var _ = Describe("Telemetry Controller", func() { | ||
| var ( | ||
| ctx context.Context | ||
| cmName = "splunk-operator-telemetry" | ||
| ns = "test-telemetry-ns" | ||
| labels = map[string]string{"name": "splunk-operator"} | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| ctx = context.TODO() | ||
| }) | ||
|
|
||
| It("Reconcile returns requeue when ConfigMap not found", func() { | ||
| builder := fake.NewClientBuilder().WithScheme(scheme.Scheme) | ||
| c := builder.Build() | ||
| r := &TelemetryReconciler{Client: c, Scheme: scheme.Scheme} | ||
| req := reconcile.Request{NamespacedName: types.NamespacedName{Name: cmName, Namespace: ns}} | ||
| result, err := r.Reconcile(ctx, req) | ||
| Expect(err).To(BeNil()) | ||
| Expect(result.Requeue).To(BeTrue()) | ||
| Expect(result.RequeueAfter).To(Equal(time.Second * 600)) | ||
| }) | ||
|
|
||
| It("Reconcile returns requeue when ConfigMap has no data", func() { | ||
| cm := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: cmName, Namespace: ns, Labels: labels}, | ||
| Data: map[string]string{}, | ||
| } | ||
| builder := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(cm) | ||
| c := builder.Build() | ||
| r := &TelemetryReconciler{Client: c, Scheme: scheme.Scheme} | ||
| req := reconcile.Request{NamespacedName: types.NamespacedName{Name: cmName, Namespace: ns}} | ||
| result, err := r.Reconcile(ctx, req) | ||
| Expect(err).To(BeNil()) | ||
| Expect(result.Requeue).To(BeTrue()) | ||
| Expect(result.RequeueAfter).To(Equal(time.Second * 600)) | ||
| }) | ||
|
|
||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.