diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 89defce3289..6705a34ec7a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,7 +19,7 @@ jobs: - name: codespell uses: codespell-project/actions-codespell@v2 with: - ignore_words_list: erro,clienta,hastable,iif,groupd + ignore_words_list: erro,clienta,hastable,iif,groupd,testin skip: go.mod,go.sum only_warn: 1 golangci: diff --git a/management/server/metrics/selfhosted.go b/management/server/metrics/selfhosted.go index 82b34393f8c..03cb21af1f9 100644 --- a/management/server/metrics/selfhosted.go +++ b/management/server/metrics/selfhosted.go @@ -195,6 +195,10 @@ func (w *Worker) generateProperties(ctx context.Context) properties { groups int routes int routesWithRGGroups int + networks int + networkResources int + networkRouters int + networkRoutersWithPG int nameservers int uiClient int version string @@ -219,6 +223,16 @@ func (w *Worker) generateProperties(ctx context.Context) properties { } groups += len(account.Groups) + networks += len(account.Networks) + networkResources += len(account.NetworkResources) + + networkRouters += len(account.NetworkRouters) + for _, router := range account.NetworkRouters { + if len(router.PeerGroups) > 0 { + networkRoutersWithPG++ + } + } + routes += len(account.Routes) for _, route := range account.Routes { if len(route.PeerGroups) > 0 { @@ -312,6 +326,10 @@ func (w *Worker) generateProperties(ctx context.Context) properties { metricsProperties["rules_with_src_posture_checks"] = rulesWithSrcPostureChecks metricsProperties["posture_checks"] = postureChecks metricsProperties["groups"] = groups + metricsProperties["networks"] = networks + metricsProperties["network_resources"] = networkResources + metricsProperties["network_routers"] = networkRouters + metricsProperties["network_routers_with_groups"] = networkRoutersWithPG metricsProperties["routes"] = routes metricsProperties["routes_with_routing_groups"] = routesWithRGGroups metricsProperties["nameservers"] = nameservers diff --git a/management/server/metrics/selfhosted_test.go b/management/server/metrics/selfhosted_test.go index 1d356387f38..4894c1ac4a8 100644 --- a/management/server/metrics/selfhosted_test.go +++ b/management/server/metrics/selfhosted_test.go @@ -5,6 +5,9 @@ import ( "testing" nbdns "github.com/netbirdio/netbird/dns" + resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types" + routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types" + networkTypes "github.com/netbirdio/netbird/management/server/networks/types" nbpeer "github.com/netbirdio/netbird/management/server/peer" "github.com/netbirdio/netbird/management/server/posture" "github.com/netbirdio/netbird/management/server/store" @@ -172,6 +175,31 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account { }, }, }, + Networks: []*networkTypes.Network{ + { + ID: "1", + AccountID: "1", + }, + }, + NetworkResources: []*resourceTypes.NetworkResource{ + { + ID: "1", + AccountID: "1", + NetworkID: "1", + }, + { + ID: "2", + AccountID: "1", + NetworkID: "1", + }, + }, + NetworkRouters: []*routerTypes.NetworkRouter{ + { + ID: "1", + AccountID: "1", + NetworkID: "1", + }, + }, }, } } @@ -200,6 +228,15 @@ func TestGenerateProperties(t *testing.T) { if properties["routes"] != 2 { t.Errorf("expected 2 routes, got %d", properties["routes"]) } + if properties["networks"] != 1 { + t.Errorf("expected 1 networks, got %d", properties["networks"]) + } + if properties["network_resources"] != 2 { + t.Errorf("expected 2 network_resources, got %d", properties["network_resources"]) + } + if properties["network_routers"] != 1 { + t.Errorf("expected 1 network_routers, got %d", properties["network_routers"]) + } if properties["rules"] != 4 { t.Errorf("expected 4 rules, got %d", properties["rules"]) }