Skip to content
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

update to telem work #588

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
541f5e0
first
Dec 4, 2019
6a22bbe
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Dec 12, 2019
44d7ddb
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Dec 17, 2019
1764d1a
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Dec 19, 2019
03491b4
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Jan 3, 2020
6517e82
Merge branch 'master' into bugfixes
jananivMS Jan 4, 2020
5812dc3
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Jan 6, 2020
a870f57
update
Jan 6, 2020
193986c
groups updated
Jan 6, 2020
469b9e4
other groups
Jan 6, 2020
53fc30f
forgot err in groups
Jan 6, 2020
8f919bb
rediscache
Jan 6, 2020
18c4613
keyvault
Jan 6, 2020
7dbac69
cosmosdb
Jan 6, 2020
9144085
last controller update
Jan 6, 2020
916263b
bug in redis cache
WilliamMortlMicrosoft Jan 6, 2020
93c129a
redis bug - take 2
WilliamMortlMicrosoft Jan 6, 2020
e0ba097
cosmosdb bug
WilliamMortlMicrosoft Jan 6, 2020
1497a60
removed uneeded keyvault import
WilliamMortlMicrosoft Jan 6, 2020
1af6830
ensureErr issue
WilliamMortlMicrosoft Jan 6, 2020
ca45237
stupid colon
WilliamMortlMicrosoft Jan 6, 2020
8679cde
fixed errRet issue
WilliamMortlMicrosoft Jan 6, 2020
a16e391
scoping issue
WilliamMortlMicrosoft Jan 6, 2020
5eabd5d
deleting
Jan 12, 2020
1391df2
Merge branch 'master' into bugfixes
WilliamMortlMicrosoft Jan 12, 2020
4aade37
merge master
frodopwns Jan 21, 2020
bb849c3
remove mocks, expose ASOStatus, capture provisioning times
frodopwns Jan 22, 2020
f407271
merge master
frodopwns Jan 22, 2020
f34a44c
update keyvault with status and telem changes
frodopwns Jan 22, 2020
761bcc9
don't like the named returns here
frodopwns Jan 23, 2020
4754baf
Merge branch 'master' into telemcont
frodopwns Jan 23, 2020
ec4637a
Merge branch 'master' into telemcont
WilliamMortlMicrosoft Jan 27, 2020
63ac1bf
Merge branch 'frodopwns-telemcont'
Feb 19, 2020
cd16661
fixes
Feb 19, 2020
e7683e1
Merge branch 'Azure-master'
Feb 19, 2020
c36ded0
Merge branch 'master' into telemcont
WilliamMortlMicrosoft Feb 25, 2020
b4cff54
Merge branch 'master' into telemcont
WilliamMortlMicrosoft Feb 26, 2020
baee626
progress
Feb 26, 2020
e7dd360
Merge branch 'telemcont' of github.com:frodopwns/azure-service-operat…
Feb 26, 2020
4676106
Merge branch 'master' into telemcont
WilliamMortlMicrosoft Feb 27, 2020
9cd24da
refactor
Feb 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions api/v1alpha1/aso_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
type ASOStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
RequestedAt *metav1.Time `json:"requested,omitempty"`
CompletedAt *metav1.Time `json:"completed,omitempty"`
Comment on lines +25 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

}

// StatusedObject used to unmarshall runtime.Object when we need Status
Expand Down
58 changes: 24 additions & 34 deletions controllers/async_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,29 @@ const (
type AsyncReconciler struct {
client.Client
AzureClient resourcemanager.ARMClient
Telemetry telemetry.PrometheusTelemetry
Telemetry telemetry.TelemetryClient
Recorder record.EventRecorder
Scheme *runtime.Scheme
}

func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (result ctrl.Result, err error) {
// Reconcile reconciles the request
func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (ctrl.Result, error) {
ctx := context.Background()

// // log operator start
// r.Telemetry.LogStart()

// // log failure / success
// defer func() {
// if err != nil {
// r.Telemetry.LogError(
// "Failure occured during reconcilliation",
// err)
// r.Telemetry.LogFailure()
// } else if result.Requeue {
// r.Telemetry.LogFailure()
// } else {
// r.Telemetry.LogSuccess()
// }
// }()
r.Telemetry.SetInstance(req.String())

if err := r.Get(ctx, req.NamespacedName, local); err != nil {
r.Telemetry.LogInfo("ignorable error", "error during fetch from api server")
r.Telemetry.LogInfo("requeueing", "error during fetch from api server")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

status, err := r.AzureClient.GetStatus(local)
if err != nil {
return ctrl.Result{}, err
}

res, err := meta.Accessor(local)
if err != nil {
r.Telemetry.LogError("accessor fail", err)
r.Telemetry.LogInfo("requeuing", fmt.Sprintf("failed getting meta accessor: %s", err.Error()))
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -109,7 +99,6 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
RemoveFinalizer(res, finalizerName)
return ctrl.Result{}, r.Update(ctx, local)
}
r.Telemetry.LogInfo("requeuing", "deletion unfinished")
return ctrl.Result{RequeueAfter: requeDuration}, nil
}
return ctrl.Result{}, nil
Expand All @@ -118,52 +107,53 @@ func (r *AsyncReconciler) Reconcile(req ctrl.Request, local runtime.Object) (res
// loop through parents until one is successfully referenced
parents, err := r.AzureClient.GetParents(local)
for _, p := range parents {
//r.Telemetry.LogInfo("status", "handling parent "+p.Key.Name)

if err := r.Get(ctx, p.Key, p.Target); err == nil {
//r.Telemetry.LogInfo("status", "handling parent get for "+reflect.TypeOf(p.Target).String())

if pAccessor, err := meta.Accessor(p.Target); err == nil {
if err := controllerutil.SetControllerReference(pAccessor, res, r.Scheme); err == nil {
r.Telemetry.LogInfo("status", "setting parent reference to object: "+pAccessor.GetName())
r.Telemetry.LogInfo("setting parent reference", pAccessor.GetName())
err := r.Update(ctx, local)
if err != nil {
r.Telemetry.LogInfo("warning", "failed to update instance: "+err.Error())
r.Telemetry.LogError("failed to reference parent", err)
}
break
}
}
}
}

r.Telemetry.LogInfo("status", "reconciling object")
r.Telemetry.LogTrace("reconciling", "reconciling object")
done, ensureErr := r.AzureClient.Ensure(ctx, local)
if ensureErr != nil {
r.Telemetry.LogError("ensure err", ensureErr)
r.Telemetry.LogError("error from Ensure", err)
}

// update the status of the resource in kubernetes
// Implementations of Ensure() tend to set their outcomes in local.Status
err = r.Status().Update(ctx, local)
if err != nil {
r.Telemetry.LogInfo("status", "failed updating status")
r.Telemetry.LogError("failed to update status", err)
}

final := multierror.Append(ensureErr, r.Update(ctx, local))
err = final.ErrorOrNil()
if err != nil {
r.Recorder.Event(local, corev1.EventTypeWarning, "FailedReconcile", fmt.Sprintf("Failed to reconcile resource: %s", err.Error()))
r.Recorder.Event(local, corev1.EventTypeWarning, "FailedReconcile", fmt.Sprintf("Unexpected error during reconciliation: %s", err.Error()))
} else if done {
r.Recorder.Event(local, corev1.EventTypeNormal, "Reconciled", "Successfully reconciled")
r.Recorder.Event(local, corev1.EventTypeNormal, "Reconciled", "Reconciliation ended with no errors")
}

result = ctrl.Result{}
result := ctrl.Result{}
if !done {
r.Telemetry.LogInfo("status", "reconciling object not finished")
r.Telemetry.LogInfo("requeueing", "reconciling object not finished, re-queueing")
result.RequeueAfter = requeDuration
} else {
r.Telemetry.LogInfo("reconciling", "success")
}

r.Telemetry.LogInfo("status", "exiting reconciliation")
r.Telemetry.LogInfo("operator", fmt.Sprintf("message from operator: %s", status.Message))
r.Telemetry.LogTrace("operator", "exiting reconciliation")

return result, err
}
9 changes: 9 additions & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("KeyVault"),
"KeyVault",
),
Log: ctrl.Log.WithName("controllers").WithName("KeyVault"),
Recorder: k8sManager.GetEventRecorderFor("KeyVault-controller"),
Scheme: scheme.Scheme,
},
Expand Down Expand Up @@ -219,6 +220,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("AppInsights"),
"AppInsights",
),
Log: ctrl.Log.WithName("controllers").WithName("AppInsights"),
Recorder: k8sManager.GetEventRecorderFor("AppInsights-controller"),
Scheme: scheme.Scheme,
},
Expand All @@ -235,6 +237,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("EventHub"),
"EventHub",
),
Log: ctrl.Log.WithName("controllers").WithName("EventHub"),
Recorder: k8sManager.GetEventRecorderFor("Eventhub-controller"),
Scheme: scheme.Scheme,
},
Expand All @@ -251,6 +254,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("ResourceGroup"),
"ResourceGroup",
),
Log: ctrl.Log.WithName("controllers").WithName("ResourceGroup"),
Recorder: k8sManager.GetEventRecorderFor("ResourceGroup-controller"),
Scheme: scheme.Scheme,
},
Expand All @@ -267,6 +271,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("EventhubNamespace"),
"EventhubNamespace",
),
Log: ctrl.Log.WithName("controllers").WithName("EventhubNamespace"),
Recorder: k8sManager.GetEventRecorderFor("EventhubNamespace-controller"),
Scheme: scheme.Scheme,
},
Expand All @@ -283,6 +288,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("ConsumerGroup"),
"ConsumerGroup",
),
Log: ctrl.Log.WithName("controllers").WithName("ConsumerGroup"),
Recorder: k8sManager.GetEventRecorderFor("ConsumerGroup-controller"),
Scheme: scheme.Scheme,
},
Expand Down Expand Up @@ -408,6 +414,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("PostgreSQLServer"),
"PostgreSQLServer",
),
Log: ctrl.Log.WithName("controllers").WithName("PostgreSQLServer"),
Recorder: k8sManager.GetEventRecorderFor("PostgreSQLServer-controller"),
Scheme: k8sManager.GetScheme(),
},
Expand All @@ -424,6 +431,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("PostgreSQLDatabaser"),
"PostgreSQLDatabase",
),
Log: ctrl.Log.WithName("controllers").WithName("PostgreSQLDatabaser"),
Recorder: k8sManager.GetEventRecorderFor("PostgreSQLDatabase-controller"),
Scheme: k8sManager.GetScheme(),
},
Expand All @@ -440,6 +448,7 @@ func setup() error {
ctrl.Log.WithName("controllers").WithName("PostgreSQLFirewallRule"),
"PostgreSQLFirewallRule",
),
Log: ctrl.Log.WithName("controllers").WithName("PostgreSQLFirewallRule"),
Recorder: k8sManager.GetEventRecorderFor("PostgreSQLFirewallRule-controller"),
Scheme: k8sManager.GetScheme(),
},
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ github.com/prometheus/client_golang v0.9.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f h1:BVwpUVJDADN2ufcGik7W992pyps0wZ888b/y9GXcLTU=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down
Loading