Skip to content

Commit

Permalink
update log module
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Jiang committed Jan 8, 2024
1 parent 632804f commit acec1cd
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 79 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup kubebuilder
run: |
make kubebuilder
- name: Build
run: |
make build
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/OrderedMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// +kubebuilder:object:generate=false
type OrderedMap map[string]string

//MarshalJSON function is a custom implementation of json.Marshal for OrderedMap
// MarshalJSON function is a custom implementation of json.Marshal for OrderedMap
func (s OrderedMap) MarshalJSON() ([]byte, error) {
m := treemap.NewWithStringComparator()

Expand All @@ -20,7 +20,7 @@ func (s OrderedMap) MarshalJSON() ([]byte, error) {
return m.ToJSON()
}

//UnmarshalJson function is a custom implementation of json to unmarshal OrderedMap
// UnmarshalJson function is a custom implementation of json to unmarshal OrderedMap
func (s *OrderedMap) UnmarshalJSON(b []byte) error {
// Just regular unmarshal into map[string]string should work fine
var foo map[string]string
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/alertsconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type AlertsConfigSpec struct {
GlobalParams OrderedMap `json:"globalParams,omitempty"`
}

//GVK struct represents the alert type and can be used as a global as well as in individual alert section
// GVK struct represents the alert type and can be used as a global as well as in individual alert section
type GVK struct {
//Group - CRD Group name which this config/s is related to
Group string `json:"group,omitempty"`
Expand All @@ -47,7 +47,7 @@ type GVK struct {
Kind string `json:"kind,omitempty"`
}

//Config section provides the AlertsConfig for each individual alert
// Config section provides the AlertsConfig for each individual alert
// +optional
type Config struct {
//GVK can be used to provide CRD group, version and kind- If there is a global GVK already provided this will overwrite it
Expand Down Expand Up @@ -77,8 +77,8 @@ type AssociatedAlert struct {
Generation int64 `json:"generation,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="current state of the alerts config"
// +kubebuilder:printcolumn:name="RetryCount",type="integer",JSONPath=".status.retryCount",description="Retry count"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="time passed since alerts config creation"
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the alertmanager v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=alertmanager.keikoproj.io
// +kubebuilder:object:generate=true
// +groupName=alertmanager.keikoproj.io
package v1alpha1

import (
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/wavefrontalert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type WavefrontAlertStatus struct {
AlertsStatus map[string]AlertStatus `json:"alertsStatus,omitempty"`
}

//AlertStatus consists of individual alert details
// AlertStatus consists of individual alert details
type AlertStatus struct {
ID string `json:"id"`
Name string `json:"alertName"`
Expand All @@ -149,8 +149,8 @@ type AssociatedAlertsConfig struct {
CR string `json:"CR,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=wavefrontalerts,scope=Namespaced,shortName=wfalerts,singular=wavefrontalert
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="current state of the wavefront alert"
// +kubebuilder:printcolumn:name="RetryCount",type="integer",JSONPath=".status.retryCount",description="Retry count"
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions controllers/alertsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (r *AlertsConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request
return r.HandleIndividalAlertConfigRemoval(ctx, req.NamespacedName)
}

//HandleIndividalAlertConfigRemoval function handles if there is any config got removed from the spec, if so- delete that alert in wavefront and also update the status
// HandleIndividalAlertConfigRemoval function handles if there is any config got removed from the spec, if so- delete that alert in wavefront and also update the status
func (r *AlertsConfigReconciler) HandleIndividalAlertConfigRemoval(ctx context.Context, namespacedName types.NamespacedName) (ctrl.Result, error) {
log := log.Logger(ctx, "controllers", "alertsconfig_controller", "HandleIndividalAlertConfigRemoval")
log = log.WithValues("alertsConfig_cr", namespacedName)
Expand Down Expand Up @@ -261,7 +261,7 @@ func (r *AlertsConfigReconciler) HandleIndividalAlertConfigRemoval(ctx context.C
return r.CommonClient.UpdateStatus(ctx, &updatedAlertsConfig, tempState, errRequeueTime)
}

//DeleteIndividualAlert function deletes individual alert and also patches the status on both wavefront alert and also alerts config status
// DeleteIndividualAlert function deletes individual alert and also patches the status on both wavefront alert and also alerts config status
func (r *AlertsConfigReconciler) DeleteIndividualAlert(ctx context.Context, alertName string, alertStatus alertmanagerv1alpha1.AlertStatus, namespace string) error {
log := log.Logger(ctx, "controllers", "alertsconfig_controller", "DeleteIndividualAlert")
log = log.WithValues("alertsConfig_cr", alertName)
Expand Down Expand Up @@ -294,7 +294,7 @@ func (r *AlertsConfigReconciler) DeleteIndividualAlert(ctx context.Context, aler
return nil
}

//PatchIndividualAlertsConfigError function is a utility function to patch the error status
// PatchIndividualAlertsConfigError function is a utility function to patch the error status
// We use status patch instead of status update to avoid any overwrite between two threads when alertsConfig CR has multiple alert configs
func (r *AlertsConfigReconciler) PatchIndividualAlertsConfigError(ctx context.Context, alertsConfig *alertmanagerv1alpha1.AlertsConfig, alertName string, state alertmanagerv1alpha1.State, err error, requeueTime ...float64) (ctrl.Result, error) {
log := log.Logger(ctx, "controllers", "alertsconfig_controller", "PatchIndividualAlertsConfigError")
Expand All @@ -312,7 +312,7 @@ func (r *AlertsConfigReconciler) PatchIndividualAlertsConfigError(ctx context.Co
return r.CommonClient.PatchStatus(ctx, alertsConfig, client.RawPatch(types.MergePatchType, patch), alertmanagerv1alpha1.Error, errRequeueTime)
}

//HandleDelete function handles the deleting wavefront alerts
// HandleDelete function handles the deleting wavefront alerts
func (r *AlertsConfigReconciler) HandleDelete(ctx context.Context, alertsConfig *alertmanagerv1alpha1.AlertsConfig) error {
log := log.Logger(ctx, "controllers", "alertsconfig_controller", "HandleDelete")
log = log.WithValues("alertsConfig_cr", alertsConfig.Name, "namespace", alertsConfig.Namespace)
Expand Down
14 changes: 7 additions & 7 deletions controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ type Client struct {
Recorder record.EventRecorder
}

//UpdateMeta function updates the metadata (mostly finalizers in this case)
//This function accepts runtime.Object which can be either cluster type or namespace type
// UpdateMeta function updates the metadata (mostly finalizers in this case)
// This function accepts runtime.Object which can be either cluster type or namespace type
func (r *Client) UpdateMeta(ctx context.Context, object client.Object) {
log := log.Logger(ctx, "controllers.common", "UpdateMeta")
if err := r.Update(ctx, object); err != nil {
Expand All @@ -80,7 +80,7 @@ func (r *Client) UpdateMeta(ctx context.Context, object client.Object) {
log.Info("successfully updated the meta")
}

//UpdateStatus function updates the status based on the process step
// UpdateStatus function updates the status based on the process step
func (r *Client) UpdateStatus(ctx context.Context, obj client.Object, state alertmanagerv1alpha1.State, requeueTime ...float64) (ctrl.Result, error) {
log := log.Logger(ctx, "controllers.common", "common", "UpdateStatus")

Expand All @@ -103,7 +103,7 @@ func (r *Client) UpdateStatus(ctx context.Context, obj client.Object, state aler
return ctrl.Result{RequeueAfter: time.Duration(requeueTime[0]) * time.Millisecond}, nil
}

//PatchStatus function patches the status based on the process step
// PatchStatus function patches the status based on the process step
func (r *Client) PatchStatus(ctx context.Context, obj client.Object, patch client.Patch, state alertmanagerv1alpha1.State, requeueTime ...float64) (ctrl.Result, error) {
log := log.Logger(ctx, "controllers.common", "common", "PatchStatus")

Expand All @@ -126,7 +126,7 @@ func (r *Client) PatchStatus(ctx context.Context, obj client.Object, patch clien
return ctrl.Result{RequeueAfter: time.Duration(requeueTime[0]) * time.Millisecond}, nil
}

//ConvertAlertCR converts alert CR to wf.Alert
// ConvertAlertCR converts alert CR to wf.Alert
func (r *Client) ConvertAlertCR(ctx context.Context, wfAlert *alertmanagerv1alpha1.WavefrontAlert, alert *wf.Alert) {
log := log.Logger(ctx, "controllers", "wavefrontalert_controller", "convertAlertCR")
//log = log.WithValues("wavefrontalert_cr", wfAlert.Name, "namespace", wfAlert.Namespace)
Expand All @@ -144,7 +144,7 @@ func (r *Client) ConvertAlertCR(ctx context.Context, wfAlert *alertmanagerv1alph
}
}

//GetProcessedWFAlert function converts wavefront alert spec to wavefront api request by processing template with the values provided in alerts config
// GetProcessedWFAlert function converts wavefront alert spec to wavefront api request by processing template with the values provided in alerts config
func GetProcessedWFAlert(ctx context.Context, wfAlert *alertmanagerv1alpha1.WavefrontAlert, params map[string]string, alert *wf.Alert) error {
log := log.Logger(ctx, "controllers", "common", "GetProcessedWFAlert")
log = log.WithValues("alertsConfig_cr", wfAlert.Name)
Expand Down Expand Up @@ -196,7 +196,7 @@ func GetProcessedWFAlert(ctx context.Context, wfAlert *alertmanagerv1alpha1.Wave
return nil
}

//PatchWfAlertAndAlertsConfigStatus function patches the individual alert status for both wavefront alert and alerts config
// PatchWfAlertAndAlertsConfigStatus function patches the individual alert status for both wavefront alert and alerts config
func (r *Client) PatchWfAlertAndAlertsConfigStatus(
ctx context.Context,
state alertmanagerv1alpha1.State,
Expand Down
6 changes: 3 additions & 3 deletions controllers/wavefrontalert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (r *WavefrontAlertReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return r.CommonClient.UpdateStatus(ctx, &wfAlert, wfAlert.Status.State, errRequeueTime)
}

//PatchIndividualAlertsStatusError function is a utility function to patch the error status
// PatchIndividualAlertsStatusError function is a utility function to patch the error status
// We use status patch instead of status update to avoid any overwrite between two threads when alertsConfig CR has multiple alert configs
func (r *WavefrontAlertReconciler) PatchIndividualAlertsStatusError(ctx context.Context, wfAlert *alertmanagerv1alpha1.WavefrontAlert, alertName string, state alertmanagerv1alpha1.State, err error, requeueTime ...float64) (ctrl.Result, error) {
log := log.Logger(ctx, "controllers", "alertsconfig_controller", "PatchIndividualAlertsStatusError")
Expand All @@ -305,7 +305,7 @@ func (r *WavefrontAlertReconciler) PatchIndividualAlertsStatusError(ctx context.
return r.CommonClient.PatchStatus(ctx, wfAlert, client.RawPatch(types.MergePatchType, patch), alertmanagerv1alpha1.Error, errRequeueTime)
}

//HandleDelete function handles the deleting wavefront alerts
// HandleDelete function handles the deleting wavefront alerts
func (r *WavefrontAlertReconciler) HandleDelete(ctx context.Context, wfAlert *alertmanagerv1alpha1.WavefrontAlert) error {
log := log.Logger(ctx, "controllers", "wavefrontalert_controller", "HandleDelete")
log = log.WithValues("wavefrontalert_cr", wfAlert.Name, "namespace", wfAlert.Namespace)
Expand Down Expand Up @@ -335,7 +335,7 @@ func (r *WavefrontAlertReconciler) HandleDelete(ctx context.Context, wfAlert *al
return nil
}

//convertAlertCR converts alert CR to wf.Alert
// convertAlertCR converts alert CR to wf.Alert
func (r *WavefrontAlertReconciler) convertAlertCR(ctx context.Context, wfAlert *alertmanagerv1alpha1.WavefrontAlert, alert *wf.Alert) {
log := log.Logger(ctx, "controllers", "wavefrontalert_controller", "convertAlertCR")
log = log.WithValues("wavefrontalert_cr", wfAlert.Name, "namespace", wfAlert.Namespace)
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ require (
github.com/go-logr/logr v1.2.4
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/keikoproj/manager v0.0.0-20200414065656-d0d64621fb96
github.com/onsi/ginkgo v1.16.4
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.27.10
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
Expand Down Expand Up @@ -37,6 +36,7 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/imdario/mergo v0.3.10 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -45,7 +45,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
Expand All @@ -63,6 +63,7 @@ require (
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit acec1cd

Please sign in to comment.