mirror of
https://github.com/netbirdio/netbird.git
synced 2026-03-31 06:24:18 -04:00
[misc] add embedded provider support metrics
count local vs idp users if embedded
This commit is contained in:
@@ -129,6 +129,11 @@ func (s *BaseServer) Start(ctx context.Context) error {
|
||||
if s.Config.IdpManagerConfig != nil && s.Config.IdpManagerConfig.ManagerType != "" {
|
||||
idpManager = s.Config.IdpManagerConfig.ManagerType
|
||||
}
|
||||
|
||||
if s.Config.EmbeddedIdP != nil && s.Config.EmbeddedIdP.Enabled {
|
||||
idpManager = metrics.EmbeddedType
|
||||
}
|
||||
|
||||
metricsWorker := metrics.NewWorker(srvCtx, installationID, s.Store(), s.PeersUpdateManager(), idpManager)
|
||||
go metricsWorker.Run(srvCtx)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/netbirdio/netbird/idp/dex"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/types"
|
||||
@@ -28,6 +29,7 @@ const (
|
||||
defaultPushInterval = 12 * time.Hour
|
||||
// requestTimeout http request timeout
|
||||
requestTimeout = 45 * time.Second
|
||||
EmbeddedType = "embedded"
|
||||
)
|
||||
|
||||
type getTokenResponse struct {
|
||||
@@ -206,6 +208,8 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
||||
peerActiveVersions []string
|
||||
osUIClients map[string]int
|
||||
rosenpassEnabled int
|
||||
localUsers int
|
||||
idpUsers int
|
||||
)
|
||||
start := time.Now()
|
||||
metricsProperties := make(properties)
|
||||
@@ -266,6 +270,16 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
||||
serviceUsers++
|
||||
} else {
|
||||
users++
|
||||
if w.idpManager == EmbeddedType {
|
||||
_, idpID, err := dex.DecodeDexUserID(user.Id)
|
||||
if err == nil {
|
||||
if idpID == "local" {
|
||||
localUsers++
|
||||
} else {
|
||||
idpUsers++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pats += len(user.PATs)
|
||||
}
|
||||
@@ -353,6 +367,8 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
||||
metricsProperties["idp_manager"] = w.idpManager
|
||||
metricsProperties["store_engine"] = w.dataSource.GetStoreEngine()
|
||||
metricsProperties["rosenpass_enabled"] = rosenpassEnabled
|
||||
metricsProperties["local_users_count"] = localUsers
|
||||
metricsProperties["idp_users_count"] = idpUsers
|
||||
|
||||
for protocol, count := range rulesProtocol {
|
||||
metricsProperties["rules_protocol_"+protocol] = count
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
nbdns "github.com/netbirdio/netbird/dns"
|
||||
"github.com/netbirdio/netbird/idp/dex"
|
||||
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"
|
||||
@@ -25,6 +26,8 @@ func (mockDatasource) GetAllConnectedPeers() map[string]struct{} {
|
||||
|
||||
// GetAllAccounts returns a list of *server.Account for use in tests with predefined information
|
||||
func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
||||
localUserID := dex.EncodeDexUserID("10", "local")
|
||||
idpUserID := dex.EncodeDexUserID("20", "zitadel")
|
||||
return []*types.Account{
|
||||
{
|
||||
Id: "1",
|
||||
@@ -98,12 +101,14 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
||||
},
|
||||
Users: map[string]*types.User{
|
||||
"1": {
|
||||
Id: "1",
|
||||
IsServiceUser: true,
|
||||
PATs: map[string]*types.PersonalAccessToken{
|
||||
"1": {},
|
||||
},
|
||||
},
|
||||
"2": {
|
||||
localUserID: {
|
||||
Id: localUserID,
|
||||
IsServiceUser: false,
|
||||
PATs: map[string]*types.PersonalAccessToken{
|
||||
"1": {},
|
||||
@@ -162,12 +167,14 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
||||
},
|
||||
Users: map[string]*types.User{
|
||||
"1": {
|
||||
Id: "1",
|
||||
IsServiceUser: true,
|
||||
PATs: map[string]*types.PersonalAccessToken{
|
||||
"1": {},
|
||||
},
|
||||
},
|
||||
"2": {
|
||||
idpUserID: {
|
||||
Id: idpUserID,
|
||||
IsServiceUser: false,
|
||||
PATs: map[string]*types.PersonalAccessToken{
|
||||
"1": {},
|
||||
@@ -214,6 +221,7 @@ func TestGenerateProperties(t *testing.T) {
|
||||
worker := Worker{
|
||||
dataSource: ds,
|
||||
connManager: ds,
|
||||
idpManager: EmbeddedType,
|
||||
}
|
||||
|
||||
properties := worker.generateProperties(context.Background())
|
||||
@@ -327,4 +335,10 @@ func TestGenerateProperties(t *testing.T) {
|
||||
t.Errorf("expected 1 active_users_last_day, got %d", properties["active_users_last_day"])
|
||||
}
|
||||
|
||||
if properties["local_users_count"] != 1 {
|
||||
t.Errorf("expected 1 local_users_count, got %d", properties["local_users_count"])
|
||||
}
|
||||
if properties["idp_users_count"] != 1 {
|
||||
t.Errorf("expected 1 idp_users_count, got %d", properties["idp_users_count"])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user