Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions internal/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ type Config struct {
LogicalEnvironment string
PhysicalEnvironment string
Cluster string
APIToken string
BaseURL string
GHAppID string
GHInstallID string
GHAppPrivateKey string
Organization string
//nolint:gosec
APIToken string
BaseURL string
GHAppID string
GHInstallID string
GHAppPrivateKey string
Organization string
}

// ValidTemplate verifies that at least one placeholder is present
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/github/deployment-tracker/pkg/deploymentrecord"
"github.com/github/deployment-tracker/pkg/image"
"github.com/github/deployment-tracker/pkg/metrics"
"github.com/github/deployment-tracker/pkg/dtmetrics"
"github.com/github/deployment-tracker/pkg/ociutil"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
amcache "k8s.io/apimachinery/pkg/util/cache"
Expand Down Expand Up @@ -271,14 +271,14 @@ func (c *Controller) processNextItem(ctx context.Context) bool {
dur := time.Since(start)

if err == nil {
metrics.EventsProcessedOk.WithLabelValues(event.EventType).Inc()
metrics.EventsProcessedTimer.WithLabelValues("ok").Observe(dur.Seconds())
dtmetrics.EventsProcessedOk.WithLabelValues(event.EventType).Inc()
dtmetrics.EventsProcessedTimer.WithLabelValues("ok").Observe(dur.Seconds())

c.workqueue.Forget(event)
return true
}
metrics.EventsProcessedTimer.WithLabelValues("failed").Observe(dur.Seconds())
metrics.EventsProcessedFailed.WithLabelValues(event.EventType).Inc()
dtmetrics.EventsProcessedTimer.WithLabelValues("failed").Observe(dur.Seconds())
dtmetrics.EventsProcessedFailed.WithLabelValues(event.EventType).Inc()

// Requeue on error with rate limiting
slog.Error("Failed to process event, requeuing",
Expand Down Expand Up @@ -443,7 +443,7 @@ func (c *Controller) recordContainer(ctx context.Context, pod *corev1.Pod, conta
}

// Extract image name and tag
imageName, version := image.ExtractName(container.Image)
imageName, version := ociutil.ExtractName(container.Image)

// Create deployment record
record := deploymentrecord.NewDeploymentRecord(
Expand Down Expand Up @@ -676,14 +676,14 @@ func getContainerDigest(pod *corev1.Pod, containerName string) string {
// Check regular container statuses
for _, status := range pod.Status.ContainerStatuses {
if status.Name == containerName {
return image.ExtractDigest(status.ImageID)
return ociutil.ExtractDigest(status.ImageID)
}
}

// Check init container statuses
for _, status := range pod.Status.InitContainerStatuses {
if status.Name == containerName {
return image.ExtractDigest(status.ImageID)
return ociutil.ExtractDigest(status.ImageID)
}
}

Expand Down
15 changes: 8 additions & 7 deletions pkg/deploymentrecord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"time"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/github/deployment-tracker/pkg/metrics"
"github.com/github/deployment-tracker/pkg/dtmetrics"
"golang.org/x/time/rate"
)

Expand Down Expand Up @@ -211,17 +211,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
}

start := time.Now()
// nolint: gosec
resp, err := c.httpClient.Do(req)
dur := time.Since(start)
metrics.PostDeploymentRecordTimer.Observe(dur.Seconds())
dtmetrics.PostDeploymentRecordTimer.Observe(dur.Seconds())
if err != nil {
lastErr = fmt.Errorf("post request failed: %w", err)

slog.Warn("recoverable error, re-trying",
"attempt", attempt,
"retries", c.retries,
"error", lastErr)
metrics.PostDeploymentRecordSoftFail.Inc()
dtmetrics.PostDeploymentRecordSoftFail.Inc()
continue
}

Expand All @@ -230,7 +231,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
resp.Body.Close()

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
metrics.PostDeploymentRecordOk.Inc()
dtmetrics.PostDeploymentRecordOk.Inc()
return nil
}

Expand All @@ -239,16 +240,16 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
// Don't retry on client errors (4xx) except for 429
// (rate limit)
if resp.StatusCode >= 400 && resp.StatusCode < 500 && resp.StatusCode != 429 {
metrics.PostDeploymentRecordClientError.Inc()
dtmetrics.PostDeploymentRecordClientError.Inc()
slog.Warn("client error, aborting",
"attempt", attempt,
"error", lastErr)
return &ClientError{err: lastErr}
}
metrics.PostDeploymentRecordSoftFail.Inc()
dtmetrics.PostDeploymentRecordSoftFail.Inc()
}

metrics.PostDeploymentRecordHardFail.Inc()
dtmetrics.PostDeploymentRecordHardFail.Inc()
slog.Error("all retries exhausted",
"count", c.retries,
"error", lastErr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/prom.go → pkg/dtmetrics/prom.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package metrics
package dtmetrics

import (
"github.com/prometheus/client_golang/prometheus"
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/digest.go → pkg/ociutil/digest.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package image
package ociutil

// ExtractDigest extracts the digest from an ImageID.
// ImageID format is typically: docker-pullable://image@sha256:abc123...
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/digest_test.go → pkg/ociutil/digest_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package image
package ociutil

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/name.go → pkg/ociutil/name.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package image
package ociutil

import (
"strings"
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/name_test.go → pkg/ociutil/name_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package image
package ociutil

import (
"testing"
Expand Down