Skip to content

Commit

Permalink
Prepare v0.2 release (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-zubrienko authored Dec 2, 2024
1 parent a5f8bc3 commit b668a27
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-gh-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: SneaksAndData/github-actions/[email protected]
with:
major_v: 0
minor_v: 1
minor_v: 2
2 changes: 1 addition & 1 deletion .helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ controller:
# A name for a Secret resource that contains Datadog API Key to use for log submissions
apiKeySecret: "secretName"

# A key in the Secret that contains Datadog API Key
# a key in the secret that contains datadog api key
apiKeySecretKey: "secretKey"

# Datadog Service Name parameter
Expand Down
18 changes: 8 additions & 10 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ func (c *Controller) runWorker(ctx context.Context) {
// attempt to process it, by calling the syncHandler.
func (c *Controller) processNextWorkItem(ctx context.Context) bool { // coverage-ignore
objRef, shutdown := c.workqueue.Get()
logger := klog.FromContext(ctx)
metrics := ctx.Value("metrics").(*statsd.Client)
metrics := ctx.Value(telemetry.MetricsClientContextKey).(*statsd.Client)
itemProcessStart := time.Now()

if shutdown {
Expand All @@ -342,7 +341,6 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool { // coverage
// If no error occurs then we Forget this item so it does not
// get queued again until another change happens.
c.workqueue.Forget(objRef)
logger.Info("Successfully synced", "objectName", objRef)
return true
}
// there was a failure so be sure to report it. This method allows for
Expand Down Expand Up @@ -415,7 +413,7 @@ func (c *Controller) syncSecretsToShard(secretNamespace string, controllerMla *v
// Get the secret with the name specified in MachineLearningAlgorithm.spec
secret, err := c.secretLister.Secrets(secretNamespace).Get(secretName)
// If the referenced Secret resource doesn't exist in the cluster where the controller is deployed, update the syncErr and move on to the next Secret
if k8serrors.IsNotFound(err) {
if k8serrors.IsNotFound(err) { // coverage-ignore
msg := fmt.Sprintf(MessageResourceMissing, secretName, controllerMla.Name)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceMissing, msg)
logger.V(4).Info("Secret not found", "secretName", secretName, "shard", shard.Name)
Expand All @@ -429,15 +427,15 @@ func (c *Controller) syncSecretsToShard(secretNamespace string, controllerMla *v
}

// requeue on error
if err != nil {
if err != nil { // coverage-ignore
msg := fmt.Sprintf(MessageResourceOperationFailed, secretName, controllerMla.Name, err)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceSyncError, msg)
return err
}

missingOwner, err := c.isMissingOwnership(shardSecret, shardMla)
// requeue on error
if err != nil {
if err != nil { // coverage-ignore
msg := fmt.Sprintf(MessageResourceOperationFailed, secretName, controllerMla.Name, err)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceSyncError, msg)
return err
Expand Down Expand Up @@ -477,7 +475,7 @@ func (c *Controller) syncConfigMapsToShard(configMapNamespace string, controller
// Get the ConfigMap with the name specified in MachineLearningAlgorithm.spec
configMap, err := c.configMapLister.ConfigMaps(configMapNamespace).Get(configMapName)
// If the referenced ConfigMap resource doesn't exist in the cluster where the controller is deployed, update syncErr and move on to the next ConfigMap
if k8serrors.IsNotFound(err) {
if k8serrors.IsNotFound(err) { // coverage-ignore
msg := fmt.Sprintf(MessageResourceMissing, configMapName, controllerMla.Name)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceMissing, msg)
logger.V(4).Info("ConfigMap not found", "configMapName", configMapName, "shard", shard.Name)
Expand All @@ -486,20 +484,20 @@ func (c *Controller) syncConfigMapsToShard(configMapNamespace string, controller

shardConfigMap, err := shard.ConfigMapLister.ConfigMaps(shardMla.Namespace).Get(configMap.Name)
// secret does not exist in this shard, create it
if k8serrors.IsNotFound(err) {
if k8serrors.IsNotFound(err) { // coverage-ignore
shardConfigMap, err = shard.CreateConfigMap(shardMla, configMap, FieldManager)
}

// requeue on error
if err != nil {
if err != nil { // coverage-ignore
msg := fmt.Sprintf(MessageResourceOperationFailed, configMapName, controllerMla.Name, err)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceSyncError, msg)
return err
}

missingOwner, err := c.isMissingOwnership(shardConfigMap, shardMla)
// requeue on error
if err != nil {
if err != nil { // coverage-ignore
msg := fmt.Sprintf(MessageResourceOperationFailed, configMapName, controllerMla.Name, err)
c.recorder.Event(controllerMla, corev1.EventTypeWarning, ErrResourceSyncError, msg)
return err
Expand Down
16 changes: 7 additions & 9 deletions pkg/telemetry/app_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"time"
)

type contextKey string

const (
// MetricsNamespace sets the datadog metrics namespace to use
MetricsNamespace = "ncc"
Expand All @@ -31,31 +33,27 @@ const (

// WorkqueueLengthMetric name for statsd
WorkqueueLengthMetric = "workqueue_length"

MetricsClientContextKey contextKey = "metrics"
)

// WithStatsd enriches the context with a statsd client if it can be instantiated
func WithStatsd(ctx context.Context) context.Context { // coverage-ignore
statsdClient, err := statsd.New("", statsd.WithNamespace(MetricsNamespace))
if err == nil {
return context.WithValue(ctx, "metrics", statsdClient)
return context.WithValue(ctx, MetricsClientContextKey, statsdClient)
}

return ctx
}

// Gauge reports a GAUGE metric using best-effort approach
func Gauge(metrics *statsd.Client, name string, value float64, tags []string, rate float64) { // coverage-ignore
err := metrics.Gauge(name, value, tags, rate)
if err != nil {
// do nothing
}
_ = metrics.Gauge(name, value, tags, rate)
}

// GaugeDuration reports a GAUGE metric corresponding to a duration of an operation that started at a specified time, in milliseconds
func GaugeDuration(metrics *statsd.Client, name string, startedAt time.Time, tags []string, rate float64) { // coverage-ignore
duration := time.Since(startedAt).Milliseconds()
err := metrics.Gauge(name, float64(duration), tags, rate)
if err != nil {
// do nothing
}
_ = metrics.Gauge(name, float64(duration), tags, rate)
}

0 comments on commit b668a27

Please sign in to comment.