From 558bd3575a3a8fc35f5cf417ea44b9ac5350e150 Mon Sep 17 00:00:00 2001 From: Nathan ter Bogt Date: Wed, 15 Apr 2026 12:53:13 +1200 Subject: [PATCH] Passing through metrics via config --- go.mod | 2 +- go.sum | 4 ++-- internal/client/project/project_test.go | 23 +++++++++++-------- internal/client/project/proto.go | 3 +++ internal/client/project/proto_test.go | 8 +++++++ .../client/project/testdata/.skpr/dev.yml | 5 +++- internal/client/project/types.go | 6 +++++ 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index ab5af13..c469d7f 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/moby/patternmatcher v0.6.1 github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 github.com/pkg/errors v0.9.1 - github.com/skpr/api v1.5.1 + github.com/skpr/api v1.5.2 github.com/skpr/compass/tracing v0.0.0-20251208094547-dafe383c3926 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/spf13/cobra v1.10.2 diff --git a/go.sum b/go.sum index 82a7918..be8e624 100644 --- a/go.sum +++ b/go.sum @@ -217,8 +217,8 @@ github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/skpr/api v1.5.1 h1:/B4eHvXseL2LiAvxj41gqB0EbbG3lCGPPx19AjTeIw0= -github.com/skpr/api v1.5.1/go.mod h1:jF55rQ39jyjTVo6MA74SRwYQduK/w+lPj6hjR6hqsyQ= +github.com/skpr/api v1.5.2 h1:JDIha2gf9Ycy/5JEYY+qyHidjKAIQa0M2q6jaFq0Vao= +github.com/skpr/api v1.5.2/go.mod h1:LMyIte2bWjGuO2e8XOA6FKNFUX10itF2qYVTckM7dwg= github.com/skpr/compass/tracing v0.0.0-20251208094547-dafe383c3926 h1:g8m8qqehB6/GMeM81BaIXQOkD2LZbCQE0HPRGear9Jw= github.com/skpr/compass/tracing v0.0.0-20251208094547-dafe383c3926/go.mod h1:Rokt2mnHteBaBmsSgiNk4P7laV0E8/BLQsSLyGUJLtk= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= diff --git a/internal/client/project/project_test.go b/internal/client/project/project_test.go index 5c24f29..6d07c50 100644 --- a/internal/client/project/project_test.go +++ b/internal/client/project/project_test.go @@ -25,7 +25,7 @@ func TestLoadFromDirectory(t *testing.T) { Size: "small", Services: Services{ MySQL: map[string]MySQL{ - "default": MySQL{ + "default": { Image: MySQLImage{ Schedule: "0 20 * * *", }, @@ -75,6 +75,9 @@ func TestLoadFromDirectory(t *testing.T) { Backup: Backup{ Schedule: "@daily", }, + Metrics: Metrics{ + Enabled: true, + }, }, "stg": { Ingress: Ingress{ @@ -92,7 +95,7 @@ func TestLoadFromDirectory(t *testing.T) { Size: "small", Services: Services{ MySQL: map[string]MySQL{ - "default": MySQL{ + "default": { Image: MySQLImage{ Schedule: "0 20 * * *", }, @@ -160,7 +163,7 @@ func TestLoadFromDirectory(t *testing.T) { Size: "large", Services: Services{ MySQL: map[string]MySQL{ - "default": MySQL{ + "default": { Image: MySQLImage{ Schedule: "0 20 * * *", }, @@ -225,7 +228,7 @@ func TestLoadFromDirectory(t *testing.T) { Size: "small", Services: Services{ MySQL: map[string]MySQL{ - "default": MySQL{ + "default": { Image: MySQLImage{ Schedule: "0 20 * * *", }, @@ -279,12 +282,14 @@ func TestLoadFromDirectory(t *testing.T) { } for name, environment := range environments { - e, err := LoadFromDirectory("./testdata/.skpr", name) - assert.NoError(t, err) + t.Run(name, func(t *testing.T) { + e, err := LoadFromDirectory("./testdata/.skpr", name) + assert.NoError(t, err) - if diff := deep.Equal(environment, e); diff != nil { - t.Error(diff) - } + if diff := deep.Equal(environment, e); diff != nil { + t.Error(diff) + } + }) } } diff --git a/internal/client/project/proto.go b/internal/client/project/proto.go index 8d3ce21..7b6d375 100644 --- a/internal/client/project/proto.go +++ b/internal/client/project/proto.go @@ -30,6 +30,9 @@ func (e Environment) Proto(name, version string) (*pb.Environment, error) { Schedule: e.Backup.Schedule, Suspend: e.Backup.Suspend, }, + Metrics: &pb.EnvironmentMetrics{ + Enabled: e.Metrics.Enabled, + }, } for bvName, bvConfig := range e.Backup.Volume { diff --git a/internal/client/project/proto_test.go b/internal/client/project/proto_test.go index 31a890e..26d46ab 100644 --- a/internal/client/project/proto_test.go +++ b/internal/client/project/proto_test.go @@ -156,6 +156,9 @@ func TestProto(t *testing.T) { }, }, }, + Metrics: Metrics{ + Enabled: true, + }, } want := &pb.Environment{ @@ -318,6 +321,9 @@ func TestProto(t *testing.T) { }, }, }, + Metrics: &pb.EnvironmentMetrics{ + Enabled: true, + }, } env, err := environment.Proto("dev", "v0.0.1") @@ -342,4 +348,6 @@ func TestProto(t *testing.T) { assert.Equal(t, want.Solr, env.Solr, "Solr is configured") assert.Equal(t, want.Link, env.Link, "Links are configured") assert.Equal(t, want.Volume, env.Volume, "Volumes are configured") + + assert.Equal(t, want.Metrics, env.Metrics, "Metrics is configured") } diff --git a/internal/client/project/testdata/.skpr/dev.yml b/internal/client/project/testdata/.skpr/dev.yml index dda0cd8..b3ffc9b 100644 --- a/internal/client/project/testdata/.skpr/dev.yml +++ b/internal/client/project/testdata/.skpr/dev.yml @@ -1,3 +1,6 @@ ingress: routes: - - dev.example.com \ No newline at end of file + - dev.example.com + +metrics: + enabled: true diff --git a/internal/client/project/types.go b/internal/client/project/types.go index 8d08c15..f27eccf 100644 --- a/internal/client/project/types.go +++ b/internal/client/project/types.go @@ -19,6 +19,7 @@ type Environment struct { Backup Backup `yaml:"backup" json:"backup"` Link map[string]Link `yaml:"link" json:"link"` Volumes map[string]EnvironmentSpecVolume `yaml:"volumes" json:"volumes"` + Metrics Metrics `yaml:"metrics,omitempty" json:"metrics,omitempty"` } // EnvironmentSpecVolume defines Volume configuration for this environemnt. @@ -244,3 +245,8 @@ type Link struct { Project string `yaml:"project,omitempty" json:"project,omitempty"` Environment string `yaml:"environment,omitempty" json:"environment,omitempty"` } + +// Metrics defines the spec for application metric collection. +type Metrics struct { + Enabled bool `yaml:"enabled" json:"enabled"` +}