mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
Fix embedded IdP metrics to count local and generic OIDC users (#5498)
This commit is contained in:
@@ -294,9 +294,9 @@ func (w *Worker) generateProperties(ctx context.Context) properties {
|
|||||||
localUsers++
|
localUsers++
|
||||||
} else {
|
} else {
|
||||||
idpUsers++
|
idpUsers++
|
||||||
idpType := extractIdpType(idpID)
|
|
||||||
embeddedIdpTypes[idpType]++
|
|
||||||
}
|
}
|
||||||
|
idpType := extractIdpType(idpID)
|
||||||
|
embeddedIdpTypes[idpType]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,6 +531,9 @@ func createPostRequest(ctx context.Context, endpoint string, payloadStr string)
|
|||||||
// Connector IDs are formatted as "<type>-<xid>" (e.g., "okta-abc123", "zitadel-xyz").
|
// Connector IDs are formatted as "<type>-<xid>" (e.g., "okta-abc123", "zitadel-xyz").
|
||||||
// Returns the type prefix, or "oidc" if no known prefix is found.
|
// Returns the type prefix, or "oidc" if no known prefix is found.
|
||||||
func extractIdpType(connectorID string) string {
|
func extractIdpType(connectorID string) string {
|
||||||
|
if connectorID == "local" {
|
||||||
|
return "local"
|
||||||
|
}
|
||||||
idx := strings.LastIndex(connectorID, "-")
|
idx := strings.LastIndex(connectorID, "-")
|
||||||
if idx <= 0 {
|
if idx <= 0 {
|
||||||
return "oidc"
|
return "oidc"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ func (mockDatasource) GetAllConnectedPeers() map[string]struct{} {
|
|||||||
func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
||||||
localUserID := dex.EncodeDexUserID("10", "local")
|
localUserID := dex.EncodeDexUserID("10", "local")
|
||||||
idpUserID := dex.EncodeDexUserID("20", "zitadel-d5uv82dra0haedlf6kv0")
|
idpUserID := dex.EncodeDexUserID("20", "zitadel-d5uv82dra0haedlf6kv0")
|
||||||
|
oidcUserID := dex.EncodeDexUserID("30", "d6jvvp69kmnc73c9pl40")
|
||||||
return []*types.Account{
|
return []*types.Account{
|
||||||
{
|
{
|
||||||
Id: "1",
|
Id: "1",
|
||||||
@@ -206,6 +207,13 @@ func (mockDatasource) GetAllAccounts(_ context.Context) []*types.Account {
|
|||||||
"1": {},
|
"1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
oidcUserID: {
|
||||||
|
Id: oidcUserID,
|
||||||
|
IsServiceUser: false,
|
||||||
|
PATs: map[string]*types.PersonalAccessToken{
|
||||||
|
"1": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Networks: []*networkTypes.Network{
|
Networks: []*networkTypes.Network{
|
||||||
{
|
{
|
||||||
@@ -278,14 +286,14 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
if properties["rules"] != 4 {
|
if properties["rules"] != 4 {
|
||||||
t.Errorf("expected 4 rules, got %d", properties["rules"])
|
t.Errorf("expected 4 rules, got %d", properties["rules"])
|
||||||
}
|
}
|
||||||
if properties["users"] != 2 {
|
if properties["users"] != 3 {
|
||||||
t.Errorf("expected 1 users, got %d", properties["users"])
|
t.Errorf("expected 3 users, got %d", properties["users"])
|
||||||
}
|
}
|
||||||
if properties["setup_keys_usage"] != 2 {
|
if properties["setup_keys_usage"] != 2 {
|
||||||
t.Errorf("expected 1 setup_keys_usage, got %d", properties["setup_keys_usage"])
|
t.Errorf("expected 1 setup_keys_usage, got %d", properties["setup_keys_usage"])
|
||||||
}
|
}
|
||||||
if properties["pats"] != 4 {
|
if properties["pats"] != 5 {
|
||||||
t.Errorf("expected 4 personal_access_tokens, got %d", properties["pats"])
|
t.Errorf("expected 5 personal_access_tokens, got %d", properties["pats"])
|
||||||
}
|
}
|
||||||
if properties["peers_ssh_enabled"] != 2 {
|
if properties["peers_ssh_enabled"] != 2 {
|
||||||
t.Errorf("expected 2 peers_ssh_enabled, got %d", properties["peers_ssh_enabled"])
|
t.Errorf("expected 2 peers_ssh_enabled, got %d", properties["peers_ssh_enabled"])
|
||||||
@@ -369,14 +377,20 @@ func TestGenerateProperties(t *testing.T) {
|
|||||||
if properties["local_users_count"] != 1 {
|
if properties["local_users_count"] != 1 {
|
||||||
t.Errorf("expected 1 local_users_count, got %d", properties["local_users_count"])
|
t.Errorf("expected 1 local_users_count, got %d", properties["local_users_count"])
|
||||||
}
|
}
|
||||||
if properties["idp_users_count"] != 1 {
|
if properties["idp_users_count"] != 2 {
|
||||||
t.Errorf("expected 1 idp_users_count, got %d", properties["idp_users_count"])
|
t.Errorf("expected 2 idp_users_count, got %d", properties["idp_users_count"])
|
||||||
|
}
|
||||||
|
if properties["embedded_idp_users_local"] != 1 {
|
||||||
|
t.Errorf("expected 1 embedded_idp_users_local, got %v", properties["embedded_idp_users_local"])
|
||||||
}
|
}
|
||||||
if properties["embedded_idp_users_zitadel"] != 1 {
|
if properties["embedded_idp_users_zitadel"] != 1 {
|
||||||
t.Errorf("expected 1 embedded_idp_users_zitadel, got %v", properties["embedded_idp_users_zitadel"])
|
t.Errorf("expected 1 embedded_idp_users_zitadel, got %v", properties["embedded_idp_users_zitadel"])
|
||||||
}
|
}
|
||||||
if properties["embedded_idp_count"] != 1 {
|
if properties["embedded_idp_users_oidc"] != 1 {
|
||||||
t.Errorf("expected 1 embedded_idp_count, got %v", properties["embedded_idp_count"])
|
t.Errorf("expected 1 embedded_idp_users_oidc, got %v", properties["embedded_idp_users_oidc"])
|
||||||
|
}
|
||||||
|
if properties["embedded_idp_count"] != 3 {
|
||||||
|
t.Errorf("expected 3 embedded_idp_count, got %v", properties["embedded_idp_count"])
|
||||||
}
|
}
|
||||||
|
|
||||||
if properties["services"] != 2 {
|
if properties["services"] != 2 {
|
||||||
@@ -436,7 +450,8 @@ func TestExtractIdpType(t *testing.T) {
|
|||||||
{"microsoft-abc123", "microsoft"},
|
{"microsoft-abc123", "microsoft"},
|
||||||
{"authentik-abc123", "authentik"},
|
{"authentik-abc123", "authentik"},
|
||||||
{"keycloak-d5uv82dra0haedlf6kv0", "keycloak"},
|
{"keycloak-d5uv82dra0haedlf6kv0", "keycloak"},
|
||||||
{"local", "oidc"},
|
{"local", "local"},
|
||||||
|
{"d6jvvp69kmnc73c9pl40", "oidc"},
|
||||||
{"", "oidc"},
|
{"", "oidc"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user