Skip to content

Commit

Permalink
chore: telemetry module tested
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Nov 6, 2023
2 parents 5dba212 + 5389b4d commit 5a6f3d5
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 20 deletions.
14 changes: 14 additions & 0 deletions api/v1alpha1/obtenant_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ func (r *OBTenant) validateMutation() error {
}
var allErrs field.ErrorList

// 0. OBCluster must exist
cluster := &OBCluster{}
err := tenantClt.Get(context.Background(), types.NamespacedName{
Namespace: r.GetNamespace(),
Name: r.Spec.ClusterName,
}, cluster)
if err != nil {
if apierrors.IsNotFound(err) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("clusterName"), r.Spec.ClusterName, "Given cluster not found"))
} else {
allErrs = append(allErrs, field.InternalError(field.NewPath("spec").Child("clusterName"), err))
}
}

// 1. Standby tenant must have a source
if r.Spec.TenantRole == constants.TenantRoleStandby {
if r.Spec.Source == nil {
Expand Down
15 changes: 14 additions & 1 deletion api/v1alpha1/obtenantbackuppolicy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ func (r *OBTenantBackupPolicy) validateBackupPolicy() error {
if r.Spec.ObClusterName == "" {
return errors.New("obClusterName is required")
}

cluster := &OBCluster{}
err := tenantClt.Get(context.Background(), types.NamespacedName{
Namespace: r.GetNamespace(),
Name: r.Spec.ObClusterName,
}, cluster)
if err != nil {
if apierrors.IsNotFound(err) {
return field.Invalid(field.NewPath("spec").Child("clusterName"), r.Spec.ObClusterName, "Given cluster not found")
}
return field.InternalError(field.NewPath("spec").Child("clusterName"), err)
}

if r.Spec.TenantName == "" && r.Spec.TenantCRName == "" {
return field.Invalid(field.NewPath("spec").Child("[tenantName | tenantCRName]"), r.Spec.TenantName, "tenantName and tenantCRName are both empty")
}
Expand Down Expand Up @@ -281,7 +294,7 @@ func (r *OBTenantBackupPolicy) validateBackupPolicy() error {
}
}

err := r.validateBackupCrontab()
err = r.validateBackupCrontab()
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions charts/oceanbase-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ monitorResource:
parameters:
- name: system_memory
value: 2G
- name: "__min_full_resource_pool_memory"
value: "2147483648" # 2G

nfsBackupEnabled: false # set true and config volume if you want to enable backup with NFS
nfsBackup:
Expand Down
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"context"
"flag"
"os"

Expand All @@ -34,6 +35,7 @@ import (
v1alpha1 "github.com/oceanbase/ob-operator/api/v1alpha1"
"github.com/oceanbase/ob-operator/pkg/controller"
"github.com/oceanbase/ob-operator/pkg/controller/config"
"github.com/oceanbase/ob-operator/pkg/telemetry"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -199,6 +201,9 @@ func main() {
os.Exit(1)
}

telem := telemetry.NewTelemetry(context.Background(), mgr.GetEventRecorderFor("ob-operator"))
telem.GenerateTelemetryRecord(nil, "Operator", "Start", "", "start ob-operator", nil)

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
6 changes: 2 additions & 4 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ spec:
image: controller:latest
name: manager
env:
# - name: TELEMETRY_DEBUG
# value: "true"
- name: TELEMETRY_SIGNATURE
value: "dbe97393a695335d67de91dd4049ba"
- name: TELEMETRY_DEBUG
value: "true"
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
4 changes: 2 additions & 2 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12637,8 +12637,8 @@ spec:
command:
- /manager
env:
- name: TELEMETRY_SIGNATURE
value: dbe97393a695335d67de91dd4049ba
- name: TELEMETRY_DEBUG
value: "true"
image: oceanbasedev/ob-operator:2.0.1-alpha.2
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion deploy/tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: t1
# namespace: oceanbase
spec:
obcluster: test
obcluster: obcluster1
tenantName: t1
unitNum: 1
charset: utf8mb4
Expand Down
2 changes: 1 addition & 1 deletion make/debug.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.PHONY: connect gettenants getpolicy getbackupjobs getcluster getobserver getrestorejobs getpods

connect:
$(eval nodeHost = $(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}'))
$(eval nodeHost = $(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}'))
ifdef TENANT
$(eval secretName = $(shell kubectl get obtenant ${TENANT} -o jsonpath='{.status.credentials.root}'))
$(eval tenantName = $(shell kubectl get obtenant ${TENANT} -o jsonpath='{.spec.tenantName}'))
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/obtenantbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type OBTenantBackupReconciler struct {
Telemetry telemetry.Telemetry

telemetryOnce sync.Once
con *operation.OceanbaseOperationManager
}

//+kubebuilder:rbac:groups=oceanbase.oceanbase.com,resources=obtenantbackups,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -272,9 +271,6 @@ func (r *OBTenantBackupReconciler) maintainRunningArchiveLogJob(ctx context.Cont
}

func (r *OBTenantBackupReconciler) getObOperationClient(ctx context.Context, job *v1alpha1.OBTenantBackup) (*operation.OceanbaseOperationManager, error) {
if r.con != nil {
return r.con, nil
}
var err error
logger := log.FromContext(ctx)
obcluster := &v1alpha1.OBCluster{}
Expand All @@ -289,7 +285,6 @@ func (r *OBTenantBackupReconciler) getObOperationClient(ctx context.Context, job
if err != nil {
return nil, errors.Wrap(err, "get oceanbase operation manager")
}
r.con = con
return con, nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/telemetry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,28 @@ See the Mulan PSL v2 for more details.
package telemetry

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/runtime"

"github.com/oceanbase/ob-operator/api/v1alpha1"
)

// Targets of sentry:
// 1. Digests IP addresses of servers
// 2. Digests NFS server address of backup volume
// 3. Remove redundant fields in status

func objectSentry(object any) {
if object == nil {
return
}

if metaObj, ok := object.(metav1.Object); ok {
// remove managed fields which are of no interest
metaObj.SetManagedFields(nil)
}

if cluster, ok := object.(*v1alpha1.OBCluster); ok {
debugWrapper(processOBCluster, cluster, "OBCluster")
} else if tenant, ok := object.(*v1alpha1.OBTenant); ok {
Expand Down
9 changes: 3 additions & 6 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ func NewTelemetry(ctx context.Context, recorder record.EventRecorder) Telemetry
clt.telemetryDisabled = true
return clt
}
// no signature means telemetry is disabled
if TelemetryRequestSignature == "" {
clt.telemetryDisabled = true
return clt
}
clt.hostMetrics = getHostMetrics()
clt.throttler = getThrottler()
return clt
Expand Down Expand Up @@ -86,10 +81,12 @@ func (t *telemetry) GenerateTelemetryRecord(object any, objectType, eventType, r
return
}
go func(ctx context.Context, ch chan<- *models.TelemetryRecord) {
// TODO: guard here to mask IP address
objectSentry(object)
record := newRecordFromEvent(object, objectType, eventType, reason, message, annotations, extra...)
record.IpHashes = t.hostMetrics.IPHashes
if object == nil && objectType == "Operator" {
record.Resource = t.hostMetrics
}
select {
case <-ctx.Done():
return
Expand Down

0 comments on commit 5a6f3d5

Please sign in to comment.