Skip to content

Commit

Permalink
(feat) telemetry collect configuration stats
Browse files Browse the repository at this point in the history
Number of ClusterProfiles/Profiles/ClusterSummaries is also collected
  • Loading branch information
mgianluc committed Nov 15, 2024
1 parent 5af6a8b commit 059c6ac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v0.41.1-0.20241112131631-fdf1a14ed67b
github.com/projectsveltos/libsveltos v0.41.1-0.20241115073300-b16b79f8ba64
github.com/prometheus/client_golang v1.20.5
github.com/spf13/pflag v1.0.5
github.com/yuin/gopher-lua v1.1.1
Expand Down
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ github.com/chai2010/gettext-go v1.0.3/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHe
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
github.com/containerd/containerd v1.7.21 h1:USGXRK1eOC/SX0L195YgxTHb0a00anxajOzgfN0qrCA=
github.com/containerd/containerd v1.7.21/go.mod h1:e3Jz1rYRUZ2Lt51YrH9Rz0zPyJBOlSvB3ghr2jbVD8g=
github.com/containerd/containerd v1.7.23 h1:H2CClyUkmpKAGlhQp95g2WXHfLYc7whAuvZGBNYOOwQ=
github.com/containerd/containerd v1.7.23/go.mod h1:7QUzfURqZWCZV7RLNEn1XjUCQLEf0bkaK4GjUaZehxw=
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=
github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM=
github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0=
github.com/containerd/errdefs v0.3.0 h1:FSZgGOeK4yuT/+DnF07/Olde/q4KBoMsaamhXxIMDp4=
github.com/containerd/errdefs v0.3.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
Expand All @@ -75,8 +71,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cyphar/filepath-securejoin v0.3.3 h1:lofZkCEVFIBe0KcdQOzFs8Soy9oaHOWl4gGtPI+gCFc=
github.com/cyphar/filepath-securejoin v0.3.3/go.mod h1:8s/MCNJREmFK0H02MF6Ihv1nakJe4L/w3WZLHNkvlYM=
github.com/cyphar/filepath-securejoin v0.3.4 h1:VBWugsJh2ZxJmLFSM06/0qzQyiQX2Qs0ViKrUAcqdZ8=
github.com/cyphar/filepath-securejoin v0.3.4/go.mod h1:8s/MCNJREmFK0H02MF6Ihv1nakJe4L/w3WZLHNkvlYM=
github.com/dariubs/percent v1.0.0 h1:fY8q40FRYaCiFZ0gTOa73Cmp21hS32w+tSSmqbGnUzc=
Expand Down Expand Up @@ -330,8 +324,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg=
github.com/projectsveltos/libsveltos v0.41.1-0.20241112131631-fdf1a14ed67b h1:tsMyv482ItKJR1UKL7poiPLxNN36MlVjrg9pgxKARvo=
github.com/projectsveltos/libsveltos v0.41.1-0.20241112131631-fdf1a14ed67b/go.mod h1:idHfT2MeJsJsedLAr9v9EW5aIXqKOMK1CrlaKZaD7AY=
github.com/projectsveltos/libsveltos v0.41.1-0.20241115073300-b16b79f8ba64 h1:gZmBBeIehRPoOe/TT9xqBY7wbrK/qKZZK6m34nK8d84=
github.com/projectsveltos/libsveltos v0.41.1-0.20241115073300-b16b79f8ba64/go.mod h1:idHfT2MeJsJsedLAr9v9EW5aIXqKOMK1CrlaKZaD7AY=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down Expand Up @@ -543,8 +537,6 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
helm.sh/helm/v3 v3.16.2 h1:Y9v7ry+ubQmi+cb5zw1Llx8OKHU9Hk9NQ/+P+LGBe2o=
helm.sh/helm/v3 v3.16.2/go.mod h1:SyTXgKBjNqi2NPsHCW5dDAsHqvGIu0kdNYNH9gQaw70=
helm.sh/helm/v3 v3.16.3 h1:kb8bSxMeRJ+knsK/ovvlaVPfdis0X3/ZhYCSFRP+YmY=
helm.sh/helm/v3 v3.16.3/go.mod h1:zeVWGDR4JJgiRbT3AnNsjYaX8OTJlIE9zC+Q7F7iUSU=
k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0=
Expand Down
43 changes: 41 additions & 2 deletions internal/telemetry/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
libsveltostelemetry "github.com/projectsveltos/libsveltos/lib/telemetry"
Expand Down Expand Up @@ -69,9 +70,11 @@ func StartCollecting(ctx context.Context, c client.Client, sveltosVersion string
return nil
}

// Every hour collects telemetry data and send to to Sveltos telemetry server
// Collects telemetry data and send to to Sveltos telemetry server
func (m *instance) reportData(ctx context.Context) {
ticker := time.NewTicker(time.Hour)
// Data are collected 4 times a day
const six = 6
ticker := time.NewTicker(six * time.Hour)
defer ticker.Stop()

for {
Expand Down Expand Up @@ -140,9 +143,45 @@ func (m *instance) collectData(ctx context.Context, uuid string) (*libsveltostel
}
}

clusterProfiles, profiles, clusterSummaries, err := m.collectConfigurationData(ctx)
if err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to collect Sveltos configuration data: %v", err))
return nil, err
}
data.ClusterProfiles = clusterProfiles
data.Profiles = profiles
data.ClusterSummaries = clusterSummaries

return &data, nil
}

func (m *instance) collectConfigurationData(ctx context.Context) (cpInstances, pInstances, csInstances int, err error) {
logger := log.FromContext(ctx)

var clusterProfiles configv1beta1.ClusterProfileList
if err = m.Client.List(ctx, &clusterProfiles); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to collect clusterProfiles: %v", err))
return
}
cpInstances = len(clusterProfiles.Items)

var profiles configv1beta1.ProfileList
if err = m.Client.List(ctx, &profiles); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to collect Profiles: %v", err))
return
}
pInstances = len(profiles.Items)

var clusterSummaries configv1beta1.ClusterSummaryList
if err = m.Client.List(ctx, &clusterSummaries); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to collect ClusterSummaries: %v", err))
return
}
csInstances = len(clusterSummaries.Items)

return
}

func (m *instance) sendData(ctx context.Context, payload *libsveltostelemetry.Cluster) {
logger := log.FromContext(ctx)

Expand Down

0 comments on commit 059c6ac

Please sign in to comment.