Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UDM metrics counters #150

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,76 @@ import (
"net/http"

"github.com/omec-project/udm/logger"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// UdmStats captures UDM stats
type UdmStats struct {
udmSubscriberDataManagement *prometheus.CounterVec
udmUeContextManagement *prometheus.CounterVec
udmUeAuthentication *prometheus.CounterVec
}

var udmStats *UdmStats

func initUdmStats() *UdmStats {
return &UdmStats{
udmSubscriberDataManagement: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "udm_subscriber_data_management",
Help: "Counter of total Subscriber Data management queries",
}, []string{"query_type", "requested_data_type", "result"}),
udmUeContextManagement: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "udm_ue_context_management",
Help: "Counter of total UE context management queries",
}, []string{"query_type", "requested_data_type", "result"}),
udmUeAuthentication: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "udm_ue_authentication",
Help: "Counter of total UE authentication queries",
}, []string{"query_type", "result"}),
}
}

func (ps *UdmStats) register() error {
if err := prometheus.Register(ps.udmSubscriberDataManagement); err != nil {
return err
}
if err := prometheus.Register(ps.udmUeContextManagement); err != nil {
return err
}
if err := prometheus.Register(ps.udmUeAuthentication); err != nil {
return err
}
return nil
}

func init() {
udmStats = initUdmStats()

if err := udmStats.register(); err != nil {
logger.InitLog.Errorln("UDM Stats register failed")
}
}

// InitMetrics initialises UDM metrics
func InitMetrics() {
http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(":8080", nil); err != nil {
logger.InitLog.Errorf("Could not open metrics port: %v", err)
}
}

// IncrementUdmSubscriberDataManagementStats increments number of total Subscriber Data management queries
func IncrementUdmSubscriberDataManagementStats(queryType, requestedDataType, result string) {
udmStats.udmSubscriberDataManagement.WithLabelValues(queryType, requestedDataType, result).Inc()
}

// IncrementUdmUeContextManagementStats increments number of total UE context management queries
func IncrementUdmUeContextManagementStats(queryType, requestedDataType, result string) {
udmStats.udmUeContextManagement.WithLabelValues(queryType, requestedDataType, result).Inc()
}

// IncrementUdmUeAuthenticationStats increments number of total UE authentication queries
func IncrementUdmUeAuthenticationStats(queryType, result string) {
udmStats.udmUeAuthentication.WithLabelValues(queryType, result).Inc()
}
6 changes: 6 additions & 0 deletions producer/generate_auth_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/omec-project/openapi/models"
udm_context "github.com/omec-project/udm/context"
"github.com/omec-project/udm/logger"
stats "github.com/omec-project/udm/metrics"
"github.com/omec-project/udm/util"
"github.com/omec-project/util/httpwrapper"
"github.com/omec-project/util/milenage"
Expand Down Expand Up @@ -85,15 +86,18 @@ func HandleGenerateAuthDataRequest(request *httpwrapper.Request) *httpwrapper.Re
supiOrSuci := request.Params["supiOrSuci"]
response, problemDetails := GenerateAuthDataProcedure(authInfoRequest, supiOrSuci)
if response != nil {
stats.IncrementUdmUeAuthenticationStats("create", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmUeAuthenticationStats("create", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmUeAuthenticationStats("create", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand All @@ -106,8 +110,10 @@ func HandleConfirmAuthDataRequest(request *httpwrapper.Request) *httpwrapper.Res
problemDetails := ConfirmAuthDataProcedure(authEvent, supi)

if problemDetails != nil {
stats.IncrementUdmUeAuthenticationStats("create", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
} else {
stats.IncrementUdmUeAuthenticationStats("create", "SUCCESS")
return httpwrapper.NewResponse(http.StatusCreated, nil, nil)
}
}
Expand Down
46 changes: 44 additions & 2 deletions producer/subscriber_data_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/omec-project/openapi/models"
udm_context "github.com/omec-project/udm/context"
"github.com/omec-project/udm/logger"
stats "github.com/omec-project/udm/metrics"
"github.com/omec-project/udm/util"
"github.com/omec-project/util/httpwrapper"
)
Expand All @@ -28,15 +29,18 @@ func HandleGetAmDataRequest(request *httpwrapper.Request) *httpwrapper.Response
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getAmDataProcedure(supi, plmnID, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "am-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "am-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "am-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -92,15 +96,18 @@ func HandleGetIdTranslationResultRequest(request *httpwrapper.Request) *httpwrap
gpsi := request.Params["gpsi"]
response, problemDetails := getIdTranslationResultProcedure(gpsi)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "id-translation-result", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "id-translation-result", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "id-translation-result", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -171,15 +178,18 @@ func HandleGetSupiRequest(request *httpwrapper.Request) *httpwrapper.Response {
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getSupiProcedure(supi, plmnID, dataSetNames, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "supi", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "supi", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "supi", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -428,15 +438,18 @@ func HandleGetSharedDataRequest(request *httpwrapper.Request) *httpwrapper.Respo
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getSharedDataProcedure(sharedDataIds, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "shared-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "shared-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "shared-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -497,15 +510,18 @@ func HandleGetSmDataRequest(request *httpwrapper.Request) *httpwrapper.Response
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getSmDataProcedure(supi, plmnID, Dnn, Snssai, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "sm-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "sm-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "sm-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -593,15 +609,18 @@ func HandleGetNssaiRequest(request *httpwrapper.Request) *httpwrapper.Response {
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getNssaiProcedure(supi, plmnID, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "nssai", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "nssai", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "nssai", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -662,15 +681,18 @@ func HandleGetSmfSelectDataRequest(request *httpwrapper.Request) *httpwrapper.Re
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getSmfSelectDataProcedure(supi, plmnID, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "smf-select-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "smf-select-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "smf-select-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -730,11 +752,14 @@ func HandleSubscribeToSharedDataRequest(request *httpwrapper.Request) *httpwrapp
sdmSubscription := request.Body.(models.SdmSubscription)
header, response, problemDetails := subscribeToSharedDataProcedure(&sdmSubscription)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("create", "shared-data-subscriptions", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusCreated, header, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("create", "shared-data-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
} else {
stats.IncrementUdmSubscriberDataManagementStats("create", "shared-data-subscriptions", "FAILURE")
return httpwrapper.NewResponse(http.StatusNotFound, nil, nil)
}
}
Expand Down Expand Up @@ -796,11 +821,14 @@ func HandleSubscribeRequest(request *httpwrapper.Request) *httpwrapper.Response
supi := request.Params["supi"]
header, response, problemDetails := subscribeProcedure(&sdmSubscription, supi)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("create", "sdm-subscriptions", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusCreated, header, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("create", "sdm-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
} else {
stats.IncrementUdmSubscriberDataManagementStats("create", "sdm-subscriptions", "FAILURE")
return httpwrapper.NewResponse(http.StatusNotFound, nil, nil)
}
}
Expand Down Expand Up @@ -865,9 +893,10 @@ func HandleUnsubscribeForSharedDataRequest(request *httpwrapper.Request) *httpwr
subscriptionID := request.Params["subscriptionId"]
problemDetails := unsubscribeForSharedDataProcedure(subscriptionID)
if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("delete", "shared-data-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}

stats.IncrementUdmSubscriberDataManagementStats("delete", "shared-data-subscriptions", "SUCCESS")
return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}

Expand Down Expand Up @@ -915,9 +944,10 @@ func HandleUnsubscribeRequest(request *httpwrapper.Request) *httpwrapper.Respons
subscriptionID := request.Params["subscriptionId"]
problemDetails := unsubscribeProcedure(supi, subscriptionID)
if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("delete", "sdm-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}

stats.IncrementUdmSubscriberDataManagementStats("delete", "sdm-subscriptions", "SUCCESS")
return httpwrapper.NewResponse(http.StatusNoContent, nil, nil)
}

Expand Down Expand Up @@ -967,15 +997,18 @@ func HandleModifyRequest(request *httpwrapper.Request) *httpwrapper.Response {
subscriptionID := request.Params["subscriptionId"]
response, problemDetails := modifyProcedure(&sdmSubsModification, supi, subscriptionID)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("update", "sdm-subscriptions", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("update", "sdm-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("update", "sdm-subscriptions", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -1032,15 +1065,18 @@ func HandleModifyForSharedDataRequest(request *httpwrapper.Request) *httpwrapper
subscriptionID := request.Params["subscriptionId"]
response, problemDetails := modifyForSharedDataProcedure(&sdmSubsModification, supi, subscriptionID)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("update", "shared-data-subscriptions", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("update", "shared-data-subscriptions", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("update", "shared-data-subscriptions", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -1098,15 +1134,18 @@ func HandleGetTraceDataRequest(request *httpwrapper.Request) *httpwrapper.Respon
plmnID := request.Query.Get("plmn-id")
response, problemDetails := getTraceDataProcedure(supi, plmnID)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "trace-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "trace-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "trace-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down Expand Up @@ -1168,15 +1207,18 @@ func HandleGetUeContextInSmfDataRequest(request *httpwrapper.Request) *httpwrapp
supportedFeatures := request.Query.Get("supported-features")
response, problemDetails := getUeContextInSmfDataProcedure(supi, supportedFeatures)
if response != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "ue-context-in-smf-data", "SUCCESS")
// status code is based on SPEC, and option headers
return httpwrapper.NewResponse(http.StatusOK, nil, response)
} else if problemDetails != nil {
stats.IncrementUdmSubscriberDataManagementStats("get", "ue-context-in-smf-data", "FAILURE")
return httpwrapper.NewResponse(int(problemDetails.Status), nil, problemDetails)
}
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Cause: "UNSPECIFIED",
}
stats.IncrementUdmSubscriberDataManagementStats("get", "ue-context-in-smf-data", "FAILURE")
return httpwrapper.NewResponse(http.StatusForbidden, nil, problemDetails)
}

Expand Down
Loading