mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 08:46:38 +00: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 != "" {
|
if s.Config.IdpManagerConfig != nil && s.Config.IdpManagerConfig.ManagerType != "" {
|
||||||
idpManager = 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)
|
metricsWorker := metrics.NewWorker(srvCtx, installationID, s.Store(), s.PeersUpdateManager(), idpManager)
|
||||||
go metricsWorker.Run(srvCtx)
|
go metricsWorker.Run(srvCtx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
|
"github.com/netbirdio/netbird/idp/dex"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
@@ -28,6 +29,7 @@ const (
|
|||||||
defaultPushInterval = 12 * time.Hour
|
defaultPushInterval = 12 * time.Hour
|
||||||
// requestTimeout http request timeout
|
// requestTimeout http request timeout
|
||||||
requestTimeout = 45 * time.Second
|
requestTimeout = 45 * time.Second
|
||||||
|
EmbeddedType = "embedded"
|
||||||
)
|
)
|
||||||
|
|
||||||
type getTokenResponse struct {
|
type getTokenResponse struct {
|
||||||
@@ -206,6 +208,8 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
peerActiveVersions []string
|
peerActiveVersions []string
|
||||||
osUIClients map[string]int
|
osUIClients map[string]int
|
||||||
rosenpassEnabled int
|
rosenpassEnabled int
|
||||||
|
localUsers int
|
||||||
|
idpUsers int
|
||||||
)
|
)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
metricsProperties := make(properties)
|
metricsProperties := make(properties)
|
||||||
@@ -266,6 +270,16 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
serviceUsers++
|
serviceUsers++
|
||||||
} else {
|
} else {
|
||||||
users++
|
users++
|
||||||
|
if w.idpManager == EmbeddedType {
|
||||||
|
_, idpID, err := dex.DecodeDexUserID(user.Id)
|
||||||
|
if err == nil {
|
||||||
|
if idpID == "local" {
|
||||||
|
localUsers++
|
||||||
|
} else {
|
||||||
|
idpUsers++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pats += len(user.PATs)
|
pats += len(user.PATs)
|
||||||
}
|
}
|
||||||
@@ -353,6 +367,8 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
metricsProperties["idp_manager"] = w.idpManager
|
metricsProperties["idp_manager"] = w.idpManager
|
||||||
metricsProperties["store_engine"] = w.dataSource.GetStoreEngine()
|
metricsProperties["store_engine"] = w.dataSource.GetStoreEngine()
|
||||||
metricsProperties["rosenpass_enabled"] = rosenpassEnabled
|
metricsProperties["rosenpass_enabled"] = rosenpassEnabled
|
||||||
|
metricsProperties["local_users_count"] = localUsers
|
||||||
|
metricsProperties["idp_users_count"] = idpUsers
|
||||||
|
|
||||||
for protocol, count := range rulesProtocol {
|
for protocol, count := range rulesProtocol {
|
||||||
metricsProperties["rules_protocol_"+protocol] = count
|
metricsProperties["rules_protocol_"+protocol] = count
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
|
"github.com/netbirdio/netbird/idp/dex"
|
||||||
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
||||||
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
||||||
networkTypes "github.com/netbirdio/netbird/management/server/networks/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
|
// GetAllAccounts returns a list of *server.Account for use in tests with predefined information
|
||||||
func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
||||||
|
localUserID := dex.EncodeDexUserID("10", "local")
|
||||||
|
idpUserID := dex.EncodeDexUserID("20", "zitadel")
|
||||||
return []*types.Account{
|
return []*types.Account{
|
||||||
{
|
{
|
||||||
Id: "1",
|
Id: "1",
|
||||||
@@ -98,12 +101,14 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
|||||||
},
|
},
|
||||||
Users: map[string]*types.User{
|
Users: map[string]*types.User{
|
||||||
"1": {
|
"1": {
|
||||||
|
Id: "1",
|
||||||
IsServiceUser: true,
|
IsServiceUser: true,
|
||||||
PATs: map[string]*types.PersonalAccessToken{
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
"1": {},
|
"1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"2": {
|
localUserID: {
|
||||||
|
Id: localUserID,
|
||||||
IsServiceUser: false,
|
IsServiceUser: false,
|
||||||
PATs: map[string]*types.PersonalAccessToken{
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
"1": {},
|
"1": {},
|
||||||
@@ -162,12 +167,14 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
|||||||
},
|
},
|
||||||
Users: map[string]*types.User{
|
Users: map[string]*types.User{
|
||||||
"1": {
|
"1": {
|
||||||
|
Id: "1",
|
||||||
IsServiceUser: true,
|
IsServiceUser: true,
|
||||||
PATs: map[string]*types.PersonalAccessToken{
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
"1": {},
|
"1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"2": {
|
idpUserID: {
|
||||||
|
Id: idpUserID,
|
||||||
IsServiceUser: false,
|
IsServiceUser: false,
|
||||||
PATs: map[string]*types.PersonalAccessToken{
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
"1": {},
|
"1": {},
|
||||||
@@ -214,6 +221,7 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
worker := Worker{
|
worker := Worker{
|
||||||
dataSource: ds,
|
dataSource: ds,
|
||||||
connManager: ds,
|
connManager: ds,
|
||||||
|
idpManager: EmbeddedType,
|
||||||
}
|
}
|
||||||
|
|
||||||
properties := worker.generateProperties(context.Background())
|
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"])
|
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