From b89380b0e8eee736d5336f064c967886a3009ecc Mon Sep 17 00:00:00 2001 From: AmaliMatharaarachchi Date: Wed, 24 Jan 2024 12:43:40 +0530 Subject: [PATCH 01/24] update httprouterefs to routerefs in cc --- .../apis/dp/v1alpha1/api_conversion.go | 16 ++++++++++++++++ common-go-libs/apis/dp/v1alpha2/api_types.go | 6 +++--- .../apis/dp/v1alpha2/api_webhook.go | 11 +++++------ .../apis/dp/v1alpha2/zz_generated.deepcopy.go | 4 ++-- .../config/crd/bases/dp.wso2.com_apis.yaml | 16 ++++++++-------- common-go-libs/go.sum | 1 + helm-charts/crds/dp.wso2.com_apis.yaml | 19 +++++++++---------- 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/common-go-libs/apis/dp/v1alpha1/api_conversion.go b/common-go-libs/apis/dp/v1alpha1/api_conversion.go index 154d6bfbd..85a067880 100644 --- a/common-go-libs/apis/dp/v1alpha1/api_conversion.go +++ b/common-go-libs/apis/dp/v1alpha1/api_conversion.go @@ -39,6 +39,22 @@ func (src *API) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.BasePath = src.Spec.BasePath dst.Spec.Organization = src.Spec.Organization dst.Spec.SystemAPI = src.Spec.SystemAPI + if src.Spec.Production != nil { + src.Spec.Production = []EnvConfig{} + for _, productionRef := range src.Spec.Production { + dst.Spec.Production = append(dst.Spec.Production, v1alpha2.EnvConfig{ + RouteRefs: productionRef.HTTPRouteRefs, + }) + } + } + if src.Spec.Sandbox != nil { + src.Spec.Sandbox = []EnvConfig{} + for _, sandboxRef := range src.Spec.Sandbox { + dst.Spec.Sandbox = append(dst.Spec.Sandbox, v1alpha2.EnvConfig{ + RouteRefs: sandboxRef.HTTPRouteRefs, + }) + } + } // Convert []Property to []v1alpha2.Property var properties []v1alpha2.Property diff --git a/common-go-libs/apis/dp/v1alpha2/api_types.go b/common-go-libs/apis/dp/v1alpha2/api_types.go index 741814b45..4579e5e0b 100644 --- a/common-go-libs/apis/dp/v1alpha2/api_types.go +++ b/common-go-libs/apis/dp/v1alpha2/api_types.go @@ -47,7 +47,7 @@ type APISpec struct { // +optional IsDefaultVersion bool `json:"isDefaultVersion"` - // DefinitionFileRef contains the OpenAPI 3 or Swagger + // DefinitionFileRef contains the // definition of the API in a ConfigMap. // // +optional @@ -124,8 +124,8 @@ type Property struct { // EnvConfig contains the environment specific configuration type EnvConfig struct { - // HTTPRouteRefs denotes the environment of the API. - HTTPRouteRefs []string `json:"httpRouteRefs"` + // RouteRefs denotes the environment of the API. + RouteRefs []string `json:"routeRefs"` } // APIStatus defines the observed state of API diff --git a/common-go-libs/apis/dp/v1alpha2/api_webhook.go b/common-go-libs/apis/dp/v1alpha2/api_webhook.go index e347680a7..19de63456 100644 --- a/common-go-libs/apis/dp/v1alpha2/api_webhook.go +++ b/common-go-libs/apis/dp/v1alpha2/api_webhook.go @@ -91,7 +91,6 @@ func (r *API) ValidateDelete() (admission.Warnings, error) { // validateAPI validate api crd fields func (r *API) validateAPI() error { - loggers.LoggerAPKOperator.Error("validating...") var allErrs field.ErrorList conf := config.ReadConfigs() namespaces := conf.CommonController.Operator.Namespaces @@ -127,17 +126,18 @@ func (r *API) validateAPI() error { allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("organization"), "Organization can not be empty")) } - if !(len(r.Spec.Production) > 0 && r.Spec.Production[0].HTTPRouteRefs != nil && len(r.Spec.Production[0].HTTPRouteRefs) > 0) && !(len(r.Spec.Sandbox) > 0 && r.Spec.Sandbox[0].HTTPRouteRefs != nil && len(r.Spec.Sandbox[0].HTTPRouteRefs) > 0) { + if !(len(r.Spec.Production) > 0 && r.Spec.Production[0].RouteRefs != nil && len(r.Spec.Production[0].RouteRefs) > 0) && + !(len(r.Spec.Sandbox) > 0 && r.Spec.Sandbox[0].RouteRefs != nil && len(r.Spec.Sandbox[0].RouteRefs) > 0) { allErrs = append(allErrs, field.Required(field.NewPath("spec"), "both API production and sandbox endpoint references cannot be empty")) } var prodHTTPRoute1, sandHTTPRoute1 []string if len(r.Spec.Production) > 0 { - prodHTTPRoute1 = r.Spec.Production[0].HTTPRouteRefs + prodHTTPRoute1 = r.Spec.Production[0].RouteRefs } if len(r.Spec.Sandbox) > 0 { - sandHTTPRoute1 = r.Spec.Sandbox[0].HTTPRouteRefs + sandHTTPRoute1 = r.Spec.Sandbox[0].RouteRefs } if isEmptyStringsInArray(prodHTTPRoute1) { @@ -263,8 +263,7 @@ func validateGzip(name, namespace string) (string, string) { configMap := &corev1.ConfigMap{} if err := c.Get(context.Background(), types.NamespacedName{Name: string(name), Namespace: namespace}, configMap); err == nil { var apiDef []byte - for key, val := range configMap.BinaryData { - loggers.LoggerAPKOperator.Error(key) + for _, val := range configMap.BinaryData { // config map data key is "swagger.yaml" apiDef = []byte(val) } diff --git a/common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go b/common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go index 0400f7780..5a869b17c 100644 --- a/common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go +++ b/common-go-libs/apis/dp/v1alpha2/zz_generated.deepcopy.go @@ -531,8 +531,8 @@ func (in *DeploymentStatus) DeepCopy() *DeploymentStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EnvConfig) DeepCopyInto(out *EnvConfig) { *out = *in - if in.HTTPRouteRefs != nil { - in, out := &in.HTTPRouteRefs, &out.HTTPRouteRefs + if in.RouteRefs != nil { + in, out := &in.RouteRefs, &out.RouteRefs *out = make([]string, len(*in)) copy(*out, *in) } diff --git a/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml b/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml index 304529c66..7846de3ca 100644 --- a/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml +++ b/common-go-libs/config/crd/bases/dp.wso2.com_apis.yaml @@ -259,8 +259,8 @@ spec: pattern: ^[/][a-zA-Z0-9~/_.-]*$ type: string definitionFileRef: - description: DefinitionFileRef contains the OpenAPI 3 or Swagger definition - of the API in a ConfigMap. + description: DefinitionFileRef contains the definition of the API + in a ConfigMap. type: string definitionPath: default: /api-definition @@ -285,13 +285,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true @@ -302,13 +302,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true diff --git a/common-go-libs/go.sum b/common-go-libs/go.sum index e4cdd32d2..aedc921d5 100644 --- a/common-go-libs/go.sum +++ b/common-go-libs/go.sum @@ -140,6 +140,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/helm-charts/crds/dp.wso2.com_apis.yaml b/helm-charts/crds/dp.wso2.com_apis.yaml index fc4e0a2a9..7846de3ca 100644 --- a/helm-charts/crds/dp.wso2.com_apis.yaml +++ b/helm-charts/crds/dp.wso2.com_apis.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.12.0 name: apis.dp.wso2.com spec: group: dp.wso2.com @@ -260,8 +259,8 @@ spec: pattern: ^[/][a-zA-Z0-9~/_.-]*$ type: string definitionFileRef: - description: DefinitionFileRef contains the OpenAPI 3 or SDL file - in gzipped format. definition of the API in a ConfigMap. + description: DefinitionFileRef contains the definition of the API + in a ConfigMap. type: string definitionPath: default: /api-definition @@ -286,13 +285,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true @@ -303,13 +302,13 @@ spec: items: description: EnvConfig contains the environment specific configuration properties: - httpRouteRefs: - description: HTTPRouteRefs denotes the environment of the API. + routeRefs: + description: RouteRefs denotes the environment of the API. items: type: string type: array required: - - httpRouteRefs + - routeRefs type: object maxItems: 1 nullable: true From 474e48130d508bf11b09ef0a2fc726c78989113d Mon Sep 17 00:00:00 2001 From: AmaliMatharaarachchi Date: Wed, 24 Jan 2024 14:27:24 +0530 Subject: [PATCH 02/24] rename httprouterefs to routerefs --- .../envoyconf/routes_with_clusters_test.go | 12 ++++----- .../operator/controllers/dp/api_controller.go | 12 ++++----- .../dp/ratelimitpolicy_controller.go | 4 +-- .../apis/dp/v1alpha1/api_conversion.go | 26 ------------------- 4 files changed, 14 insertions(+), 40 deletions(-) diff --git a/adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go b/adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go index 03ca8957c..6fae0262d 100644 --- a/adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go +++ b/adapter/internal/oasparser/envoyconf/routes_with_clusters_test.go @@ -48,7 +48,7 @@ func TestCreateRoutesWithClustersWithExactAndRegularExpressionRules(t *testing.T BasePath: "/test-api/2.0.0", Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ "test-api-2-prod-http-route", }, }, @@ -218,7 +218,7 @@ func generateSampleAPI(apiName string, apiVersion string, basePath string) synch BasePath: basePath, Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ apiName + "-prod-http-route", }, }, @@ -281,7 +281,7 @@ func TestCreateRoutesWithClustersWithMultiplePathPrefixRules(t *testing.T) { BasePath: "/test-api/1.0.0", Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ "test-api-1-prod-http-route", }, }, @@ -430,7 +430,7 @@ func TestCreateRoutesWithClustersWithBackendTLSConfigs(t *testing.T) { BasePath: "/test-api-3/1.0.0", Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ "test-api-3-prod-http-route", }, }, @@ -553,7 +553,7 @@ func TestCreateRoutesWithClustersDifferentBackendRefs(t *testing.T) { BasePath: "/test-api-different-backendrefs/1.0.0", Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ "test-api-different-backendrefs-prod-http-route", }, }, @@ -645,7 +645,7 @@ func TestCreateRoutesWithClustersSameBackendRefs(t *testing.T) { BasePath: "/test-api-same-backendrefs/1.0.0", Production: []v1alpha2.EnvConfig{ { - HTTPRouteRefs: []string{ + RouteRefs: []string{ "test-api-same-backendrefs-prod-http-route", }, }, diff --git a/adapter/internal/operator/controllers/dp/api_controller.go b/adapter/internal/operator/controllers/dp/api_controller.go index a6220f937..339e74c87 100644 --- a/adapter/internal/operator/controllers/dp/api_controller.go +++ b/adapter/internal/operator/controllers/dp/api_controller.go @@ -300,10 +300,10 @@ func (apiReconciler *APIReconciler) applyStartupAPIs() { func (apiReconciler *APIReconciler) resolveAPIRefs(ctx context.Context, api dpv1alpha2.API) (*synchronizer.APIEvent, error) { var prodRouteRefs, sandRouteRefs []string if len(api.Spec.Production) > 0 { - prodRouteRefs = api.Spec.Production[0].HTTPRouteRefs + prodRouteRefs = api.Spec.Production[0].RouteRefs } if len(api.Spec.Sandbox) > 0 { - sandRouteRefs = api.Spec.Sandbox[0].HTTPRouteRefs + sandRouteRefs = api.Spec.Sandbox[0].RouteRefs } apiState := &synchronizer.APIState{ @@ -1484,7 +1484,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { api := rawObj.(*dpv1alpha2.API) var httpRoutes []string if len(api.Spec.Production) > 0 { - for _, ref := range api.Spec.Production[0].HTTPRouteRefs { + for _, ref := range api.Spec.Production[0].RouteRefs { if ref != "" { httpRoutes = append(httpRoutes, types.NamespacedName{ @@ -1495,7 +1495,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { } } if len(api.Spec.Sandbox) > 0 { - for _, ref := range api.Spec.Sandbox[0].HTTPRouteRefs { + for _, ref := range api.Spec.Sandbox[0].RouteRefs { if ref != "" { httpRoutes = append(httpRoutes, types.NamespacedName{ @@ -1515,7 +1515,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { api := rawObj.(*dpv1alpha2.API) var gqlRoutes []string if len(api.Spec.Production) > 0 { - for _, ref := range api.Spec.Production[0].HTTPRouteRefs { + for _, ref := range api.Spec.Production[0].RouteRefs { if ref != "" { gqlRoutes = append(gqlRoutes, types.NamespacedName{ @@ -1526,7 +1526,7 @@ func addIndexes(ctx context.Context, mgr manager.Manager) error { } } if len(api.Spec.Sandbox) > 0 { - for _, ref := range api.Spec.Sandbox[0].HTTPRouteRefs { + for _, ref := range api.Spec.Sandbox[0].RouteRefs { if ref != "" { gqlRoutes = append(gqlRoutes, types.NamespacedName{ diff --git a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go index 6b5bc538b..782341ae8 100644 --- a/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go +++ b/common-controller/internal/operator/controllers/dp/ratelimitpolicy_controller.go @@ -289,7 +289,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte if len(api.Spec.Production) > 0 && api.Spec.APIType == "REST" { resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, - api.Spec.Production[0].HTTPRouteRefs) + api.Spec.Production[0].RouteRefs) if err != nil { return nil, err } @@ -301,7 +301,7 @@ func (ratelimitReconsiler *RateLimitPolicyReconciler) marshelRateLimit(ctx conte if len(api.Spec.Sandbox) > 0 && api.Spec.APIType == "REST" { resolveResourceList, err := ratelimitReconsiler.getHTTPRouteResourceList(ctx, ratelimitKey, ratelimitPolicy, - api.Spec.Sandbox[0].HTTPRouteRefs) + api.Spec.Sandbox[0].RouteRefs) if err != nil { return nil, err } diff --git a/common-go-libs/apis/dp/v1alpha1/api_conversion.go b/common-go-libs/apis/dp/v1alpha1/api_conversion.go index 85a067880..4de702be0 100644 --- a/common-go-libs/apis/dp/v1alpha1/api_conversion.go +++ b/common-go-libs/apis/dp/v1alpha1/api_conversion.go @@ -63,19 +63,6 @@ func (src *API) ConvertTo(dstRaw conversion.Hub) error { } dst.Spec.APIProperties = properties - // Convert []EnvConfig to []v1alpha2.EnvConfig - var production []v1alpha2.EnvConfig - for _, p := range src.Spec.Production { - production = append(production, v1alpha2.EnvConfig(p)) - } - dst.Spec.Production = production - - var sandbox []v1alpha2.EnvConfig - for _, s := range src.Spec.Sandbox { - sandbox = append(sandbox, v1alpha2.EnvConfig(s)) - } - dst.Spec.Sandbox = sandbox - // Status dst.Status.DeploymentStatus = v1alpha2.DeploymentStatus(src.Status.DeploymentStatus) @@ -107,19 +94,6 @@ func (src *API) ConvertFrom(srcRaw conversion.Hub) error { } src.Spec.APIProperties = properties - // Convert []EnvConfig to []v1alpha1.EnvConfig - var production []EnvConfig - for _, p := range dst.Spec.Production { - production = append(production, EnvConfig(p)) - } - src.Spec.Production = production - - var sandbox []EnvConfig - for _, s := range dst.Spec.Sandbox { - sandbox = append(sandbox, EnvConfig(s)) - } - src.Spec.Sandbox = sandbox - // Status src.Status.DeploymentStatus = DeploymentStatus(dst.Status.DeploymentStatus) From b64bb30ea938e473d9ea90a76464bdc6e0f84507 Mon Sep 17 00:00:00 2001 From: AmaliMatharaarachchi Date: Wed, 24 Jan 2024 14:39:58 +0530 Subject: [PATCH 03/24] rename httprouterefs to routerefs in crs --- .../integration/tests/resources/base/manifests.yaml | 2 +- .../resources/tests/all-http-methods-for-wildcard.yaml | 2 +- .../tests/resources/tests/api-different-listener.yaml | 2 +- .../resources/tests/api-policy-with-jwt-generator.yaml | 2 +- .../tests/resources/tests/api-with-backend-base-path.yaml | 2 +- .../tests/resources/tests/api-with-cors-policy.yaml | 4 ++-- .../tests/resources/tests/api-with-operational-policy.yaml | 2 +- .../tests/resources/tests/api-with-path-params.yaml | 2 +- .../resources/tests/api-with-request-header-modify.yaml | 2 +- .../resources/tests/api-with-response-header-modify.yaml | 2 +- .../resources/tests/api-without-backend-base-path.yaml | 2 +- .../tests/resources/tests/custom-auth-header.yaml | 2 +- .../tests/resources/tests/custom-policy-ratelimiting.yaml | 2 +- .../tests/default-api-version-ratelimit-resource-level.yaml | 2 +- .../resources/tests/default-api-version-ratelimit.yaml | 2 +- .../tests/resources/tests/default-api-version.yaml | 2 +- .../resources/tests/different-endpoint-with-same-route.yaml | 2 +- .../tests/resources/tests/disable-api-level-jwt.yaml | 6 +++--- .../tests/resources/tests/disable-api-level-security.yaml | 2 +- .../tests/resources/tests/disable-resource-level-jwt.yaml | 6 +++--- .../resources/tests/disable-resource-level-security.yaml | 2 +- .../tests/resources/tests/fetch-api-definition.yaml | 2 +- .../resources/tests/fetch-non-existing-api-definition.yaml | 2 +- .../integration/tests/resources/tests/gql-api.yaml | 2 +- .../tests/resources/tests/interceptors-api-level.yaml | 2 +- .../tests/resources/tests/interceptors-resource-level.yaml | 2 +- .../tests/resources/tests/multiple_port_listener.yaml | 4 ++-- .../tests/resources/tests/prod-and-sand-apis.yaml | 6 +++--- .../tests/resources/tests/ratelimit-priority.yaml | 2 +- .../integration/tests/resources/tests/resource-scopes.yaml | 2 +- .../integration/tests/resources/tests/trailing-slash.yaml | 2 +- 31 files changed, 39 insertions(+), 39 deletions(-) diff --git a/test/integration/integration/tests/resources/base/manifests.yaml b/test/integration/integration/tests/resources/base/manifests.yaml index aa8a03411..5d4ef2460 100644 --- a/test/integration/integration/tests/resources/base/manifests.yaml +++ b/test/integration/integration/tests/resources/base/manifests.yaml @@ -426,6 +426,6 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - all-http-methods-for-wildcard-httproute organization: wso2-org1111 diff --git a/test/integration/integration/tests/resources/tests/all-http-methods-for-wildcard.yaml b/test/integration/integration/tests/resources/tests/all-http-methods-for-wildcard.yaml index 75fc0e4c5..fdbe8313d 100644 --- a/test/integration/integration/tests/resources/tests/all-http-methods-for-wildcard.yaml +++ b/test/integration/integration/tests/resources/tests/all-http-methods-for-wildcard.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - all-http-methods-for-wildcard-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-different-listener.yaml b/test/integration/integration/tests/resources/tests/api-different-listener.yaml index 65f80d101..b8c03f24f 100644 --- a/test/integration/integration/tests/resources/tests/api-different-listener.yaml +++ b/test/integration/integration/tests/resources/tests/api-different-listener.yaml @@ -26,7 +26,7 @@ spec: basePath: /test-api-with-different-listener/v1.0.0 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - test-api-with-different-listener-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-policy-with-jwt-generator.yaml b/test/integration/integration/tests/resources/tests/api-policy-with-jwt-generator.yaml index 8adfb9a2f..bbc22ce45 100644 --- a/test/integration/integration/tests/resources/tests/api-policy-with-jwt-generator.yaml +++ b/test/integration/integration/tests/resources/tests/api-policy-with-jwt-generator.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - api-policy-with-jwt-generator-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-backend-base-path.yaml b/test/integration/integration/tests/resources/tests/api-with-backend-base-path.yaml index acc89d9ff..9fb505524 100644 --- a/test/integration/integration/tests/resources/tests/api-with-backend-base-path.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-backend-base-path.yaml @@ -38,7 +38,7 @@ spec: isDefaultVersion: true #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - test-api-with-backend-base-path-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-cors-policy.yaml b/test/integration/integration/tests/resources/tests/api-with-cors-policy.yaml index e2aca8699..6c71a76c2 100644 --- a/test/integration/integration/tests/resources/tests/api-with-cors-policy.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-cors-policy.yaml @@ -26,7 +26,7 @@ spec: basePath: /cors-policy-api/1.0.0 isDefaultVersion: true production: - - httpRouteRefs: + - routeRefs: - cors-policy-httproute organization: wso2-org --- @@ -95,7 +95,7 @@ spec: apiVersion: 1.0.0 basePath: /no-cors-policy-api/1.0.0 production: - - httpRouteRefs: + - routeRefs: - no-cors-policy-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-operational-policy.yaml b/test/integration/integration/tests/resources/tests/api-with-operational-policy.yaml index be2fbef20..6d350c3b8 100644 --- a/test/integration/integration/tests/resources/tests/api-with-operational-policy.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-operational-policy.yaml @@ -43,7 +43,7 @@ spec: isDefaultVersion: true #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - test-api-with-operatinal-policy-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-path-params.yaml b/test/integration/integration/tests/resources/tests/api-with-path-params.yaml index 81304619e..e4e1e053a 100644 --- a/test/integration/integration/tests/resources/tests/api-with-path-params.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-path-params.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - test-api-with-path-params-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-request-header-modify.yaml b/test/integration/integration/tests/resources/tests/api-with-request-header-modify.yaml index 7ac6a07da..d045c275e 100644 --- a/test/integration/integration/tests/resources/tests/api-with-request-header-modify.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-request-header-modify.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - test-api-with-request-header-modify-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-with-response-header-modify.yaml b/test/integration/integration/tests/resources/tests/api-with-response-header-modify.yaml index 416247d03..6596cd0cd 100644 --- a/test/integration/integration/tests/resources/tests/api-with-response-header-modify.yaml +++ b/test/integration/integration/tests/resources/tests/api-with-response-header-modify.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - test-api-with-response-header-modify-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/api-without-backend-base-path.yaml b/test/integration/integration/tests/resources/tests/api-without-backend-base-path.yaml index 54358cdb7..2353d1ee4 100644 --- a/test/integration/integration/tests/resources/tests/api-without-backend-base-path.yaml +++ b/test/integration/integration/tests/resources/tests/api-without-backend-base-path.yaml @@ -26,7 +26,7 @@ spec: basePath: /no-basepath/v1 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - no-backend-base-path-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/custom-auth-header.yaml b/test/integration/integration/tests/resources/tests/custom-auth-header.yaml index 585359006..3f602c0b0 100644 --- a/test/integration/integration/tests/resources/tests/custom-auth-header.yaml +++ b/test/integration/integration/tests/resources/tests/custom-auth-header.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - custom-auth-header-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/custom-policy-ratelimiting.yaml b/test/integration/integration/tests/resources/tests/custom-policy-ratelimiting.yaml index a41adb3e5..751228c0e 100644 --- a/test/integration/integration/tests/resources/tests/custom-policy-ratelimiting.yaml +++ b/test/integration/integration/tests/resources/tests/custom-policy-ratelimiting.yaml @@ -70,7 +70,7 @@ spec: basePath: /http-bin-api/1.0.8 #definitionFileRef: swagger-definition-http-bin-api production: - - httpRouteRefs: + - routeRefs: - prod-http-route-http-bin-api-basic organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256 --- diff --git a/test/integration/integration/tests/resources/tests/default-api-version-ratelimit-resource-level.yaml b/test/integration/integration/tests/resources/tests/default-api-version-ratelimit-resource-level.yaml index ab977102e..07eb23cdf 100644 --- a/test/integration/integration/tests/resources/tests/default-api-version-ratelimit-resource-level.yaml +++ b/test/integration/integration/tests/resources/tests/default-api-version-ratelimit-resource-level.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - default-api-version-ratelimit-resource-level-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/default-api-version-ratelimit.yaml b/test/integration/integration/tests/resources/tests/default-api-version-ratelimit.yaml index 95aa3a7bd..3a9b9a5db 100644 --- a/test/integration/integration/tests/resources/tests/default-api-version-ratelimit.yaml +++ b/test/integration/integration/tests/resources/tests/default-api-version-ratelimit.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - default-api-version-ratelimit-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/default-api-version.yaml b/test/integration/integration/tests/resources/tests/default-api-version.yaml index 64a6440b5..b63875b0f 100644 --- a/test/integration/integration/tests/resources/tests/default-api-version.yaml +++ b/test/integration/integration/tests/resources/tests/default-api-version.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - default-api-version-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/different-endpoint-with-same-route.yaml b/test/integration/integration/tests/resources/tests/different-endpoint-with-same-route.yaml index 02fc2318d..a7bda1ef9 100644 --- a/test/integration/integration/tests/resources/tests/different-endpoint-with-same-route.yaml +++ b/test/integration/integration/tests/resources/tests/different-endpoint-with-same-route.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - different-endpoint-with-same-route-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/disable-api-level-jwt.yaml b/test/integration/integration/tests/resources/tests/disable-api-level-jwt.yaml index f28abe7f6..646c908f8 100644 --- a/test/integration/integration/tests/resources/tests/disable-api-level-jwt.yaml +++ b/test/integration/integration/tests/resources/tests/disable-api-level-jwt.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-api-level-jwt-httproute organization: wso2-org --- @@ -88,7 +88,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-api-level-jwt1-httproute organization: wso2-org --- @@ -159,7 +159,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-api-level-jwt2-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/disable-api-level-security.yaml b/test/integration/integration/tests/resources/tests/disable-api-level-security.yaml index 3a112479c..fd4558e0b 100644 --- a/test/integration/integration/tests/resources/tests/disable-api-level-security.yaml +++ b/test/integration/integration/tests/resources/tests/disable-api-level-security.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-api-security-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/disable-resource-level-jwt.yaml b/test/integration/integration/tests/resources/tests/disable-resource-level-jwt.yaml index a6c559be9..f7459d308 100644 --- a/test/integration/integration/tests/resources/tests/disable-resource-level-jwt.yaml +++ b/test/integration/integration/tests/resources/tests/disable-resource-level-jwt.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-resource-level-jwt-httproute organization: wso2-org --- @@ -94,7 +94,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-resource-level-jwt1-httproute organization: wso2-org --- @@ -171,7 +171,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-resource-level-jwt2-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/disable-resource-level-security.yaml b/test/integration/integration/tests/resources/tests/disable-resource-level-security.yaml index d9e11c97a..bd66d7241 100644 --- a/test/integration/integration/tests/resources/tests/disable-resource-level-security.yaml +++ b/test/integration/integration/tests/resources/tests/disable-resource-level-security.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - disable-resoruce-security-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/fetch-api-definition.yaml b/test/integration/integration/tests/resources/tests/fetch-api-definition.yaml index 34a519318..97e5a1d79 100644 --- a/test/integration/integration/tests/resources/tests/fetch-api-definition.yaml +++ b/test/integration/integration/tests/resources/tests/fetch-api-definition.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true definitionFileRef: definition-file-swagger production: - - httpRouteRefs: + - routeRefs: - fetch-api-defintion-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/fetch-non-existing-api-definition.yaml b/test/integration/integration/tests/resources/tests/fetch-non-existing-api-definition.yaml index 60c341572..eb25ac95a 100644 --- a/test/integration/integration/tests/resources/tests/fetch-non-existing-api-definition.yaml +++ b/test/integration/integration/tests/resources/tests/fetch-non-existing-api-definition.yaml @@ -25,7 +25,7 @@ spec: apiVersion: v1.0.0 basePath: /fetch-non-existing-api-definition/v1.0.0 production: - - httpRouteRefs: + - routeRefs: - fetch-non-api-definition-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/gql-api.yaml b/test/integration/integration/tests/resources/tests/gql-api.yaml index 474e9bca4..224dfba25 100644 --- a/test/integration/integration/tests/resources/tests/gql-api.yaml +++ b/test/integration/integration/tests/resources/tests/gql-api.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: false definitionFileRef: gql-sdl production: - - httpRouteRefs: + - routeRefs: - gql-api-gqlroute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/interceptors-api-level.yaml b/test/integration/integration/tests/resources/tests/interceptors-api-level.yaml index 5ca0c2725..af5d12643 100644 --- a/test/integration/integration/tests/resources/tests/interceptors-api-level.yaml +++ b/test/integration/integration/tests/resources/tests/interceptors-api-level.yaml @@ -26,7 +26,7 @@ spec: basePath: /interceptor/2.0.0 #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - api-interceptor-route organization: wso2-org apiProperties: diff --git a/test/integration/integration/tests/resources/tests/interceptors-resource-level.yaml b/test/integration/integration/tests/resources/tests/interceptors-resource-level.yaml index c4f790e83..06882d25a 100644 --- a/test/integration/integration/tests/resources/tests/interceptors-resource-level.yaml +++ b/test/integration/integration/tests/resources/tests/interceptors-resource-level.yaml @@ -26,7 +26,7 @@ spec: basePath: /interceptor/1.0.0 #definitionFileRef: swagger-definition-webhook production: - - httpRouteRefs: + - routeRefs: - resource-interceptor-route organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/multiple_port_listener.yaml b/test/integration/integration/tests/resources/tests/multiple_port_listener.yaml index e1ffa437f..8dd1e4b96 100644 --- a/test/integration/integration/tests/resources/tests/multiple_port_listener.yaml +++ b/test/integration/integration/tests/resources/tests/multiple_port_listener.yaml @@ -26,7 +26,7 @@ spec: basePath: /test-api-with-multiple-port-listener/v1.0.0 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - test-api-with-multiple-port-listener-httproute organization: wso2-org --- @@ -42,7 +42,7 @@ spec: basePath: /test-api-with-multiple-port-listener-1/v1.0.0 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - test-api-with-multiple-port-listener-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/prod-and-sand-apis.yaml b/test/integration/integration/tests/resources/tests/prod-and-sand-apis.yaml index 16327affa..82c99b640 100644 --- a/test/integration/integration/tests/resources/tests/prod-and-sand-apis.yaml +++ b/test/integration/integration/tests/resources/tests/prod-and-sand-apis.yaml @@ -26,7 +26,7 @@ spec: basePath: /prod-sand-test-api/v1 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - prod-httproute organization: wso2-org --- @@ -128,9 +128,9 @@ spec: basePath: /prod-sand-test-api/v1 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - prod-httproute sandbox: - - httpRouteRefs: + - routeRefs: - sand-httproute organization: wso2-org diff --git a/test/integration/integration/tests/resources/tests/ratelimit-priority.yaml b/test/integration/integration/tests/resources/tests/ratelimit-priority.yaml index b2a59aeb3..819f5eac1 100644 --- a/test/integration/integration/tests/resources/tests/ratelimit-priority.yaml +++ b/test/integration/integration/tests/resources/tests/ratelimit-priority.yaml @@ -27,7 +27,7 @@ spec: isDefaultVersion: true #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - ratelimit-priority-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/resource-scopes.yaml b/test/integration/integration/tests/resources/tests/resource-scopes.yaml index 7cb94975e..d0b5908ab 100644 --- a/test/integration/integration/tests/resources/tests/resource-scopes.yaml +++ b/test/integration/integration/tests/resources/tests/resource-scopes.yaml @@ -26,7 +26,7 @@ spec: basePath: /resource-scopes/v1 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - resource-scopes-httproute organization: wso2-org --- diff --git a/test/integration/integration/tests/resources/tests/trailing-slash.yaml b/test/integration/integration/tests/resources/tests/trailing-slash.yaml index c79dbed85..1b9bcd09d 100644 --- a/test/integration/integration/tests/resources/tests/trailing-slash.yaml +++ b/test/integration/integration/tests/resources/tests/trailing-slash.yaml @@ -26,7 +26,7 @@ spec: basePath: /trailing-slash/v1.0.0 #definitionFileRef: definition-file production: - - httpRouteRefs: + - routeRefs: - trailing-slash-httproute organization: wso2-org --- From ce0bb1a3d1d421f244016415298cab8a9c537247 Mon Sep 17 00:00:00 2001 From: AmaliMatharaarachchi Date: Wed, 24 Jan 2024 15:16:32 +0530 Subject: [PATCH 04/24] remove debug logs --- .../data-plane/config-deployer/config-ds-configmap.yaml | 2 +- .../data-plane/gateway-components/common-log-conf.yaml | 2 +- helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml index 89a53a89d..83be6b02a 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml @@ -23,7 +23,7 @@ metadata: data: Config.toml: | [ballerina.log] - level = "DEBUG" + level = "INFO" [ballerina.http] traceLogConsole = true [wso2.config_deployer_service.keyStores.tls] diff --git a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml index 0fa0bb360..ad7d5adb8 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml @@ -87,7 +87,7 @@ data: logLevel = "INFO" # LogLevels can be "DEBG", "FATL", "ERRO", "WARN", "INFO", "PANC" [[pkg]] name = "github.com/wso2/apk/common-controller/internal/utils" - logLevel = "DEBG" # LogLevels can be "DEBG", "FATL", "ERRO", "WARN", "INFO", "PANC" + logLevel = "INFO" # LogLevels can be "DEBG", "FATL", "ERRO", "WARN", "INFO", "PANC" [[pkg]] # The logging configuration for Router diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml index 2abf4dcf8..5ac4bf1be 100644 --- a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml +++ b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml @@ -23,7 +23,7 @@ metadata: data: Config.toml: | [ballerina.log] - level = "DEBUG" + level = "INFO" [ballerina.http] traceLogConsole = true # Sample configurations From 8d674e0990b412d399c1c1d927b4a9b82376c791 Mon Sep 17 00:00:00 2001 From: AmaliMatharaarachchi Date: Wed, 6 Mar 2024 10:46:08 +0530 Subject: [PATCH 05/24] fix lint issues --- adapter/internal/operator/synchronizer/synchronizer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/internal/operator/synchronizer/synchronizer.go b/adapter/internal/operator/synchronizer/synchronizer.go index 3305399d5..8f177d80c 100644 --- a/adapter/internal/operator/synchronizer/synchronizer.go +++ b/adapter/internal/operator/synchronizer/synchronizer.go @@ -224,7 +224,7 @@ func deployMultipleAPIsInGateway(event *APIEvent, successChannel *chan SuccessEv updated := xds.UpdateXdsCacheOnAPIChange(updatedLabelsMap) if updated { - loggers.LoggerAPKOperator.Info("XDS cache updated for apis: %+v", updatedAPIs) + loggers.LoggerAPKOperator.Infof("XDS cache updated for apis: %+v", updatedAPIs) *successChannel <- SuccessEvent{ APINamespacedName: updatedAPIs, State: event.EventType, @@ -234,7 +234,7 @@ func deployMultipleAPIsInGateway(event *APIEvent, successChannel *chan SuccessEv paritionCh <- event } } else { - loggers.LoggerAPKOperator.Info("XDS cache not updated for APIs : %+v", updatedAPIs) + loggers.LoggerAPKOperator.Infof("XDS cache not updated for APIs : %+v", updatedAPIs) } } From 273952a95c25b107efe2691fb287923a3692c81e Mon Sep 17 00:00:00 2001 From: tharindu1st Date: Wed, 6 Mar 2024 16:37:30 +0530 Subject: [PATCH 06/24] httpRouteRef=>routeRef change --- developer/tryout/samples/sample-api.yaml | 6 +++--- .../wso2-apk-config-deployer-api.yaml | 4 ++-- .../wso2-apk-config-generator-api.yaml | 4 ++-- .../gateway-runtime/jwks-domain-api.yaml | 4 ++-- .../idp/authenticationEndpoint-domain-api.yaml | 4 ++-- .../templates/idp/commonoauth-domain-api.yaml | 4 ++-- helm-charts/templates/idp/dcr-domain-api.yaml | 4 ++-- helm-charts/templates/idp/oauth-domain-api.yaml | 4 ++-- .../config-deployer-service/ballerina/APIClient.bal | 4 ++-- .../ballerina/Dependencies.toml | 2 +- .../ballerina/Dependencies.toml.template | 13 +++++++------ .../ballerina/modules/model/API.bal | 2 +- .../api-interceptor/sample-api.yaml | 4 ++-- .../gateway-interceptor/sample-api.yaml | 4 ++-- .../resource-interceptor/sample-api.yaml | 4 ++-- .../k8s-resources/api.yaml | 4 ++-- test/performance/artifacts/api.yaml | 4 ++-- 17 files changed, 38 insertions(+), 37 deletions(-) diff --git a/developer/tryout/samples/sample-api.yaml b/developer/tryout/samples/sample-api.yaml index 50de733e3..a954bae37 100644 --- a/developer/tryout/samples/sample-api.yaml +++ b/developer/tryout/samples/sample-api.yaml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ----------------------------------------------------------------------- -apiVersion: dp.wso2.com/v1alpha1 +apiVersion: dp.wso2.com/v1alpha2 kind: API metadata: name: http-bin-api @@ -24,11 +24,11 @@ spec: basePath: /http-bin-api/1.0.8 definitionFileRef: swagger-definition-http-bin-api production: - - httpRouteRefs: + - routeRefs: - prod-http-route-http-bin-api-p1 - prod-http-route-http-bin-api-p2 sandbox: - - httpRouteRefs: + - routeRefs: - sand-http-route-http-bin-api organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256 --- diff --git a/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-deployer-api.yaml b/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-deployer-api.yaml index d1a39ea98..c51f866fd 100644 --- a/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-deployer-api.yaml +++ b/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-deployer-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if and .Values.wso2.apk.dp.enabled .Values.wso2.apk.dp.configdeployer.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: "{{ template "apk-helm.resource.prefix" . }}-wso2-apk-config-deployer-api" namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: organization: "apk-system" definitionFileRef: "{{ template "apk-helm.resource.prefix" . }}-wso2-apk-config-deployer-api-definition" production: - - httpRouteRefs: + - routeRefs: - "{{ template "apk-helm.resource.prefix" . }}-config-deploy-api-route" systemAPI: true {{- end -}} diff --git a/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-generator-api.yaml b/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-generator-api.yaml index 61f4dc246..7a8dc6645 100644 --- a/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-generator-api.yaml +++ b/helm-charts/templates/data-plane/config-deployer/wso2-apk-config-generator-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if and .Values.wso2.apk.dp.enabled .Values.wso2.apk.dp.configdeployer.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: "{{ template "apk-helm.resource.prefix" . }}-wso2-apk-config-generator-api" namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: organization: "apk-system" definitionFileRef: "{{ template "apk-helm.resource.prefix" . }}-wso2-apk-config-generator-api-definition" production: - - httpRouteRefs: + - routeRefs: - "{{ template "apk-helm.resource.prefix" . }}-config-api-route" systemAPI: true {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/jwks-domain-api.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/jwks-domain-api.yaml index 7e5eecc6a..85767ba67 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/jwks-domain-api.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/jwks-domain-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if .Values.idp.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: {{ template "apk-helm.resource.prefix" . }}-jwks-endpoint-ds-api namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: organization: "apk-system" isDefaultVersion: true production: - - httpRouteRefs: + - routeRefs: - {{ template "apk-helm.resource.prefix" . }}-jwks-endpoint-ds-httproute systemAPI: true {{- end -}} diff --git a/helm-charts/templates/idp/authenticationEndpoint-domain-api.yaml b/helm-charts/templates/idp/authenticationEndpoint-domain-api.yaml index 9b6b31268..c759c62f6 100644 --- a/helm-charts/templates/idp/authenticationEndpoint-domain-api.yaml +++ b/helm-charts/templates/idp/authenticationEndpoint-domain-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if .Values.idp.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: {{ template "apk-helm.resource.prefix" . }}-authentication-endpoint-ds-api namespace: {{ .Release.Namespace }} @@ -29,7 +29,7 @@ spec: basePath: "/authenticationEndpoint/1.0.0" organization: "apk-system" production: - - httpRouteRefs: + - routeRefs: - {{ template "apk-helm.resource.prefix" . }}-authentication-endpoint-ds-httproute systemAPI: true {{- end -}} diff --git a/helm-charts/templates/idp/commonoauth-domain-api.yaml b/helm-charts/templates/idp/commonoauth-domain-api.yaml index dfcc4602a..9e0d7a04d 100644 --- a/helm-charts/templates/idp/commonoauth-domain-api.yaml +++ b/helm-charts/templates/idp/commonoauth-domain-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if .Values.idp.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: {{ template "apk-helm.resource.prefix" . }}-commonoauth-api namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: isDefaultVersion: true organization: "apk-system" production: - - httpRouteRefs: + - routeRefs: - {{ template "apk-helm.resource.prefix" . }}-commonoauth-ds-httproute systemAPI: true {{- end -}} diff --git a/helm-charts/templates/idp/dcr-domain-api.yaml b/helm-charts/templates/idp/dcr-domain-api.yaml index f4280ac65..d5a22a14b 100644 --- a/helm-charts/templates/idp/dcr-domain-api.yaml +++ b/helm-charts/templates/idp/dcr-domain-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if .Values.idp.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: {{ template "apk-helm.resource.prefix" . }}-dcr-api namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: isDefaultVersion: true organization: "apk-system" production: - - httpRouteRefs: + - routeRefs: - {{ template "apk-helm.resource.prefix" . }}-dcr-ds-httproute systemAPI: true {{- end -}} diff --git a/helm-charts/templates/idp/oauth-domain-api.yaml b/helm-charts/templates/idp/oauth-domain-api.yaml index 6f13f7976..179ef80c8 100644 --- a/helm-charts/templates/idp/oauth-domain-api.yaml +++ b/helm-charts/templates/idp/oauth-domain-api.yaml @@ -15,7 +15,7 @@ # under the License. {{- if .Values.idp.enabled }} kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: {{ template "apk-helm.resource.prefix" . }}-oauth-api namespace: {{ .Release.Namespace }} @@ -30,7 +30,7 @@ spec: isDefaultVersion: true organization: "apk-system" production: - - httpRouteRefs: + - routeRefs: - {{ template "apk-helm.resource.prefix" . }}-oauth-ds-httproute systemAPI: true {{- end -}} diff --git a/runtime/config-deployer-service/ballerina/APIClient.bal b/runtime/config-deployer-service/ballerina/APIClient.bal index d6441725f..9a59bb912 100644 --- a/runtime/config-deployer-service/ballerina/APIClient.bal +++ b/runtime/config-deployer-service/ballerina/APIClient.bal @@ -450,10 +450,10 @@ public class APIClient { } if productionRoutes.length() > 0 { - k8sAPI.spec.production = [{httpRouteRefs: productionRoutes}]; + k8sAPI.spec.production = [{routeRef: productionRoutes}]; } if sandboxRoutes.length() > 0 { - k8sAPI.spec.sandbox = [{httpRouteRefs: sandboxRoutes}]; + k8sAPI.spec.sandbox = [{routeRef: sandboxRoutes}]; } if apkConf.id != () { k8sAPI.metadata["annotations"] = {[API_UUID_ANNOTATION] : apkConf.id}; diff --git a/runtime/config-deployer-service/ballerina/Dependencies.toml b/runtime/config-deployer-service/ballerina/Dependencies.toml index 9c45a8850..5ba9b8e5a 100644 --- a/runtime/config-deployer-service/ballerina/Dependencies.toml +++ b/runtime/config-deployer-service/ballerina/Dependencies.toml @@ -70,7 +70,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.7" +version = "2.10.8" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, diff --git a/runtime/config-deployer-service/ballerina/Dependencies.toml.template b/runtime/config-deployer-service/ballerina/Dependencies.toml.template index 526506973..c07db3430 100644 --- a/runtime/config-deployer-service/ballerina/Dependencies.toml.template +++ b/runtime/config-deployer-service/ballerina/Dependencies.toml.template @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.0" +distribution-version = "2201.8.5" [[package]] org = "ballerina" @@ -33,7 +33,7 @@ dependencies = [ [[package]] org = "ballerina" name = "constraint" -version = "1.4.0" +version = "1.5.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -44,7 +44,7 @@ modules = [ [[package]] org = "ballerina" name = "crypto" -version = "2.5.0" +version = "2.6.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -70,7 +70,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.10.7" +version = "2.10.8" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -368,7 +368,7 @@ modules = [ [[package]] org = "ballerinax" name = "postgresql" -version = "1.10.0" +version = "1.11.0" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "io"}, @@ -397,7 +397,8 @@ dependencies = [ modules = [ {org = "wso2", packageName = "apk_common_lib", moduleName = "apk_common_lib"}, {org = "wso2", packageName = "apk_common_lib", moduleName = "apk_common_lib.java.io"}, - {org = "wso2", packageName = "apk_common_lib", moduleName = "apk_common_lib.java.lang"} + {org = "wso2", packageName = "apk_common_lib", moduleName = "apk_common_lib.java.lang"}, + {org = "wso2", packageName = "apk_common_lib", moduleName = "apk_common_lib.org.wso2.apk.common"} ] [[package]] diff --git a/runtime/config-deployer-service/ballerina/modules/model/API.bal b/runtime/config-deployer-service/ballerina/modules/model/API.bal index b0510e540..7cb81ea24 100644 --- a/runtime/config-deployer-service/ballerina/modules/model/API.bal +++ b/runtime/config-deployer-service/ballerina/modules/model/API.bal @@ -58,7 +58,7 @@ public type APIStatus record { }; public type EnvConfig record { - string[] httpRouteRefs; + string[] routeRef; }; public type APIList record { diff --git a/samples/custom-ratelimit-interceptor-service/api-interceptor/sample-api.yaml b/samples/custom-ratelimit-interceptor-service/api-interceptor/sample-api.yaml index d78610b24..39a150ff5 100644 --- a/samples/custom-ratelimit-interceptor-service/api-interceptor/sample-api.yaml +++ b/samples/custom-ratelimit-interceptor-service/api-interceptor/sample-api.yaml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ----------------------------------------------------------------------- -apiVersion: dp.wso2.com/v1alpha1 +apiVersion: dp.wso2.com/v1alpha2 kind: API metadata: name: http-bin-api-basic @@ -24,7 +24,7 @@ spec: basePath: /http-bin-api/1.0.8 definitionFileRef: swagger-definition-http-bin-api production: - - httpRouteRefs: + - routeRefs: - prod-http-route-http-bin-api-basic organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256 --- diff --git a/samples/custom-ratelimit-interceptor-service/gateway-interceptor/sample-api.yaml b/samples/custom-ratelimit-interceptor-service/gateway-interceptor/sample-api.yaml index d78610b24..39a150ff5 100644 --- a/samples/custom-ratelimit-interceptor-service/gateway-interceptor/sample-api.yaml +++ b/samples/custom-ratelimit-interceptor-service/gateway-interceptor/sample-api.yaml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ----------------------------------------------------------------------- -apiVersion: dp.wso2.com/v1alpha1 +apiVersion: dp.wso2.com/v1alpha2 kind: API metadata: name: http-bin-api-basic @@ -24,7 +24,7 @@ spec: basePath: /http-bin-api/1.0.8 definitionFileRef: swagger-definition-http-bin-api production: - - httpRouteRefs: + - routeRefs: - prod-http-route-http-bin-api-basic organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256 --- diff --git a/samples/custom-ratelimit-interceptor-service/resource-interceptor/sample-api.yaml b/samples/custom-ratelimit-interceptor-service/resource-interceptor/sample-api.yaml index 85adc1264..87daab988 100644 --- a/samples/custom-ratelimit-interceptor-service/resource-interceptor/sample-api.yaml +++ b/samples/custom-ratelimit-interceptor-service/resource-interceptor/sample-api.yaml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ----------------------------------------------------------------------- -apiVersion: dp.wso2.com/v1alpha1 +apiVersion: dp.wso2.com/v1alpha2 kind: API metadata: name: http-bin-api-basic @@ -24,7 +24,7 @@ spec: basePath: /http-bin-api/1.0.8 definitionFileRef: swagger-definition-http-bin-api production: - - httpRouteRefs: + - routeRefs: - prod-http-route-http-bin-api-basic organization: a3b58ccf-6ecc-4557-b5bb-0a35cce38256 --- diff --git a/samples/request-response-mediation-interceptors/k8s-resources/api.yaml b/samples/request-response-mediation-interceptors/k8s-resources/api.yaml index 472e8305b..14acdb6a1 100644 --- a/samples/request-response-mediation-interceptors/k8s-resources/api.yaml +++ b/samples/request-response-mediation-interceptors/k8s-resources/api.yaml @@ -14,7 +14,7 @@ # limitations under the License. # ----------------------------------------------------------------------- -apiVersion: dp.wso2.com/v1alpha1 +apiVersion: dp.wso2.com/v1alpha2 kind: API metadata: name: interceptor-api @@ -31,7 +31,7 @@ spec: - name: propertyName2 value: "propertyValue2" production: - - httpRouteRefs: + - routeRefs: - interceptor-route --- apiVersion: dp.wso2.com/v1alpha1 diff --git a/test/performance/artifacts/api.yaml b/test/performance/artifacts/api.yaml index 23aa76b99..0343f8f85 100644 --- a/test/performance/artifacts/api.yaml +++ b/test/performance/artifacts/api.yaml @@ -1,6 +1,6 @@ --- kind: "API" -apiVersion: "dp.wso2.com/v1alpha1" +apiVersion: "dp.wso2.com/v1alpha2" metadata: name: "default-api-definition-endpoint-test" labels: @@ -18,7 +18,7 @@ spec: organization: "default" definitionFileRef: "default-api-definition-endpoint-test-definition" production: - - httpRouteRefs: + - routeRefs: - "01ee3d7a-36d0-176e-aee2-6b601948eb64" sandbox: null apiProperties: [] From bc0601a65e84ae0b8700f008040adc27597afb1d Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Thu, 22 Feb 2024 09:05:53 +0530 Subject: [PATCH 07/24] Add modify api test --- .../modifyAPI/aNewResourceAddedAPI.yaml | 31 ++++++++++++ .../modifyAPI/aResourceRemovedAPI.yaml | 27 +++++++++++ .../apk-confs/modifyAPI/originalAPI.yaml | 27 +++++++++++ .../resources/tests/api/ModifyAPITest.feature | 48 +++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml create mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml create mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml create mode 100644 test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml new file mode 100644 index 000000000..ebe29160d --- /dev/null +++ b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml @@ -0,0 +1,31 @@ +--- +name: "EmployeeServiceAPI" +basePath: "/test" +version: "3.14" +type: "REST" +defaultVersion: false +id: "modify-api-test" +endpointConfigurations: + production: + endpoint: "http://backend:80/anything" +operations: + - target: "/employee" + verb: "GET" + secured: true + scopes: [] + - target: "/employee1" + verb: "GET" + secured: true + scopes: [] + - target: "/employee" + verb: "POST" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "PUT" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "DELETE" + secured: true + scopes: [] diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml new file mode 100644 index 000000000..e6fdd91a0 --- /dev/null +++ b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml @@ -0,0 +1,27 @@ +--- +name: "EmployeeServiceAPI" +basePath: "/test" +version: "3.14" +type: "REST" +defaultVersion: false +id: "modify-api-test" +endpointConfigurations: + production: + endpoint: "http://backend:80/anything" +operations: + - target: "/employee1" + verb: "GET" + secured: true + scopes: [] + - target: "/employee" + verb: "POST" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "PUT" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "DELETE" + secured: true + scopes: [] diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml new file mode 100644 index 000000000..35a766609 --- /dev/null +++ b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml @@ -0,0 +1,27 @@ +--- +name: "EmployeeServiceAPI" +basePath: "/test" +version: "3.14" +type: "REST" +defaultVersion: false +id: "modify-api-test" +endpointConfigurations: + production: + endpoint: "http://backend:80/anything" +operations: + - target: "/employee" + verb: "GET" + secured: true + scopes: [] + - target: "/employee" + verb: "POST" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "PUT" + secured: true + scopes: [] + - target: "/employee/{employeeId}" + verb: "DELETE" + secured: true + scopes: [] diff --git a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature new file mode 100644 index 000000000..b3af0ba0f --- /dev/null +++ b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature @@ -0,0 +1,48 @@ +Feature: API Deployment and invocation + Scenario: Deploying an API and basic http method invocations + Given The system is ready + And I have a valid subscription + When I use the APK Conf file "artifacts/apk-confs/modifyAPI/originalAPI.yaml" + And the definition file "artifacts/definitions/employees_api.json" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + |Authorization|bearer ${accessToken}| + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" + And I eventually receive 200 response code, not accepting + |429| + And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And the response status code should be 404 + When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml" + And the definition file "artifacts/definitions/employees_api.json" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + | Authorization | bearer ${accessToken} | + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" + And I eventually receive 200 response code, not accepting + | 429 | + And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And the response status code should be 200 + When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml" + And the definition file "artifacts/definitions/employees_api.json" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + | Authorization | bearer ${accessToken} | + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" + And I eventually receive 404 response code, not accepting + | 429 | + And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And the response status code should be 200 + + Scenario Outline: Undeploy API + Given The system is ready + And I have a valid subscription + When I undeploy the API whose ID is "" + Then the response status code should be + + Examples: + | apiID | expectedStatusCode | + | modify-api-test | 202 | + From f9d923f5811dbea7676ca8f6c4b3382ac3237ee5 Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 28 Feb 2024 14:42:49 +0530 Subject: [PATCH 08/24] Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature --- .../src/test/resources/tests/api/ModifyAPITest.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature index b3af0ba0f..26bf55b03 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature @@ -33,7 +33,7 @@ Feature: API Deployment and invocation And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" And I eventually receive 404 response code, not accepting | 429 | - And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" And the response status code should be 200 Scenario Outline: Undeploy API From 9dfe2f6c2341ac73b0613653a0eb62db9acb23ce Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 28 Feb 2024 14:42:58 +0530 Subject: [PATCH 09/24] Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature --- .../src/test/resources/tests/api/ModifyAPITest.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature index 26bf55b03..ae7d45eb0 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature @@ -11,7 +11,7 @@ Feature: API Deployment and invocation And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" And I eventually receive 200 response code, not accepting |429| - And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" And the response status code should be 404 When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml" And the definition file "artifacts/definitions/employees_api.json" From fa299536b9fb532107759b7bafd0221c82a00488 Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 28 Feb 2024 14:43:07 +0530 Subject: [PATCH 10/24] Update test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature --- .../src/test/resources/tests/api/ModifyAPITest.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature index ae7d45eb0..80e180ab0 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature @@ -22,7 +22,7 @@ Feature: API Deployment and invocation And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" And I eventually receive 200 response code, not accepting | 429 | - And I send "POST" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" + And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" And the response status code should be 200 When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml" And the definition file "artifacts/definitions/employees_api.json" From 4006891547c41965fbc487d2bbc5a1e9100044c2 Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 6 Mar 2024 10:00:02 +0530 Subject: [PATCH 11/24] Change gateway name --- .../tests/resources/tests/jwt-api-level-security.yaml | 2 +- .../tests/resources/tests/jwt-resource-level-security.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/integration/tests/resources/tests/jwt-api-level-security.yaml b/test/integration/integration/tests/resources/tests/jwt-api-level-security.yaml index d9a08b245..7bfb7e9df 100644 --- a/test/integration/integration/tests/resources/tests/jwt-api-level-security.yaml +++ b/test/integration/integration/tests/resources/tests/jwt-api-level-security.yaml @@ -40,7 +40,7 @@ spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway - name: default + name: wso2-apk-default namespace: apk-integration-test sectionName: httpslistener hostnames: diff --git a/test/integration/integration/tests/resources/tests/jwt-resource-level-security.yaml b/test/integration/integration/tests/resources/tests/jwt-resource-level-security.yaml index 529b48aa5..332351577 100644 --- a/test/integration/integration/tests/resources/tests/jwt-resource-level-security.yaml +++ b/test/integration/integration/tests/resources/tests/jwt-resource-level-security.yaml @@ -40,7 +40,7 @@ spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway - name: default + name: wso2-apk-default namespace: apk-integration-test sectionName: httpslistener hostnames: From 7c3a922c047355b22f26a2210331682fda46b590 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Mon, 19 Feb 2024 16:04:34 +0530 Subject: [PATCH 12/24] Add prometheus configs to adapter enforcer router --- adapter/config/default_config.go | 6 + adapter/config/types.go | 8 +- adapter/go.mod | 6 + adapter/go.sum | 20 ++ adapter/internal/adapter/adapter.go | 9 + adapter/pkg/metrics/metrics.go | 215 ++++++++++++++++++ adapter/pkg/metrics/types.go | 24 ++ .../org.wso2.apk.enforcer/build.gradle | 1 + .../org/wso2/apk/enforcer/jmx/JMXUtils.java | 4 +- .../metrics/jmx/api/ExtAuthMetricsMXBean.java | 36 +-- .../metrics/jmx/impl/ExtAuthMetrics.java | 67 +++--- .../metrics/prometheus-jmx-config.yml | 44 ++++ .../adapter/adapter-deployment.yaml | 4 + .../adapter/adapter-service.yaml | 5 + .../gateway-runtime/enforcer-service.yaml | 5 + .../gateway-runtime-deployment.yaml | 22 +- .../prometheus-jmx-configmap.yaml | 31 +++ .../gateway-runtime/router-service.yaml | 31 +++ helm-charts/values.yaml | 3 + libs.versions.toml | 2 + 20 files changed, 495 insertions(+), 48 deletions(-) create mode 100644 adapter/pkg/metrics/metrics.go create mode 100644 adapter/pkg/metrics/types.go create mode 100644 gateway/enforcer/resources/metrics/prometheus-jmx-config.yml create mode 100644 helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml create mode 100644 helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml diff --git a/adapter/config/default_config.go b/adapter/config/default_config.go index 86630ad57..1fe3847d7 100644 --- a/adapter/config/default_config.go +++ b/adapter/config/default_config.go @@ -32,6 +32,12 @@ var defaultConfig = &Config{ Namespaces: nil, }, Environment: "Default", + Metrics: metrics{ + Enabled: true, + Type: "prometheus", + Port: 18006, + CollectionInterval: 5, + }, }, Envoy: envoy{ ListenerCodecType: "AUTO", diff --git a/adapter/config/types.go b/adapter/config/types.go index f51f2577f..8e8954f38 100644 --- a/adapter/config/types.go +++ b/adapter/config/types.go @@ -93,6 +93,8 @@ type adapter struct { Operator operator // Environment of the Adapter Environment string + // Metric represents configurations to expose/export go metrics + Metrics metrics } // Envoy Listener Component related configurations. @@ -299,8 +301,10 @@ type tracing struct { } type metrics struct { - Enabled bool - Type string + Enabled bool + Type string + Port int32 + CollectionInterval int32 } type analyticsAdapter struct { diff --git a/adapter/go.mod b/adapter/go.mod index b276c876e..d90a94e1d 100644 --- a/adapter/go.mod +++ b/adapter/go.mod @@ -10,6 +10,9 @@ require ( github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 github.com/pelletier/go-toml v1.9.5 + github.com/prometheus/client_golang v1.18.0 + github.com/prometheus/procfs v0.12.0 + github.com/shirou/gopsutil/v3 v3.24.1 github.com/sirupsen/logrus v1.9.0 github.com/wso2/apk/common-go-libs v0.0.0-20231208100153-24bee7b4bd81 golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb @@ -47,6 +50,7 @@ require ( github.com/imdario/mergo v0.3.16 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -59,6 +63,8 @@ require ( github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/vektah/gqlparser v1.3.1 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect diff --git a/adapter/go.sum b/adapter/go.sum index 26378461c..c943d5bd9 100644 --- a/adapter/go.sum +++ b/adapter/go.sum @@ -62,6 +62,7 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -88,6 +89,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= @@ -112,6 +115,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= @@ -121,6 +129,12 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= +github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -136,6 +150,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqfU= github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -182,9 +200,11 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/adapter/internal/adapter/adapter.go b/adapter/internal/adapter/adapter.go index 08ba6d809..83575ee23 100644 --- a/adapter/internal/adapter/adapter.go +++ b/adapter/internal/adapter/adapter.go @@ -20,6 +20,7 @@ package adapter import ( "crypto/tls" + "strings" "time" discoveryv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3" @@ -33,6 +34,7 @@ import ( wso2_server "github.com/wso2/apk/adapter/pkg/discovery/protocol/server/v3" "github.com/wso2/apk/adapter/pkg/health" healthservice "github.com/wso2/apk/adapter/pkg/health/api/wso2/health/service" + metrics "github.com/wso2/apk/adapter/pkg/metrics" "github.com/wso2/apk/adapter/pkg/utils/tlsutils" "context" @@ -154,6 +156,13 @@ func Run(conf *config.Config) { } logger.LoggerAPK.Info("Starting adapter ....") + + // Start the metrics server + if conf.Adapter.Metrics.Enabled && strings.EqualFold(conf.Adapter.Metrics.Type, metrics.PrometheusMetricType) { + logger.LoggerAPK.Info("Starting Prometheus Metrics Server ....") + go metrics.StartPrometheusMetricsServer(conf.Adapter.Metrics.Port, conf.Adapter.Metrics.CollectionInterval) + } + cache := xds.GetXdsCache() enforcerCache := xds.GetEnforcerCache() enforcerAPICache := xds.GetEnforcerAPICache() diff --git a/adapter/pkg/metrics/metrics.go b/adapter/pkg/metrics/metrics.go new file mode 100644 index 000000000..62a82e254 --- /dev/null +++ b/adapter/pkg/metrics/metrics.go @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Package metrics holds the implementation for exposing adapter metrics to prometheus +package metrics + +import ( + "fmt" + "net/http" + "os" + "runtime" + "strconv" + "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/procfs" + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/host" + "github.com/shirou/gopsutil/v3/load" + "github.com/shirou/gopsutil/v3/mem" + logger "github.com/wso2/apk/adapter/internal/loggers" + "github.com/wso2/apk/adapter/pkg/logging" +) + +var ( + prometheusMetricRegistry = prometheus.NewRegistry() + + hostInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "host_info", + Help: "Host Info", + }, []string{"os"}) + + availableCPUs = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_available_cpu_total", + Help: "Number of available CPUs.", + }) + + freePhysicalMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_free_physical_memory_bytes", + Help: "Amount of free physical memory.", + }) + + totalVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_total_virtual_memory_bytes", + Help: "Amount of total virtual memory.", + }) + usedVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_used_virtual_memory_bytes", + Help: "Amount of used virtual memory.", + }) + + systemCPULoad = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_system_cpu_load_percentage", + Help: "System-wide CPU usage as a percentage.", + }) + + loadAvg = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "os_system_load_average", + Help: "Current load of CPU in the host system for the last {x} minutes", + }, []string{"duration"}) + + processStartTime = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "process_start_time_seconds", + Help: "Start time of the process since unix epoch in seconds.", + }) + + processOpenFDs = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "process_open_fds", + Help: "Number of open file descriptors.", + }) +) + +func init() { + // Register the Go collector with the registry + goCollector := collectors.NewGoCollector() + prometheusMetricRegistry.MustRegister(goCollector) + + // Register other metrics + prometheusMetricRegistry.MustRegister(hostInfo, availableCPUs, freePhysicalMemory, usedVirtualMemory, totalVirtualMemory, + systemCPULoad, loadAvg, processStartTime, processOpenFDs) +} + +// recordMetrics record custom golang metrics +var recordMetrics = func(collectionInterval int32) { + for { + host, err := host.Info() + if handleError(err, "Failed to get host info") { + return + } + hostInfo.WithLabelValues(host.OS).Set(1) + availableCPUs.Set(float64(runtime.NumCPU())) + + v, err := mem.VirtualMemory() + if handleError(err, "Failed to read virtual memory metrics") { + return + } + freePhysicalMemory.Set(float64(v.Free)) + usedVirtualMemory.Set(float64(v.Used)) + totalVirtualMemory.Set(float64(v.Total)) + + percentages, err := cpu.Percent(0, false) + if handleError(err, "Failed to read cpu usage metrics") || len(percentages) == 0 { + return + } + totalPercentage := 0.0 + for _, p := range percentages { + totalPercentage += p + } + averagePercentage := totalPercentage / float64(len(percentages)) + systemCPULoad.Set(averagePercentage) + + pid := os.Getpid() + p, err := procfs.NewProc(pid) + if handleError(err, "Failed to get current process") { + return + } + stat, err := p.Stat() + if handleError(err, "Failed to get process stats") { + return + } + t, err := stat.StartTime() + if handleError(err, "Failed to read process start time") { + return + } + processStartTime.Set(t) + fds, err := p.FileDescriptorsLen() + if handleError(err, "Failed to read file descriptor count") { + return + } + processOpenFDs.Set(float64(fds)) + + avg, err := load.Avg() + if handleError(err, "Failed to read cpu load averages") { + return + } + loadAvg.WithLabelValues("1m").Set(avg.Load1) + loadAvg.WithLabelValues("5m").Set(avg.Load5) + loadAvg.WithLabelValues("15m").Set(avg.Load15) + + // Sleep before the next measurement + time.Sleep(time.Duration(collectionInterval) * time.Second) + } + +} + +func handleError(err error, message string) bool { + if err != nil { + logger.LoggerAPK.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintf(message, err.Error()), + Severity: logging.MINOR, + ErrorCode: 1109, + }) + return true + } + return false +} + +// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. +func StartPrometheusMetricsServer(port int32, collectionInterval int32) { + done := make(chan struct{}) // Channel to indicate recordMetrics routine exit + + // Start the Prometheus metrics server + go func() { + http.Handle("/metrics", promhttp.HandlerFor(prometheusMetricRegistry, promhttp.HandlerOpts{})) + err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) + if err != nil { + logger.LoggerAPK.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintln("Prometheus metrics server error:", err), + Severity: logging.MAJOR, + ErrorCode: 1110, + }) + } + }() + + for { + // Start the recordMetrics goroutine + go func() { + defer func() { + if r := recover(); r != nil { + logger.LoggerAPK.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintln("recordMetrics goroutine exited with error:", r), + Severity: logging.MAJOR, + ErrorCode: 1111, + }) + } + }() + recordMetrics(collectionInterval) + done <- struct{}{} // Signal that the goroutine has completed + }() + + // Wait for the previous recordMetrics goroutine to complete + <-done + + // Log and restart the goroutine + logger.LoggerAPK.Info("Restarting recordMetrics goroutine...") + time.Sleep(3 * time.Second) + } +} \ No newline at end of file diff --git a/adapter/pkg/metrics/types.go b/adapter/pkg/metrics/types.go new file mode 100644 index 000000000..8e9fae144 --- /dev/null +++ b/adapter/pkg/metrics/types.go @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + package metrics + + const ( + // PrometheusMetricType prometheus metric type + PrometheusMetricType = "prometheus" + ) \ No newline at end of file diff --git a/gateway/enforcer/org.wso2.apk.enforcer/build.gradle b/gateway/enforcer/org.wso2.apk.enforcer/build.gradle index 8d1b50f11..5a7bc193a 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/build.gradle +++ b/gateway/enforcer/org.wso2.apk.enforcer/build.gradle @@ -71,6 +71,7 @@ dependencies { implementation libs.opentelemetry.extension.trace.propagators implementation libs.opentelemetry.sdk implementation libs.opentelemetry.semconv + implementation libs.prometheus implementation libs.snakeyaml implementation libs.sun.saaj.impl implementation libs.swagger.core.v3 diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/jmx/JMXUtils.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/jmx/JMXUtils.java index 2c2028c8a..f460437ae 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/jmx/JMXUtils.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/jmx/JMXUtils.java @@ -21,7 +21,7 @@ */ public class JMXUtils { - private static final String CHOREO_CONNECT_JMX_METRICS_ENABLE = "choreo.connect.jmx.metrics.enabled"; + private static final String APK_JMX_METRICS_ENABLE = "apk.jmx.metrics.enabled"; /** * Returns true if jmx metrics enabled as a system property, otherwise false. @@ -29,6 +29,6 @@ public class JMXUtils { * @return boolean */ public static boolean isJMXMetricsEnabled() { - return Boolean.getBoolean(CHOREO_CONNECT_JMX_METRICS_ENABLE); + return Boolean.getBoolean(APK_JMX_METRICS_ENABLE); } } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java index 5bd3fc919..105eccf13 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java @@ -23,31 +23,32 @@ public interface ExtAuthMetricsMXBean { /** * Getter for total request count. - * + * * @return long */ public long getTotalRequestCount(); /** * Getter for average response time in milli seconds. - * - * @return long + * + * @return double */ - public long getAverageResponseTimeMillis(); + public double getAverageResponseTimeMillis(); /** * Getter for maximum response time in milliseconds. - * - * @return long + * + * @return double */ - public long getMaxResponseTimeMillis(); + public double getMaxResponseTimeMillis(); + /** * Getter for mimnimum response time in milliseconds. - * - * @return long + * + * @return double */ - public long getMinResponseTimeMillis(); + public double getMinResponseTimeMillis(); /** * Resets all the metrics to thier initial values. @@ -55,8 +56,17 @@ public interface ExtAuthMetricsMXBean { public void resetExtAuthMetrics(); /** - * Resets all the metrics to thier initial values. + * Get request count in last five minutes window + * + * @return long + */ + public long getRequestCountInLastFiveMinuteWindow(); + + /** + * Get the start time of request count window + * + * @return */ - public long getRequestCountInLastFiveMinutes(); + public long getRequestCountWindowStartTimeMillis(); -} +} \ No newline at end of file diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java index 9f558ba1f..e01ac205c 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java @@ -30,33 +30,35 @@ public class ExtAuthMetrics extends TimerTask implements ExtAuthMetricsMXBean { private static final long REQUEST_COUNT_INTERVAL_MILLIS = 5 * 60 * 1000; private static ExtAuthMetrics extAuthMetricsMBean = null; - private long requestCountInLastFiveMinutes = 0; + private long requestCountInLastFiveMinuteWindow = 0; + private long requestCountWindowStartTimeMillis = System.currentTimeMillis(); private long totalRequestCount = 0; - private long averageResponseTimeMillis = 0; - private long maxResponseTimeMillis = Long.MIN_VALUE; - private long minResponseTimeMillis = Long.MAX_VALUE; + private double averageResponseTimeMillis = 0; + private double maxResponseTimeMillis = Double.MIN_VALUE; + private double minResponseTimeMillis = Double.MAX_VALUE; private ExtAuthMetrics() { MBeanRegistrator.registerMBean(this); } - /** - * Getter for the Singleton ExtAuthMetrics instance. - * - * @return ExtAuthMetrics - */ - public static ExtAuthMetrics getInstance() { - if (extAuthMetricsMBean == null) { - synchronized (ExtAuthMetrics.class) { - if (extAuthMetricsMBean == null) { - Timer timer = new Timer(); - extAuthMetricsMBean = new ExtAuthMetrics(); - timer.schedule(extAuthMetricsMBean, 0, REQUEST_COUNT_INTERVAL_MILLIS); - } +/** + * Getter for the Singleton ExtAuthMetrics instance. + * + * @return ExtAuthMetrics + */ +public static ExtAuthMetrics getInstance() { + if (extAuthMetricsMBean == null) { + synchronized (ExtAuthMetrics.class) { + if (extAuthMetricsMBean == null) { + Timer timer = new Timer(); + extAuthMetricsMBean = new ExtAuthMetrics(); + extAuthMetricsMBean.requestCountWindowStartTimeMillis = System.currentTimeMillis(); + timer.schedule(extAuthMetricsMBean, REQUEST_COUNT_INTERVAL_MILLIS, REQUEST_COUNT_INTERVAL_MILLIS); } } - return extAuthMetricsMBean; } + return extAuthMetricsMBean; +} @Override public long getTotalRequestCount() { @@ -64,24 +66,25 @@ public long getTotalRequestCount() { }; @Override - public long getAverageResponseTimeMillis() { + public double getAverageResponseTimeMillis() { return averageResponseTimeMillis; }; @Override - public long getMaxResponseTimeMillis() { + public double getMaxResponseTimeMillis() { return maxResponseTimeMillis; }; @Override - public long getMinResponseTimeMillis() { + public double getMinResponseTimeMillis() { return minResponseTimeMillis; }; public synchronized void recordMetric(long responseTimeMillis) { - this.requestCountInLastFiveMinutes += 1; + this.requestCountInLastFiveMinuteWindow += 1; this.totalRequestCount += 1; - this.averageResponseTimeMillis = (this.averageResponseTimeMillis + responseTimeMillis) / totalRequestCount; + this.averageResponseTimeMillis = this.averageResponseTimeMillis + + (responseTimeMillis - this.averageResponseTimeMillis) / totalRequestCount; this.minResponseTimeMillis = Math.min(this.minResponseTimeMillis, responseTimeMillis); this.maxResponseTimeMillis = Math.max(this.maxResponseTimeMillis, responseTimeMillis); } @@ -90,17 +93,23 @@ public synchronized void recordMetric(long responseTimeMillis) { public synchronized void resetExtAuthMetrics() { this.totalRequestCount = 0; this.averageResponseTimeMillis = 0; - this.maxResponseTimeMillis = Long.MIN_VALUE; - this.minResponseTimeMillis = Long.MAX_VALUE; + this.maxResponseTimeMillis = Double.MIN_VALUE; + this.minResponseTimeMillis = Double.MAX_VALUE; } @Override public synchronized void run() { - requestCountInLastFiveMinutes = 0; + requestCountWindowStartTimeMillis = System.currentTimeMillis(); + requestCountInLastFiveMinuteWindow = 0; } @Override - public long getRequestCountInLastFiveMinutes() { - return requestCountInLastFiveMinutes; + public long getRequestCountInLastFiveMinuteWindow() { + return requestCountInLastFiveMinuteWindow; } -} + + @Override + public long getRequestCountWindowStartTimeMillis() { + return requestCountWindowStartTimeMillis; + } +} \ No newline at end of file diff --git a/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml b/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml new file mode 100644 index 000000000..ef6c6c86e --- /dev/null +++ b/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml @@ -0,0 +1,44 @@ +# -------------------------------------------------------------------- +# Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ----------------------------------------------------------------------- + +# Config options: https://github.com/prometheus/jmx_exporter/blob/main/README.md +lowercaseOutputName: true +lowercaseOutputLabelNames: true +rules: + # WSO2 APK related metrics + - pattern: 'org.wso2.apk.enforcer<>total_request_count: (.*)' + name: org_wso2_apk_enforcer_request_count_total + help: "WSO2 APK enforcer total request count." + attrNameSnakeCase: true + type: COUNTER + - pattern: 'org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' + name: org_wso2_apk_enforcer_$1 + help: "WSO2 APK enforcer $1." + attrNameSnakeCase: true + type: GAUGE + - pattern: 'org.wso2.apk.enforcer<>(\w+): (.*)' + name: org_wso2_apk_enforcer_thread_pool_$1 + help: "WSO2 APK enforcer thread pool $1." + attrNameSnakeCase: true + type: GAUGE + # OS related metrics + - pattern: 'java.lang<>(\w+): (.*)' + name: os_$1 + help: Operating System $1 + attrNameSnakeCase: true + type: GAUGE \ No newline at end of file diff --git a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-deployment.yaml index 1f28bf973..7bf0a25fc 100644 --- a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-deployment.yaml @@ -46,6 +46,10 @@ spec: protocol: "TCP" - containerPort: 18001 protocol: TCP + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + - containerPort: 18006 + protocol: "TCP" + {{ end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.adapter.deployment.resources | indent 10 }} {{ include "apk-helm.deployment.env" .Values.wso2.apk.dp.adapter.deployment.env | indent 10 }} - name: OPERATOR_POD_NAMESPACE diff --git a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml index 8c78ff45c..c0c8e0c7c 100644 --- a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml @@ -41,4 +41,9 @@ spec: - name: profile-port protocol: TCP port: 6060 + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + - name: prometheus-adapter-port + port: 18006 + protocol: "TCP" + {{ end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml index e88b6d861..a8355ce99 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml @@ -28,4 +28,9 @@ spec: - name: servlet-https protocol: TCP port: 9092 + {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - name: prometheus-enforcer-port + protocol: TCP + port: 18007 + {{- end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml index a9918a9a5..2a0a055d5 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml @@ -52,6 +52,10 @@ spec: protocol: "TCP" - containerPort: 18002 protocol: "TCP" + {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + - containerPort: 18007 + protocol: "TCP" + {{- end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.resources | indent 10 }} {{ include "apk-helm.deployment.env" .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.env | indent 10 }} - name: ADAPTER_HOST_NAME @@ -87,7 +91,11 @@ spec: - name: enforcer_admin_pwd value: admin - name: JAVA_OPTS - value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 + {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config.yml + {{- else }} + value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 + {{- end }} {{- if .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.redis }} - name: REDIS_USERNAME value: {{ .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.redis.username | default "default" }} @@ -153,6 +161,11 @@ spec: {{- else }} subPath: tls.key {{- end }} + {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - name: prometheus-jmx-config-volume + mountPath: /tmp/metrics/prometheus-jmx-config.yml + subPath: prometheus-jmx-config.yml + {{- end }} - name: enforcer-keystore-secret-volume mountPath: /home/wso2/security/keystore/enforcer.crt {{- if and .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs.tls }} @@ -382,9 +395,14 @@ spec: # secretName: {{ template "apk-helm.resource.prefix" . }}-common-controller-server-cert # {{- end }} # defaultMode: 420 + {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - name: prometheus-jmx-config-volume + configMap: + name: prometheus-jmx-config + {{- end }} - name: enforcer-keystore-secret-volume secret: - {{- if and .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs.tls }} + {{- if and .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs.tls }} secretName: {{ .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.configs.tls.certificatesSecret | default (printf "%s-enforcer-server-cert" (include "apk-helm.resource.prefix" .)) }} {{- else }} secretName: {{ template "apk-helm.resource.prefix" . }}-enforcer-server-cert diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml new file mode 100644 index 000000000..71065b996 --- /dev/null +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-jmx-config +data: + prometheus-jmx-config.yml: | + lowercaseOutputName: true + lowercaseOutputLabelNames: true + rules: + # WSO2 APK related metrics + - pattern: 'org.wso2.apk.enforcer<>total_request_count: (.*)' + name: org_wso2_apk_enforcer_request_count_total + help: "WSO2 APK enforcer total request count." + attrNameSnakeCase: true + type: COUNTER + - pattern: 'org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' + name: org_wso2_apk_enforcer_$1 + help: "WSO2 APK enforcer $1." + attrNameSnakeCase: true + type: GAUGE + - pattern: 'org.wso2.apk.enforcer<>(\w+): (.*)' + name: org_wso2_apk_enforcer_thread_pool_$1 + help: "WSO2 APK enforcer thread pool $1." + attrNameSnakeCase: true + type: GAUGE + # OS related metrics + - pattern: 'java.lang<>(\w+): (.*)' + name: os_$1 + help: Operating System $1 + attrNameSnakeCase: true + type: GAUGE \ No newline at end of file diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml new file mode 100644 index 000000000..8450a504d --- /dev/null +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +{{- if and .Values.wso2.apk.dp.enabled .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "apk-helm.resource.prefix" . }}-router-service + namespace : {{ .Release.Namespace }} +spec: + # label keys and values that must match in order to receive traffic for this service + selector: +{{ include "apk-helm.pod.selectorLabels" (dict "root" . "app" "gateway" ) | indent 4}} + ports: + - name: prometheus-router-port + protocol: TCP + port: 9000 +{{- end -}} diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index dadb28be3..00976c673 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -249,6 +249,9 @@ wso2: # JWKSClient: # skipSSLVerification: false # hostnameVerifier: "AllowAll" + + metrics: + enabled: true idp: enabled: true listener: diff --git a/libs.versions.toml b/libs.versions.toml index 98a8315ee..100dd115a 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -80,6 +80,7 @@ opentelemetry-extension-trace-propagators = {module = "io.opentelemetry:opentele opentelemetry-sdk = {module = "io.opentelemetry:opentelemetry-sdk", version.ref = "opentelemetry"} opentelemetry-semconv = {module = "io.opentelemetry:opentelemetry-semconv", version.ref = "opentelemetry-semconv"} postgresql = {module = "org.postgresql:postgresql", version.ref = "postgresql"} +prometheus = {module = "io.prometheus.jmx:jmx_prometheus_javaagent", version.ref = "prometheus"} snakeyaml = {module = "org.yaml:snakeyaml", version.ref = "snakeyaml"} sun-saaj-impl = {module = "com.sun.xml.messaging.saaj:saaj-impl", version.ref = "sun"} swagger-annotations = {module = "io.swagger:swagger-annotations", version.ref = "io-swagger"} @@ -165,6 +166,7 @@ opentelemetry-jaeger-thrift = "1.24.0" opentelemetry-semconv = "1.24.0-alpha" org-json = "20231013" postgresql = "42.5.0" +prometheus = "0.20.0" snakeyaml = "2.0" sun = "1.5.3" swagger-codegen = "2.4.11" From 6781d04e577b62190503f599a29ed11c70cc773e Mon Sep 17 00:00:00 2001 From: sgayangi Date: Sun, 25 Feb 2024 09:20:51 +0530 Subject: [PATCH 13/24] Add Prometheus support to common controller --- adapter/go.mod | 6 +- adapter/go.sum | 10 +- .../commoncontroller/common_controller.go | 8 + common-controller/go.mod | 12 +- common-controller/go.sum | 28 ++- .../internal/config/default_config.go | 9 +- common-controller/internal/config/types.go | 8 + common-controller/pkg/metrics/metrics.go | 215 ++++++++++++++++++ common-controller/pkg/metrics/types.go | 24 ++ .../discovery/JWTIssuerDiscoveryClient.java | 6 + .../apk/enforcer/grpc/ExtAuthService.java | 6 +- .../metrics/jmx/api/ExtAuthMetricsMXBean.java | 17 +- .../metrics/jmx/impl/ExtAuthMetrics.java | 21 +- .../SubscriptionDataStoreUtil.java | 5 + .../metrics/prometheus-jmx-config.yml | 6 +- .../config-deployer/config-ds-configmap.yaml | 12 + .../common-controller-deployment.yaml | 4 + .../common-controller-service.yaml | 5 + .../gateway-runtime-deployment.yaml | 2 +- .../prometheus-jmx-configmap.yaml | 2 +- .../artifact-deployer-api_service.bal | 10 +- 21 files changed, 391 insertions(+), 25 deletions(-) create mode 100644 common-controller/pkg/metrics/metrics.go create mode 100644 common-controller/pkg/metrics/types.go diff --git a/adapter/go.mod b/adapter/go.mod index d90a94e1d..03faae8b7 100644 --- a/adapter/go.mod +++ b/adapter/go.mod @@ -37,6 +37,7 @@ require ( github.com/evanphx/json-patch/v5 v5.7.0 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/zapr v1.2.4 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-openapi/jsonpointer v0.20.0 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.4 // indirect @@ -58,14 +59,15 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.17.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect - github.com/prometheus/procfs v0.12.0 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/vektah/gqlparser v1.3.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect golang.org/x/net v0.21.0 // indirect diff --git a/adapter/go.sum b/adapter/go.sum index c943d5bd9..0af7a43be 100644 --- a/adapter/go.sum +++ b/adapter/go.sum @@ -41,6 +41,8 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= @@ -113,13 +115,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= -github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= @@ -160,6 +159,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= @@ -211,6 +212,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/common-controller/commoncontroller/common_controller.go b/common-controller/commoncontroller/common_controller.go index ea071545c..676c87bff 100644 --- a/common-controller/commoncontroller/common_controller.go +++ b/common-controller/commoncontroller/common_controller.go @@ -25,6 +25,7 @@ import ( "net" "os" "os/signal" + "strings" "time" corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" @@ -40,6 +41,7 @@ import ( "github.com/wso2/apk/common-controller/internal/server" utils "github.com/wso2/apk/common-controller/internal/utils" xds "github.com/wso2/apk/common-controller/internal/xds" + "github.com/wso2/apk/common-controller/pkg/metrics" apkmgt "github.com/wso2/apk/common-go-libs/pkg/discovery/api/wso2/discovery/service/apkmgt" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -206,6 +208,12 @@ func InitCommonControllerServer(conf *config.Config) { loggers.LoggerAPKOperator.Info("Starting common controller ....") + // Start the metrics server + if conf.CommonController.Metrics.Enabled && strings.EqualFold(conf.CommonController.Metrics.Type, metrics.PrometheusMetricType) { + loggers.LoggerAPKOperator.Info("Starting Prometheus Metrics Server ....") + go metrics.StartPrometheusMetricsServer(conf.CommonController.Metrics.Port, conf.CommonController.Metrics.CollectionInterval) + } + rateLimiterCache := xds.GetRateLimiterCache() rlsSrv := xdsv3.NewServer(ctx, rateLimiterCache, &xds.Callbacks{}) diff --git a/common-controller/go.mod b/common-controller/go.mod index 80b975191..9013a7ac6 100644 --- a/common-controller/go.mod +++ b/common-controller/go.mod @@ -5,6 +5,8 @@ go 1.20 require ( github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 + github.com/prometheus/client_golang v1.18.0 + github.com/prometheus/procfs v0.12.0 github.com/sirupsen/logrus v1.9.0 k8s.io/apimachinery v0.28.3 k8s.io/client-go v0.28.3 @@ -18,6 +20,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/pelletier/go-toml v1.9.5 github.com/redis/go-redis/v9 v9.2.1 + github.com/shirou/gopsutil/v3 v3.24.1 github.com/wso2/apk/adapter v0.0.0-20231207051518-6dd728943082 github.com/wso2/apk/common-go-libs v0.0.0-20231208100153-24bee7b4bd81 google.golang.org/grpc v1.62.0 @@ -34,6 +37,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect @@ -41,13 +45,19 @@ require ( github.com/google/gnostic-models v0.6.8 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/vektah/gqlparser v1.3.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect @@ -84,10 +94,8 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.17.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect - github.com/prometheus/procfs v0.12.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.8.4 go.uber.org/multierr v1.11.0 // indirect diff --git a/common-controller/go.sum b/common-controller/go.sum index da9f79556..b678ced88 100644 --- a/common-controller/go.sum +++ b/common-controller/go.sum @@ -66,6 +66,8 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= @@ -103,6 +105,7 @@ github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvR github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -138,6 +141,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= @@ -165,8 +170,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= -github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= @@ -179,6 +186,12 @@ github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0 github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= +github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= @@ -200,6 +213,10 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= @@ -210,6 +227,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= @@ -270,9 +289,11 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -281,6 +302,9 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/common-controller/internal/config/default_config.go b/common-controller/internal/config/default_config.go index 081122c36..2391f9524 100644 --- a/common-controller/internal/config/default_config.go +++ b/common-controller/internal/config/default_config.go @@ -41,6 +41,13 @@ var defaultConfig = &Config{ EventPort: 18000, RestPort: 18001, RetryInterval: 5, - Persistence: persistence{Type: "K8s"}}, + Persistence: persistence{Type: "K8s"}, + }, + Metrics: metrics{ + Enabled: true, + Type: "prometheus", + Port: 18009, + CollectionInterval: 5, + }, }, } diff --git a/common-controller/internal/config/types.go b/common-controller/internal/config/types.go index 372dc195e..35b57dd32 100644 --- a/common-controller/internal/config/types.go +++ b/common-controller/internal/config/types.go @@ -48,6 +48,7 @@ type commoncontroller struct { WebServer webServer InternalAPIServer internalAPIServer ControlPlane controlplane + Metrics metrics } type controlplane struct { Enabled bool @@ -102,3 +103,10 @@ type sts struct { type webServer struct { Port int64 } + +type metrics struct { + Enabled bool + Type string + Port int32 + CollectionInterval int32 +} diff --git a/common-controller/pkg/metrics/metrics.go b/common-controller/pkg/metrics/metrics.go new file mode 100644 index 000000000..ef7824ebb --- /dev/null +++ b/common-controller/pkg/metrics/metrics.go @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Package metrics holds the implementation for exposing common controller metrics to prometheus +package metrics + +import ( + "fmt" + "net/http" + "os" + "runtime" + "strconv" + "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/prometheus/procfs" + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/host" + "github.com/shirou/gopsutil/v3/load" + "github.com/shirou/gopsutil/v3/mem" + "github.com/wso2/apk/adapter/pkg/logging" + logger "github.com/wso2/apk/common-controller/internal/loggers" +) + +var ( + prometheusMetricRegistry = prometheus.NewRegistry() + + hostInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "host_info", + Help: "Host Info", + }, []string{"os"}) + + availableCPUs = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_available_cpu_total", + Help: "Number of available CPUs.", + }) + + freePhysicalMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_free_physical_memory_bytes", + Help: "Amount of free physical memory.", + }) + + totalVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_total_virtual_memory_bytes", + Help: "Amount of total virtual memory.", + }) + usedVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_used_virtual_memory_bytes", + Help: "Amount of used virtual memory.", + }) + + systemCPULoad = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "os_system_cpu_load_percentage", + Help: "System-wide CPU usage as a percentage.", + }) + + loadAvg = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "os_system_load_average", + Help: "Current load of CPU in the host system for the last {x} minutes", + }, []string{"duration"}) + + processStartTime = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "process_start_time_seconds", + Help: "Start time of the process since unix epoch in seconds.", + }) + + processOpenFDs = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "process_open_fds", + Help: "Number of open file descriptors.", + }) +) + +func init() { + // Register the Go collector with the registry + goCollector := collectors.NewGoCollector() + prometheusMetricRegistry.MustRegister(goCollector) + + // Register other metrics + prometheusMetricRegistry.MustRegister(hostInfo, availableCPUs, freePhysicalMemory, usedVirtualMemory, totalVirtualMemory, + systemCPULoad, loadAvg, processStartTime, processOpenFDs) +} + +// recordMetrics record custom golang metrics +var recordMetrics = func(collectionInterval int32) { + for { + host, err := host.Info() + if handleError(err, "Failed to get host info") { + return + } + hostInfo.WithLabelValues(host.OS).Set(1) + availableCPUs.Set(float64(runtime.NumCPU())) + + v, err := mem.VirtualMemory() + if handleError(err, "Failed to read virtual memory metrics") { + return + } + freePhysicalMemory.Set(float64(v.Free)) + usedVirtualMemory.Set(float64(v.Used)) + totalVirtualMemory.Set(float64(v.Total)) + + percentages, err := cpu.Percent(0, false) + if handleError(err, "Failed to read cpu usage metrics") || len(percentages) == 0 { + return + } + totalPercentage := 0.0 + for _, p := range percentages { + totalPercentage += p + } + averagePercentage := totalPercentage / float64(len(percentages)) + systemCPULoad.Set(averagePercentage) + + pid := os.Getpid() + p, err := procfs.NewProc(pid) + if handleError(err, "Failed to get current process") { + return + } + stat, err := p.Stat() + if handleError(err, "Failed to get process stats") { + return + } + t, err := stat.StartTime() + if handleError(err, "Failed to read process start time") { + return + } + processStartTime.Set(t) + fds, err := p.FileDescriptorsLen() + if handleError(err, "Failed to read file descriptor count") { + return + } + processOpenFDs.Set(float64(fds)) + + avg, err := load.Avg() + if handleError(err, "Failed to read cpu load averages") { + return + } + loadAvg.WithLabelValues("1m").Set(avg.Load1) + loadAvg.WithLabelValues("5m").Set(avg.Load5) + loadAvg.WithLabelValues("15m").Set(avg.Load15) + + // Sleep before the next measurement + time.Sleep(time.Duration(collectionInterval) * time.Second) + } + +} + +func handleError(err error, message string) bool { + if err != nil { + logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintf(message, err.Error()), + Severity: logging.MINOR, + ErrorCode: 1109, + }) + return true + } + return false +} + +// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. +func StartPrometheusMetricsServer(port int32, collectionInterval int32) { + done := make(chan struct{}) // Channel to indicate recordMetrics routine exit + + // Start the Prometheus metrics server + go func() { + http.Handle("/metrics", promhttp.HandlerFor(prometheusMetricRegistry, promhttp.HandlerOpts{})) + err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) + if err != nil { + logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintln("Prometheus metrics server error:", err), + Severity: logging.MAJOR, + ErrorCode: 1110, + }) + } + }() + + for { + // Start the recordMetrics goroutine + go func() { + defer func() { + if r := recover(); r != nil { + logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintln("recordMetrics goroutine exited with error:", r), + Severity: logging.MAJOR, + ErrorCode: 1111, + }) + } + }() + recordMetrics(collectionInterval) + done <- struct{}{} // Signal that the goroutine has completed + }() + + // Wait for the previous recordMetrics goroutine to complete + <-done + + // Log and restart the goroutine + logger.LoggerAPKOperator.Info("Restarting recordMetrics goroutine...") + time.Sleep(3 * time.Second) + } +} diff --git a/common-controller/pkg/metrics/types.go b/common-controller/pkg/metrics/types.go new file mode 100644 index 000000000..07761ebaf --- /dev/null +++ b/common-controller/pkg/metrics/types.go @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package metrics + +const ( + // PrometheusMetricType prometheus metric type + PrometheusMetricType = "prometheus" +) diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java index 9d751a267..42ae752ed 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java @@ -36,6 +36,8 @@ import org.wso2.apk.enforcer.discovery.service.subscription.JWTIssuerDiscoveryServiceGrpc; import org.wso2.apk.enforcer.discovery.subscription.JWTIssuer; import org.wso2.apk.enforcer.discovery.subscription.JWTIssuerList; +import org.wso2.apk.enforcer.jmx.JMXUtils; +import org.wso2.apk.enforcer.metrics.jmx.impl.ExtAuthMetrics; import org.wso2.apk.enforcer.subscription.SubscriptionDataHolder; import org.wso2.apk.enforcer.subscription.SubscriptionDataStore; import org.wso2.apk.enforcer.util.GRPCUtils; @@ -160,6 +162,10 @@ public void onNext(DiscoveryResponse response) { } subscriptionDataStore.addJWTIssuers(v); }); + + if (JMXUtils.isJMXMetricsEnabled()) { + ExtAuthMetrics.getInstance().recordJWTIssuerMetrics(jwtIssuers.size()); + } logger.info("Number of jwt issuers received : " + jwtIssuers.size()); ack(); } catch (Exception e) { diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java index f815f0203..78cadd01e 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java @@ -66,7 +66,7 @@ public class ExtAuthService extends AuthorizationGrpc.AuthorizationImplBase { public void check(CheckRequest request, StreamObserver responseObserver) { TracingSpan extAuthServiceSpan = null; Scope extAuthServiceSpanScope = null; - long starTimestamp = System.currentTimeMillis(); + long startTimestamp = System.currentTimeMillis(); try { String traceId = request.getAttributes().getRequest().getHttp() .getHeadersOrDefault(HttpConstants.X_REQUEST_ID_HEADER, @@ -94,10 +94,10 @@ public void check(CheckRequest request, StreamObserver responseOb } if (MetricsManager.isMetricsEnabled()) { MetricsExporter metricsExporter = MetricsManager.getInstance(); - metricsExporter.trackMetric("enforcerLatency", System.currentTimeMillis() - starTimestamp); + metricsExporter.trackMetric("enforcerLatency", System.currentTimeMillis() - startTimestamp); } if (JMXUtils.isJMXMetricsEnabled()) { - ExtAuthMetrics.getInstance().recordMetric(System.currentTimeMillis() - starTimestamp); + ExtAuthMetrics.getInstance().recordMetric(System.currentTimeMillis() - startTimestamp); } } } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java index 105eccf13..4755ebb45 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/api/ExtAuthMetricsMXBean.java @@ -42,7 +42,6 @@ public interface ExtAuthMetricsMXBean { */ public double getMaxResponseTimeMillis(); - /** * Getter for mimnimum response time in milliseconds. * @@ -51,7 +50,7 @@ public interface ExtAuthMetricsMXBean { public double getMinResponseTimeMillis(); /** - * Resets all the metrics to thier initial values. + * Resets all the metrics to their initial values. */ public void resetExtAuthMetrics(); @@ -69,4 +68,18 @@ public interface ExtAuthMetricsMXBean { */ public long getRequestCountWindowStartTimeMillis(); + /** + * Get the number of token issuers + * + * @return + */ + public int getTokenIssuerCount(); + + /** + * Get the number of subscriptions + * + * @return + */ + public int getSubscriptionCount(); + } \ No newline at end of file diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java index e01ac205c..29b68d653 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java @@ -29,10 +29,11 @@ public class ExtAuthMetrics extends TimerTask implements ExtAuthMetricsMXBean { private static final long REQUEST_COUNT_INTERVAL_MILLIS = 5 * 60 * 1000; private static ExtAuthMetrics extAuthMetricsMBean = null; - private long requestCountInLastFiveMinuteWindow = 0; + private int jwtIssuerCount = 0; private long requestCountWindowStartTimeMillis = System.currentTimeMillis(); private long totalRequestCount = 0; + private int subscriptionCount = 0; private double averageResponseTimeMillis = 0; private double maxResponseTimeMillis = Double.MIN_VALUE; private double minResponseTimeMillis = Double.MAX_VALUE; @@ -89,6 +90,14 @@ public synchronized void recordMetric(long responseTimeMillis) { this.maxResponseTimeMillis = Math.max(this.maxResponseTimeMillis, responseTimeMillis); } + public synchronized void recordJWTIssuerMetrics(int jwtIssuers) { + this.jwtIssuerCount = jwtIssuers; + } + + public synchronized void recordSubscriptionMetrics(int subscriptionCount) { + this.subscriptionCount = subscriptionCount; + } + @Override public synchronized void resetExtAuthMetrics() { this.totalRequestCount = 0; @@ -112,4 +121,14 @@ public long getRequestCountInLastFiveMinuteWindow() { public long getRequestCountWindowStartTimeMillis() { return requestCountWindowStartTimeMillis; } + + @Override + public int getTokenIssuerCount() { + return jwtIssuerCount; + } + + @Override + public int getSubscriptionCount() { + return subscriptionCount; + } } \ No newline at end of file diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java index 22a576d07..6c4905201 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java @@ -29,6 +29,8 @@ import org.wso2.apk.enforcer.discovery.subscription.ApplicationKeyMapping; import org.wso2.apk.enforcer.discovery.subscription.ApplicationMapping; import org.wso2.apk.enforcer.discovery.subscription.Subscription; +import org.wso2.apk.enforcer.jmx.JMXUtils; +import org.wso2.apk.enforcer.metrics.jmx.impl.ExtAuthMetrics; import org.wso2.apk.enforcer.util.ApacheFeignHttpClient; import org.wso2.apk.enforcer.util.FilterUtils; @@ -157,6 +159,9 @@ private static void loadSubscriptions() { new Thread(() -> { SubscriptionListDto subscriptions = subscriptionValidationDataRetrievalRestClient.getAllSubscriptions(); List list = subscriptions.getList(); + if (JMXUtils.isJMXMetricsEnabled()) { + ExtAuthMetrics.getInstance().recordSubscriptionMetrics(list.size()); + } Map> orgWizeMAp = new HashMap<>(); for (SubscriptionDto subscriptionDto : list) { String organization = subscriptionDto.getOrganization(); diff --git a/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml b/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml index ef6c6c86e..5771c0027 100644 --- a/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml +++ b/gateway/enforcer/resources/metrics/prometheus-jmx-config.yml @@ -21,12 +21,12 @@ lowercaseOutputName: true lowercaseOutputLabelNames: true rules: # WSO2 APK related metrics - - pattern: 'org.wso2.apk.enforcer<>total_request_count: (.*)' + - pattern: "org.wso2.apk.enforcer<>total_request_count: (.*)" name: org_wso2_apk_enforcer_request_count_total help: "WSO2 APK enforcer total request count." attrNameSnakeCase: true type: COUNTER - - pattern: 'org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' + - pattern: "org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis|token_issuer_count|subscription_count): (.*)" name: org_wso2_apk_enforcer_$1 help: "WSO2 APK enforcer $1." attrNameSnakeCase: true @@ -41,4 +41,4 @@ rules: name: os_$1 help: Operating System $1 attrNameSnakeCase: true - type: GAUGE \ No newline at end of file + type: GAUGE diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml index 83be6b02a..adaa4055e 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml @@ -26,6 +26,18 @@ data: level = "INFO" [ballerina.http] traceLogConsole = true + {{if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + [ballerina.observe] + metricsEnabled=true + metricsReporter="prometheus" + [ballerinax.prometheus] + port=18008 + {{if .Values.wso2.apk.metrics.configdeployerhost}} + host={{.Values.wso2.apk.metrics.configdeployerhost}} + {{else}} + host="127.0.0.1" + {{end}} + {{end}} [wso2.config_deployer_service.keyStores.tls] keyFilePath = "/home/wso2apk/config-deployer/security/config.key" certFilePath = "/home/wso2apk/config-deployer/security/config.pem" diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml index 5a2647ca0..ef35c6424 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml @@ -48,6 +48,10 @@ spec: protocol: TCP - containerPort: 18003 protocol: TCP + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - containerPort: 18009 + protocol: "TCP" + {{ end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.commonController.deployment.resources | indent 10 }} {{ include "apk-helm.deployment.env" .Values.wso2.apk.dp.commonController.deployment.env | indent 10 }} - name: OPERATOR_POD_NAMESPACE diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml index e5adf645f..debcb579f 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml @@ -38,4 +38,9 @@ spec: - name: https-internal-api protocol: TCP port: 18003 + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - name: prometheus-common-controller-port + protocol: TCP + port: 18009 + {{ end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml index 2a0a055d5..c9aeb8d4d 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml @@ -94,7 +94,7 @@ spec: {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config.yml {{- else }} - value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 + value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 {{- end }} {{- if .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.redis }} - name: REDIS_USERNAME diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml index 71065b996..ce94cf2a4 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml @@ -13,7 +13,7 @@ data: help: "WSO2 APK enforcer total request count." attrNameSnakeCase: true type: COUNTER - - pattern: 'org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' + - pattern: 'org.wso2.apk.enforcer<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis|token_issuer_count|subscription_count): (.*)' name: org_wso2_apk_enforcer_$1 help: "WSO2 APK enforcer $1." attrNameSnakeCase: true diff --git a/runtime/config-deployer-service/ballerina/artifact-deployer-api_service.bal b/runtime/config-deployer-service/ballerina/artifact-deployer-api_service.bal index 437a369e8..11907a88d 100644 --- a/runtime/config-deployer-service/ballerina/artifact-deployer-api_service.bal +++ b/runtime/config-deployer-service/ballerina/artifact-deployer-api_service.bal @@ -1,4 +1,6 @@ import ballerina/http; +import ballerinax/prometheus as _; + import wso2/apk_common_lib as commons; isolated service http:InterceptableService /api/deployer on ep0 { @@ -9,11 +11,11 @@ isolated service http:InterceptableService /api/deployer on ep0 { # anydata (API deployed successfully) # BadRequestError (Bad Request. Invalid request or validation error.) # InternalServerErrorError (Internal Server Error.) - isolated resource function post apis/deploy(http:RequestContext requestContext,http:Request request) returns commons:APKError|http:Response { + isolated resource function post apis/deploy(http:RequestContext requestContext, http:Request request) returns commons:APKError|http:Response { DeployerClient deployerClient = new; commons:UserContext authenticatedUserContext = check commons:getAuthenticatedUserContext(requestContext); commons:Organization organization = authenticatedUserContext.organization; - return check deployerClient.handleAPIDeployment(request,organization); + return check deployerClient.handleAPIDeployment(request, organization); } # Undeploy API # @@ -22,11 +24,11 @@ isolated service http:InterceptableService /api/deployer on ep0 { # AcceptedString (API undeployed successfully) # BadRequestError (Bad Request. Invalid request or validation error.) # InternalServerErrorError (Internal Server Error.) - isolated resource function post apis/undeploy(http:RequestContext requestContext,string apiId) returns AcceptedString|BadRequestError|InternalServerErrorError|commons:APKError { + isolated resource function post apis/undeploy(http:RequestContext requestContext, string apiId) returns AcceptedString|BadRequestError|InternalServerErrorError|commons:APKError { DeployerClient deployerClient = new; commons:UserContext authenticatedUserContext = check commons:getAuthenticatedUserContext(requestContext); commons:Organization organization = authenticatedUserContext.organization; - return check deployerClient.handleAPIUndeployment(apiId,organization); + return check deployerClient.handleAPIUndeployment(apiId, organization); } public function createInterceptors() returns http:Interceptor|http:Interceptor[] { From dde944ae9c56704d8c7321c02ae57a973364f131 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Sun, 25 Feb 2024 15:47:23 +0530 Subject: [PATCH 14/24] Update exposed adapter and enforcer metrics --- adapter/internal/discovery/xds/server.go | 34 +++++++++++++++++ .../operator/synchronizer/data_store.go | 5 +++ adapter/pkg/metrics/metrics.go | 37 ++++++++++++++++++- .../enforcer/constants/MetadataConstants.java | 2 +- .../apk/enforcer/grpc/ExtAuthService.java | 4 +- 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/adapter/internal/discovery/xds/server.go b/adapter/internal/discovery/xds/server.go index f85195bbf..da5dd9295 100644 --- a/adapter/internal/discovery/xds/server.go +++ b/adapter/internal/discovery/xds/server.go @@ -779,3 +779,37 @@ func SanitizeGateway(gatewayName string, create bool) error { } return nil } + +// GetEnvoyGatewayConfigClusters method gets the number of clusters in envoy gateway config +func GetEnvoyGatewayConfigClusters() int { + totalClusters := 0 + for _, config := range gatewayLabelConfigMap { + // Add the number of clusters in this EnvoyGatewayConfig instance to the total + totalClusters += len(config.clusters) + } + return totalClusters +} + +// GetEnvoyInternalAPIRoutes method gets the number of routes in envoy internal API +func GetEnvoyInternalAPIRoutes() int { + totalRoutes := 0 + for _, orgMap := range orgAPIMap { + for _, api := range orgMap { + // Add the number of routes in this EnvoyInternalAPI instance to the total + totalRoutes += len(api.routes) + } + } + return totalRoutes +} + +// GetEnvoyInternalAPIClusters method gets the number of clusters in envoy internal API +func GetEnvoyInternalAPIClusters() int { + totalClusters := 0 + for _, orgMap := range orgAPIMap { + for _, api := range orgMap { + // Add the number of clusters in this EnvoyInternalAPI instance to the total + totalClusters += len(api.clusters) + } + } + return totalClusters +} diff --git a/adapter/internal/operator/synchronizer/data_store.go b/adapter/internal/operator/synchronizer/data_store.go index 80265707d..1ec062f86 100644 --- a/adapter/internal/operator/synchronizer/data_store.go +++ b/adapter/internal/operator/synchronizer/data_store.go @@ -571,3 +571,8 @@ func (ods *OperatorDataStore) DeleteCachedGateway(gatewayName types.NamespacedNa defer ods.mu.Unlock() delete(ods.gatewayStore, gatewayName) } + +// GetAPICount gets API count +func (ods *OperatorDataStore) GetAPICount() int { + return len(ods.apiStore) +} diff --git a/adapter/pkg/metrics/metrics.go b/adapter/pkg/metrics/metrics.go index 62a82e254..d62e21ef0 100644 --- a/adapter/pkg/metrics/metrics.go +++ b/adapter/pkg/metrics/metrics.go @@ -35,7 +35,9 @@ import ( "github.com/shirou/gopsutil/v3/host" "github.com/shirou/gopsutil/v3/load" "github.com/shirou/gopsutil/v3/mem" + xds "github.com/wso2/apk/adapter/internal/discovery/xds" logger "github.com/wso2/apk/adapter/internal/loggers" + synchronizer "github.com/wso2/apk/adapter/internal/operator/synchronizer" "github.com/wso2/apk/adapter/pkg/logging" ) @@ -85,6 +87,26 @@ var ( Name: "process_open_fds", Help: "Number of open file descriptors.", }) + + apis = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "api_count", + Help: "Number of APIs created.", + }) + + internalClusterCount = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "internal_cluster_count", + Help: "Number of internal clusters created.", + }) + + gwClusterCount = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "gw_cluster_count", + Help: "Number of gw clusters created.", + }) + + internalRouteCount = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "internal_route_count", + Help: "Number of internal routes created.", + }) ) func init() { @@ -94,12 +116,23 @@ func init() { // Register other metrics prometheusMetricRegistry.MustRegister(hostInfo, availableCPUs, freePhysicalMemory, usedVirtualMemory, totalVirtualMemory, - systemCPULoad, loadAvg, processStartTime, processOpenFDs) + systemCPULoad, loadAvg, processStartTime, processOpenFDs, apis, internalClusterCount, internalRouteCount, gwClusterCount) } // recordMetrics record custom golang metrics var recordMetrics = func(collectionInterval int32) { for { + envoyInternalAPIClusterCount := xds.GetEnvoyInternalAPIClusters() + internalClusterCount.Set(float64(envoyInternalAPIClusterCount)) + + envoyInternalAPIRouteCount := xds.GetEnvoyInternalAPIRoutes() + internalRouteCount.Set(float64(envoyInternalAPIRouteCount)) + + gwClusterCount.Set(float64(xds.GetEnvoyGatewayConfigClusters())) + + apiCount := synchronizer.GetOperatorDataStore().GetAPICount() + apis.Set(float64(apiCount)) + host, err := host.Info() if handleError(err, "Failed to get host info") { return @@ -212,4 +245,4 @@ func StartPrometheusMetricsServer(port int32, collectionInterval int32) { logger.LoggerAPK.Info("Restarting recordMetrics goroutine...") time.Sleep(3 * time.Second) } -} \ No newline at end of file +} diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/MetadataConstants.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/MetadataConstants.java index 191a7bcee..5dc541a2c 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/MetadataConstants.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/constants/MetadataConstants.java @@ -53,7 +53,7 @@ public class MetadataConstants { public static final String CLIENT_IP_KEY = WSO2_METADATA_PREFIX + "client-ip"; public static final String ERROR_CODE_KEY = "ErrorCode"; - public static final String CHOREO_CONNECT_ENFORCER_REPLY = "apk-enforcer-reply"; + public static final String APK_ENFORCER_REPLY = "apk-enforcer-reply"; public static final String RATELIMIT_WSO2_ORG_PREFIX = "customorg"; public static final String GATEWAY_URL = WSO2_METADATA_PREFIX + "x-original-gw-url"; public static final String API_ENVIRONMENT = WSO2_METADATA_PREFIX + "api-environment"; diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java index 78cadd01e..f0f30364e 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/grpc/ExtAuthService.java @@ -142,7 +142,7 @@ private CheckResponse buildResponse(CheckRequest request, ResponseObject respons } addMetadata(metadataStructBuilder, "correlationID", responseObject.getCorrelationID()); - addMetadata(metadataStructBuilder, MetadataConstants.CHOREO_CONNECT_ENFORCER_REPLY, "Ok"); + addMetadata(metadataStructBuilder, MetadataConstants.APK_ENFORCER_REPLY, "Ok"); return checkResponseBuilder .setDynamicMetadata(metadataStructBuilder.build()) @@ -189,7 +189,7 @@ private CheckResponse buildResponse(CheckRequest request, ResponseObject respons responseObject.getRequestPath().split("\\?")[0]); // adding org level ratelimit key to metadata addMetadata(structBuilder, MetadataConstants.RATELIMIT_WSO2_ORG_PREFIX, responseObject.getOrganizationId()); - addMetadata(structBuilder, MetadataConstants.CHOREO_CONNECT_ENFORCER_REPLY, "Ok"); + addMetadata(structBuilder, MetadataConstants.APK_ENFORCER_REPLY, "Ok"); return CheckResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()) .setOkResponse(okResponseBuilder.build()) From 3d3627368410e19605063d5e326346af8939c937 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Tue, 27 Feb 2024 14:55:46 +0530 Subject: [PATCH 15/24] Update enforcer metric configs --- .../apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java | 6 +++--- .../gateway-runtime/gateway-runtime-deployment.yaml | 8 ++++---- .../gateway-runtime/prometheus-jmx-configmap.yaml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java index 29b68d653..be72384af 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/metrics/jmx/impl/ExtAuthMetrics.java @@ -30,7 +30,7 @@ public class ExtAuthMetrics extends TimerTask implements ExtAuthMetricsMXBean { private static final long REQUEST_COUNT_INTERVAL_MILLIS = 5 * 60 * 1000; private static ExtAuthMetrics extAuthMetricsMBean = null; private long requestCountInLastFiveMinuteWindow = 0; - private int jwtIssuerCount = 0; + private int tokenIssuerCount = 0; private long requestCountWindowStartTimeMillis = System.currentTimeMillis(); private long totalRequestCount = 0; private int subscriptionCount = 0; @@ -91,7 +91,7 @@ public synchronized void recordMetric(long responseTimeMillis) { } public synchronized void recordJWTIssuerMetrics(int jwtIssuers) { - this.jwtIssuerCount = jwtIssuers; + this.tokenIssuerCount = jwtIssuers; } public synchronized void recordSubscriptionMetrics(int subscriptionCount) { @@ -124,7 +124,7 @@ public long getRequestCountWindowStartTimeMillis() { @Override public int getTokenIssuerCount() { - return jwtIssuerCount; + return tokenIssuerCount; } @Override diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml index c9aeb8d4d..e9e696a1f 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml @@ -92,7 +92,7 @@ spec: value: admin - name: JAVA_OPTS {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config.yml + value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config-enforcer.yml {{- else }} value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 {{- end }} @@ -163,8 +163,8 @@ spec: {{- end }} {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - name: prometheus-jmx-config-volume - mountPath: /tmp/metrics/prometheus-jmx-config.yml - subPath: prometheus-jmx-config.yml + mountPath: /tmp/metrics/prometheus-jmx-config-enforcer.yml + subPath: prometheus-jmx-config-enforcer.yml {{- end }} - name: enforcer-keystore-secret-volume mountPath: /home/wso2/security/keystore/enforcer.crt @@ -398,7 +398,7 @@ spec: {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - name: prometheus-jmx-config-volume configMap: - name: prometheus-jmx-config + name: prometheus-jmx-config-enforcer {{- end }} - name: enforcer-keystore-secret-volume secret: diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml index ce94cf2a4..dc1849b2d 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: ConfigMap metadata: - name: prometheus-jmx-config + name: prometheus-jmx-config-enforcer data: - prometheus-jmx-config.yml: | + prometheus-jmx-config-enforcer.yml: | lowercaseOutputName: true lowercaseOutputLabelNames: true rules: From ebac428a3241c4d3ce169d5d369ea2bab84b2ee4 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Wed, 28 Feb 2024 09:55:11 +0530 Subject: [PATCH 16/24] Add Prometheus support to Config DS --- .../config-deployer/config-ds-configmap.yaml | 8 ++-- .../config-deployer/config-ds-deployment.yaml | 12 +++++ .../config-ds-prometheus-jmx-configmap.yaml | 47 +++++++++++++++++++ .../config-deployer/config-ds-service.yaml | 8 ++++ helm-charts/values.yaml | 1 + .../ballerina/APIClient.bal | 5 +- .../ballerina/Ballerina.toml | 8 +++- .../ballerina/Dependencies.toml | 30 ++++++++++++ .../config-deployer-service/docker/Dockerfile | 2 + .../docker/config-deployer/config.sh | 13 ++--- .../config-deployer-service/java/build.gradle | 33 ++++++++++++- 11 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml index adaa4055e..8fd18a700 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml @@ -25,17 +25,17 @@ data: [ballerina.log] level = "INFO" [ballerina.http] - traceLogConsole = true + traceLogConsole = false {{if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} [ballerina.observe] metricsEnabled=true metricsReporter="prometheus" [ballerinax.prometheus] port=18008 - {{if .Values.wso2.apk.metrics.configdeployerhost}} - host={{.Values.wso2.apk.metrics.configdeployerhost}} + {{if .Values.wso2.apk.metrics.configDSBalPort}} + host="{{ .Values.wso2.apk.metrics.configDSBalPort}}" {{else}} - host="127.0.0.1" + host="0.0.0.0" {{end}} {{end}} [wso2.config_deployer_service.keyStores.tls] diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml index 29d23a6df..acef54358 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml @@ -42,6 +42,12 @@ spec: ports: - containerPort: 9443 protocol: "TCP" + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - containerPort: 18008 + protocol: "TCP" + - containerPort: 18010 + protocol: "TCP" + {{ end }} readinessProbe: httpGet: path: /health @@ -68,6 +74,9 @@ spec: {{- else }} subPath: tls.key {{- end }} + - name: prometheus-jmx-config-volume + mountPath: /tmp/metrics/prometheus-jmx-config-configds.yml + subPath: prometheus-jmx-config-configds.yml - name: config-ds-tls-volume mountPath: /home/wso2apk/config-deployer/security/config.pem {{- if and .Values.wso2.apk.dp.configdeployer.configs .Values.wso2.apk.dp.configdeployer.configs.tls }} @@ -105,6 +114,9 @@ spec: - name: config-toml-volume configMap: name: {{ template "apk-helm.resource.prefix" . }}-config-ds-configmap + - name: prometheus-jmx-config-volume + configMap: + name: prometheus-jmx-config-configds - name: config-ds-tls-volume secret: {{ if and .Values.wso2.apk.dp.configdeployer.configs .Values.wso2.apk.dp.configdeployer.configs.tls }} diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml new file mode 100644 index 000000000..610f358ec --- /dev/null +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml @@ -0,0 +1,47 @@ +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-jmx-config-configds +data: + prometheus-jmx-config-configds.yml: | + lowercaseOutputName: true + lowercaseOutputLabelNames: true + rules: + # WSO2 APK related metrics + - pattern: 'org.wso2.apk.config<>total_request_count: (.*)' + name: org_wso2_apk_config_request_count_total + help: "WSO2 APK config total request count." + attrNameSnakeCase: true + type: COUNTER + - pattern: 'org.wso2.apk.config<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' + name: org_wso2_apk_config_$1 + help: "WSO2 APK config $1." + attrNameSnakeCase: true + type: GAUGE + - pattern: 'org.wso2.apk.config<>(\w+): (.*)' + name: org_wso2_apk_config_thread_pool_$1 + help: "WSO2 APK config thread pool $1." + attrNameSnakeCase: true + type: GAUGE + # OS related metrics + - pattern: 'java.lang<>(\w+): (.*)' + name: os_$1 + help: Operating System $1 + attrNameSnakeCase: true + type: GAUGE \ No newline at end of file diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml index b19708a7f..ffd488cb4 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml @@ -28,4 +28,12 @@ spec: - name: servlet-https protocol: TCP port: 9443 + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - name: prometheus-config-ds-port-lang + protocol: TCP + port: 18008 + - name: prometheus-config-ds-port-system + protocol: TCP + port: 18010 + {{ end }} {{- end -}} diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index 00976c673..e670c336c 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -252,6 +252,7 @@ wso2: metrics: enabled: true + # configDSBalPort: 0.0.0.0 idp: enabled: true listener: diff --git a/runtime/config-deployer-service/ballerina/APIClient.bal b/runtime/config-deployer-service/ballerina/APIClient.bal index 9a59bb912..fba8b6790 100644 --- a/runtime/config-deployer-service/ballerina/APIClient.bal +++ b/runtime/config-deployer-service/ballerina/APIClient.bal @@ -27,10 +27,9 @@ import ballerina/uuid; import ballerina/crypto; import config_deployer_service.java.io as javaio; import wso2/apk_common_lib as commons; - -# +import ballerinax/prometheus as _; public class APIClient { - + # This function used to convert APKInternalAPI model to APKConf. # # + api - APKInternalAPI model diff --git a/runtime/config-deployer-service/ballerina/Ballerina.toml b/runtime/config-deployer-service/ballerina/Ballerina.toml index 46bc216ad..82f0b4f11 100644 --- a/runtime/config-deployer-service/ballerina/Ballerina.toml +++ b/runtime/config-deployer-service/ballerina/Ballerina.toml @@ -5,7 +5,7 @@ version = "1.1.0-SNAPSHOT" distribution = "2201.8.0" [build-options] -observabilityIncluded = false +observabilityIncluded = true [[dependency]] org = "wso2" @@ -49,6 +49,12 @@ groupId = "io.swagger" artifactId = "swagger-core" version = "1.6.10" +# transitive dependency of io.prometheus.jmx:jmx_prometheus_javaagent:0.20.0 +[[platform.java11.dependency]] +groupId = "io.prometheus.jmx" +artifactId = "jmx_prometheus_javaagent" +version = "0.20.0" + # transitive dependency of io.swagger.parser.v3:swagger-parser:2.1.13 [[platform.java11.dependency]] groupId = "io.swagger" diff --git a/runtime/config-deployer-service/ballerina/Dependencies.toml b/runtime/config-deployer-service/ballerina/Dependencies.toml index 5ba9b8e5a..45dbaad3f 100644 --- a/runtime/config-deployer-service/ballerina/Dependencies.toml +++ b/runtime/config-deployer-service/ballerina/Dependencies.toml @@ -365,6 +365,18 @@ modules = [ {org = "ballerina", packageName = "uuid", moduleName = "uuid"} ] +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + [[package]] org = "ballerinax" name = "postgresql" @@ -377,6 +389,21 @@ dependencies = [ {org = "ballerina", name = "time"} ] +[[package]] +org = "ballerinax" +name = "prometheus" +version = "0.2.0" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "regex"} +] +modules = [ + {org = "ballerinax", packageName = "prometheus", moduleName = "prometheus"} +] + [[package]] org = "wso2" name = "apk_common_lib" @@ -420,6 +447,8 @@ dependencies = [ {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, {org = "ballerina", name = "uuid"}, + {org = "ballerinai", name = "observe"}, + {org = "ballerinax", name = "prometheus"}, {org = "wso2", name = "apk_common_lib"} ] modules = [ @@ -432,6 +461,7 @@ modules = [ {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.model"}, {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.org.wso2.apk.config"}, {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.org.wso2.apk.config.api"}, + {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.org.wso2.apk.config.definitions"}, {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.org.wso2.apk.config.model"}, {org = "wso2", packageName = "config_deployer_service", moduleName = "config_deployer_service.partitionClient"} ] diff --git a/runtime/config-deployer-service/docker/Dockerfile b/runtime/config-deployer-service/docker/Dockerfile index 82f8ba2aa..a7df67708 100644 --- a/runtime/config-deployer-service/docker/Dockerfile +++ b/runtime/config-deployer-service/docker/Dockerfile @@ -53,6 +53,8 @@ RUN groupadd --system -g ${USER_GROUP_ID} ${USER_GROUP} \ ADD config-deployer ${USER_HOME}/config-deployer COPY docker-entrypoint.sh ${USER_HOME} +COPY /lib/jmx_prometheus_javaagent-0.20.0.jar /home/${USER}/lib/ + RUN chown -R ${USER} ${USER_HOME}/config-deployer \ && chown ${USER} /home/${USER}/docker-entrypoint.sh \ && chgrp -R 0 ${USER_HOME} \ diff --git a/runtime/config-deployer-service/docker/config-deployer/config.sh b/runtime/config-deployer-service/docker/config-deployer/config.sh index cfb35a976..acac82f1b 100644 --- a/runtime/config-deployer-service/docker/config-deployer/config.sh +++ b/runtime/config-deployer-service/docker/config-deployer/config.sh @@ -98,9 +98,10 @@ fi echo "Using Java memory options: $JVM_MEM_OPTS" $JAVACMD \ - $JVM_MEM_OPTS \ - $JAVA_OPTS \ - -classpath "$CLASSPATH" \ - -Djava.io.tmpdir="$RUNTIME_HOME/tmp" \ - -jar config_deployer_service.jar $* - status=$? \ No newline at end of file + $JVM_MEM_OPTS \ + $JAVA_OPTS \ + -classpath "$CLASSPATH" \ + -Djava.io.tmpdir="$RUNTIME_HOME/tmp" \ + -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18010:/tmp/metrics/prometheus-jmx-config-configds.yml \ + -jar config_deployer_service.jar $* +status=$? diff --git a/runtime/config-deployer-service/java/build.gradle b/runtime/config-deployer-service/java/build.gradle index 95e278c66..a7f868785 100644 --- a/runtime/config-deployer-service/java/build.gradle +++ b/runtime/config-deployer-service/java/build.gradle @@ -17,8 +17,6 @@ apply from: "$projectDir/../../../common-gradle-scripts/java.gradle" - - dependencies { implementation libs.commons.logging implementation libs.gson @@ -34,4 +32,35 @@ dependencies { implementation libs.handy.uri.templates implementation libs.json implementation libs.commons.lang + implementation libs.prometheus +} + +tasks.register('copy_dependencies', Copy) { + dependsOn create_lib + from configurations.default + into "$projectDir/../docker/lib" + finalizedBy build +} + +tasks.register('create_lib') { + dependsOn delete_lib + finalizedBy copy_dependencies } + +tasks.register('delete_lib', Delete) { + delete "$projectDir/lib" + finalizedBy create_lib +} + +tasks.named('build').configure { + dependsOn copy_dependencies +} + +configurations.implementation { + exclude group: 'jline' + exclude group: 'org.slf4j', module: 'slf4j-log4j12' + exclude group: 'org.apache.logging' + exclude group: 'log4j' + exclude group: 'org.ops4j.pax.logging' + exclude group: 'com.google.guava' +} \ No newline at end of file From d1dfc144c0d9c8e90f2dec2f3e5c5fdf704f46cd Mon Sep 17 00:00:00 2001 From: sgayangi Date: Wed, 28 Feb 2024 12:33:16 +0530 Subject: [PATCH 17/24] Update configurations for Prometheus --- .../internal/config/default_config.go | 2 +- .../config-deployer/config-ds-deployment.yaml | 12 ++--- .../config-ds-prometheus-jmx-configmap.yaml | 18 +------ .../config-deployer/config-ds-service.yaml | 8 --- .../adapter/adapter-service.yaml | 5 -- .../common-controller-deployment.yaml | 2 +- .../common-controller-service.yaml | 5 -- .../gateway-runtime/enforcer-service.yaml | 5 -- .../prometheus-jmx-configmap.yaml | 16 ++++++ .../gateway-runtime/router-service.yaml | 31 ----------- .../docker/config-deployer/config.sh | 53 ++++++++++--------- 11 files changed, 52 insertions(+), 105 deletions(-) delete mode 100644 helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml diff --git a/common-controller/internal/config/default_config.go b/common-controller/internal/config/default_config.go index 2391f9524..269b19bd4 100644 --- a/common-controller/internal/config/default_config.go +++ b/common-controller/internal/config/default_config.go @@ -46,7 +46,7 @@ var defaultConfig = &Config{ Metrics: metrics{ Enabled: true, Type: "prometheus", - Port: 18009, + Port: 18010, CollectionInterval: 5, }, }, diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml index acef54358..e4d520600 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml @@ -45,7 +45,7 @@ spec: {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - containerPort: 18008 protocol: "TCP" - - containerPort: 18010 + - containerPort: 18009 protocol: "TCP" {{ end }} readinessProbe: @@ -67,6 +67,9 @@ spec: - mountPath: /home/wso2apk/config-deployer/conf/Config.toml name: config-toml-volume subPath: Config.toml + - name: prometheus-jmx-config-volume + mountPath: /tmp/metrics/prometheus-jmx-config-configds.yml + subPath: prometheus-jmx-config-configds.yml - name: config-ds-tls-volume mountPath: /home/wso2apk/config-deployer/security/config.key {{- if and .Values.wso2.apk.dp.configdeployer.configs .Values.wso2.apk.dp.configdeployer.configs.tls }} @@ -74,9 +77,6 @@ spec: {{- else }} subPath: tls.key {{- end }} - - name: prometheus-jmx-config-volume - mountPath: /tmp/metrics/prometheus-jmx-config-configds.yml - subPath: prometheus-jmx-config-configds.yml - name: config-ds-tls-volume mountPath: /home/wso2apk/config-deployer/security/config.pem {{- if and .Values.wso2.apk.dp.configdeployer.configs .Values.wso2.apk.dp.configdeployer.configs.tls }} @@ -114,8 +114,8 @@ spec: - name: config-toml-volume configMap: name: {{ template "apk-helm.resource.prefix" . }}-config-ds-configmap - - name: prometheus-jmx-config-volume - configMap: + - name: prometheus-jmx-config-volume + configMap: name: prometheus-jmx-config-configds - name: config-ds-tls-volume secret: diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml index 610f358ec..de2731309 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-prometheus-jmx-configmap.yaml @@ -23,25 +23,9 @@ data: lowercaseOutputName: true lowercaseOutputLabelNames: true rules: - # WSO2 APK related metrics - - pattern: 'org.wso2.apk.config<>total_request_count: (.*)' - name: org_wso2_apk_config_request_count_total - help: "WSO2 APK config total request count." - attrNameSnakeCase: true - type: COUNTER - - pattern: 'org.wso2.apk.config<>(average_response_time_millis|max_response_time_millis|min_response_time_millis|request_count_in_last_five_minute_window|request_count_window_start_time_millis): (.*)' - name: org_wso2_apk_config_$1 - help: "WSO2 APK config $1." - attrNameSnakeCase: true - type: GAUGE - - pattern: 'org.wso2.apk.config<>(\w+): (.*)' - name: org_wso2_apk_config_thread_pool_$1 - help: "WSO2 APK config thread pool $1." - attrNameSnakeCase: true - type: GAUGE # OS related metrics - pattern: 'java.lang<>(\w+): (.*)' name: os_$1 help: Operating System $1 attrNameSnakeCase: true - type: GAUGE \ No newline at end of file + type: GAUGE diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml index ffd488cb4..b19708a7f 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-service.yaml @@ -28,12 +28,4 @@ spec: - name: servlet-https protocol: TCP port: 9443 - {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - name: prometheus-config-ds-port-lang - protocol: TCP - port: 18008 - - name: prometheus-config-ds-port-system - protocol: TCP - port: 18010 - {{ end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml index c0c8e0c7c..8c78ff45c 100644 --- a/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/adapter/adapter-service.yaml @@ -41,9 +41,4 @@ spec: - name: profile-port protocol: TCP port: 6060 - {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} - - name: prometheus-adapter-port - port: 18006 - protocol: "TCP" - {{ end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml index ef35c6424..133cd8441 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml @@ -49,7 +49,7 @@ spec: - containerPort: 18003 protocol: TCP {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - containerPort: 18009 + - containerPort: 18010 protocol: "TCP" {{ end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.commonController.deployment.resources | indent 10 }} diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml index debcb579f..e5adf645f 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-service.yaml @@ -38,9 +38,4 @@ spec: - name: https-internal-api protocol: TCP port: 18003 - {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - name: prometheus-common-controller-port - protocol: TCP - port: 18009 - {{ end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml index a8355ce99..e88b6d861 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/enforcer-service.yaml @@ -28,9 +28,4 @@ spec: - name: servlet-https protocol: TCP port: 9092 - {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - name: prometheus-enforcer-port - protocol: TCP - port: 18007 - {{- end }} {{- end -}} diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml index dc1849b2d..4f45e2d4f 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/prometheus-jmx-configmap.yaml @@ -1,3 +1,19 @@ +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + apiVersion: v1 kind: ConfigMap metadata: diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml deleted file mode 100644 index 8450a504d..000000000 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/router-service.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. -# -# WSO2 LLC. licenses this file to you under the Apache License, -# Version 2.0 (the "License"); you may not use this file except -# in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -{{- if and .Values.wso2.apk.dp.enabled .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} -apiVersion: v1 -kind: Service -metadata: - name: {{ template "apk-helm.resource.prefix" . }}-router-service - namespace : {{ .Release.Namespace }} -spec: - # label keys and values that must match in order to receive traffic for this service - selector: -{{ include "apk-helm.pod.selectorLabels" (dict "root" . "app" "gateway" ) | indent 4}} - ports: - - name: prometheus-router-port - protocol: TCP - port: 9000 -{{- end -}} diff --git a/runtime/config-deployer-service/docker/config-deployer/config.sh b/runtime/config-deployer-service/docker/config-deployer/config.sh index acac82f1b..9cc37c02d 100644 --- a/runtime/config-deployer-service/docker/config-deployer/config.sh +++ b/runtime/config-deployer-service/docker/config-deployer/config.sh @@ -2,23 +2,26 @@ PRG="$0" while [ -h "$PRG" ]; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '.*/.*' > /dev/null; then + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '.*/.*' >/dev/null; then PRG="$link" else - PRG=`dirname "$PRG"`/"$link" + PRG=$(dirname "$PRG")/"$link" fi done # Get standard environment variables -PRGDIR=`dirname "$PRG"` +PRGDIR=$(dirname "$PRG") -[ -z "$RUNTIME_HOME" ] && RUNTIME_HOME=`cd "$PRGDIR" ; pwd` +[ -z "$RUNTIME_HOME" ] && RUNTIME_HOME=$( + cd "$PRGDIR" + pwd +) -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +if [ -z "$JAVACMD" ]; then + if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else @@ -29,7 +32,7 @@ if [ -z "$JAVACMD" ] ; then fi fi -if [ ! -x "$JAVACMD" ] ; then +if [ ! -x "$JAVACMD" ]; then echo "Error: JAVA_HOME is not defined correctly." echo " Admin cannot execute $JAVACMD" exit 1 @@ -42,16 +45,15 @@ if [ -z "$JAVA_HOME" ]; then fi # ----- Process the input command ---------------------------------------------- args="" -for c in $* -do - if [ "$c" = "--debug" ] || [ "$c" = "-debug" ] || [ "$c" = "debug" ]; then - CMD="--debug" - continue - elif [ "$CMD" = "--debug" ]; then - if [ -z "$PORT" ]; then - PORT=$c - fi +for c in $*; do + if [ "$c" = "--debug" ] || [ "$c" = "-debug" ] || [ "$c" = "debug" ]; then + CMD="--debug" + continue + elif [ "$CMD" = "--debug" ]; then + if [ -z "$PORT" ]; then + PORT=$c fi + fi done if [ "$CMD" = "--debug" ]; then @@ -69,11 +71,10 @@ fi CLASSPATH="" if [ -e "$JAVA_HOME/lib/tools.jar" ]; then - CLASSPATH="$JAVA_HOME/lib/tools.jar" + CLASSPATH="$JAVA_HOME/lib/tools.jar" fi -for t in "$RUNTIME_HOME"/lib/*.jar -do - CLASSPATH="$CLASSPATH":$t +for t in "$RUNTIME_HOME"/lib/*.jar; do + CLASSPATH="$CLASSPATH":$t done # ----- Execute The Requested Command ----------------------------------------- @@ -85,15 +86,15 @@ cd "$RUNTIME_HOME" TMP_DIR="$RUNTIME_HOME"/tmp if [ -d "$TMP_DIR" ]; then -rm -rf "$TMP_DIR"/* + rm -rf "$TMP_DIR"/* fi START_EXIT_STATUS=121 status=$START_EXIT_STATUS if [ -z "$JVM_MEM_OPTS" ]; then - java_version=$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}') - JVM_MEM_OPTS="-Xms256m -Xmx1024m" + java_version=$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}') + JVM_MEM_OPTS="-Xms256m -Xmx1024m" fi echo "Using Java memory options: $JVM_MEM_OPTS" From 44302fc81bf519dd52ed5a4bd6eb491367fedc75 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Thu, 29 Feb 2024 11:54:47 +0530 Subject: [PATCH 18/24] Add Prometheus support to IdP DS --- .../config-deployer/config-ds-configmap.yaml | 4 +-- .../idp/idp-ds/idp-ds-configmap.yaml | 14 ++++++++- .../idp/idp-ds/idp-ds-deployment.yaml | 12 +++++++ .../idp-ds-prometheus-jmx-configmap.yaml | 31 +++++++++++++++++++ helm-charts/values.yaml | 6 ++-- helm-charts/values.yaml.template | 8 +++++ .../ballerina/Ballerina.toml | 5 +++ .../ballerina/Dependencies.toml | 18 ++++++++++- idp/idp-domain-service/ballerina/Init.bal | 1 + idp/idp-domain-service/docker/Dockerfile | 1 + idp/idp-domain-service/docker/build.gradle | 29 +++++++++++++++-- idp/idp-domain-service/docker/idp/idp.sh | 13 ++++---- .../docker/config-deployer/config.sh | 2 +- 13 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 helm-charts/templates/idp/idp-ds/idp-ds-prometheus-jmx-configmap.yaml diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml index 8fd18a700..1f6c3f6f3 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml @@ -32,8 +32,8 @@ data: metricsReporter="prometheus" [ballerinax.prometheus] port=18008 - {{if .Values.wso2.apk.metrics.configDSBalPort}} - host="{{ .Values.wso2.apk.metrics.configDSBalPort}}" + {{if .Values.wso2.apk.metrics.configDSBalHost}} + host="{{ .Values.wso2.apk.metrics.configDSBalHost}}" {{else}} host="0.0.0.0" {{end}} diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml index 5ac4bf1be..d33cea731 100644 --- a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml +++ b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml @@ -25,7 +25,19 @@ data: [ballerina.log] level = "INFO" [ballerina.http] - traceLogConsole = true + traceLogConsole = false + {{if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + [ballerina.observe] + metricsEnabled=true + metricsReporter="prometheus" + [ballerinax.prometheus] + port=18011 + {{if .Values.wso2.apk.metrics.idpDSBalHost}} + host="{{ .Values.wso2.apk.metrics.idpDSBalHost}}" + {{else}} + host="0.0.0.0" + {{end}} + {{end}} # Sample configurations [wso2.idp_domain_service.datasourceConfiguration] description = "Database for idp" diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml index d246dd99d..079209c48 100644 --- a/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml +++ b/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml @@ -51,6 +51,12 @@ spec: ports: - containerPort: 9443 protocol: "TCP" + {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} + - containerPort: 18011 + protocol: "TCP" + - containerPort: 18012 + protocol: "TCP" + {{ end }} readinessProbe: httpGet: path: /health @@ -76,6 +82,9 @@ spec: - mountPath: /home/wso2apk/idp/security/wso2carbon.pem name: idp-signing-keystore-volume subPath: wso2carbon.pem + - name: prometheus-jmx-config-volume + mountPath: /tmp/metrics/prometheus-jmx-config-idpds.yml + subPath: prometheus-jmx-config-idpds.yml - name: idp-ds-tls-volume mountPath: /home/wso2apk/idp/security/idp.key {{- if and .Values.idp.idpds.configs .Values.idp.idpds.configs.tls }} @@ -111,6 +120,9 @@ spec: - name: config-toml-volume configMap: name: {{ template "apk-helm.resource.prefix" . }}-idp-ds-configmap + - name: prometheus-jmx-config-volume + configMap: + name: prometheus-jmx-config-idpds - name: idp-signing-keystore-volume secret: secretName: {{ template "apk-helm.resource.prefix" . }}-idp-signing-keystore-secret diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-prometheus-jmx-configmap.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-prometheus-jmx-configmap.yaml new file mode 100644 index 000000000..773615b87 --- /dev/null +++ b/helm-charts/templates/idp/idp-ds/idp-ds-prometheus-jmx-configmap.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-jmx-config-idpds +data: + prometheus-jmx-config-idpds.yml: | + lowercaseOutputName: true + lowercaseOutputLabelNames: true + rules: + # OS related metrics + - pattern: 'java.lang<>(\w+): (.*)' + name: os_$1 + help: Operating System $1 + attrNameSnakeCase: true + type: GAUGE diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index e670c336c..88a34f604 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -251,8 +251,10 @@ wso2: # hostnameVerifier: "AllowAll" metrics: - enabled: true - # configDSBalPort: 0.0.0.0 + enabled: false + # configDSBalHost: 0.0.0.0 + # idpDSBalHost: 0.0.0.0 + idp: enabled: true listener: diff --git a/helm-charts/values.yaml.template b/helm-charts/values.yaml.template index 0c04fc44c..ebfa2189a 100644 --- a/helm-charts/values.yaml.template +++ b/helm-charts/values.yaml.template @@ -592,6 +592,14 @@ wso2: keepAliveTime: 600 # -- Queue size of the worker threads queueSize: 1000 + metrics: + # -- Enable Prometheus metrics + enabled: false + # -- Configure the host for exposing the config ds ballerina metrics + # configDSBalHost: 0.0.0.0 + # -- Configure the host for exposing the idp ds ballerina metrics. + # idpDSBalHost: 0.0.0.0 + idp: # -- Enable Non production identity server enabled: true diff --git a/idp/idp-domain-service/ballerina/Ballerina.toml b/idp/idp-domain-service/ballerina/Ballerina.toml index 7f9e44b8e..ac2a6ec1e 100644 --- a/idp/idp-domain-service/ballerina/Ballerina.toml +++ b/idp/idp-domain-service/ballerina/Ballerina.toml @@ -9,5 +9,10 @@ groupId = "org.postgresql" artifactId = "postgresql" version = "42.2.20" +[[platform.java11.dependency]] +groupId = "io.prometheus.jmx" +artifactId = "jmx_prometheus_javaagent" +version = "0.20.0" + [build-options] observabilityIncluded = true diff --git a/idp/idp-domain-service/ballerina/Dependencies.toml b/idp/idp-domain-service/ballerina/Dependencies.toml index fc72aa1d3..210772f7e 100644 --- a/idp/idp-domain-service/ballerina/Dependencies.toml +++ b/idp/idp-domain-service/ballerina/Dependencies.toml @@ -375,6 +375,21 @@ modules = [ {org = "ballerinax", packageName = "postgresql", moduleName = "postgresql"} ] +[[package]] +org = "ballerinax" +name = "prometheus" +version = "0.2.0" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "regex"} +] +modules = [ + {org = "ballerinax", packageName = "prometheus", moduleName = "prometheus"} +] + [[package]] org = "wso2" name = "idp_domain_service" @@ -392,7 +407,8 @@ dependencies = [ {org = "ballerina", name = "url"}, {org = "ballerina", name = "uuid"}, {org = "ballerinai", name = "observe"}, - {org = "ballerinax", name = "postgresql"} + {org = "ballerinax", name = "postgresql"}, + {org = "ballerinax", name = "prometheus"} ] modules = [ {org = "wso2", packageName = "idp_domain_service", moduleName = "idp_domain_service"} diff --git a/idp/idp-domain-service/ballerina/Init.bal b/idp/idp-domain-service/ballerina/Init.bal index b34ebe42a..78fe6721e 100644 --- a/idp/idp-domain-service/ballerina/Init.bal +++ b/idp/idp-domain-service/ballerina/Init.bal @@ -20,6 +20,7 @@ import ballerina/log; import ballerina/sql; import ballerina/http; import ballerina/jwt; +import ballerinax/prometheus as _; configurable IDPConfiguration & readonly idpConfiguration = ?; final postgresql:Client|sql:Error dbClient; diff --git a/idp/idp-domain-service/docker/Dockerfile b/idp/idp-domain-service/docker/Dockerfile index 6f8406c82..f07cf7498 100644 --- a/idp/idp-domain-service/docker/Dockerfile +++ b/idp/idp-domain-service/docker/Dockerfile @@ -72,6 +72,7 @@ RUN groupadd --system -g ${USER_GROUP_ID} ${USER_GROUP} \ ADD idp ${USER_HOME}/idp COPY docker-entrypoint.sh ${USER_HOME} +COPY /lib/jmx_prometheus_javaagent-0.20.0.jar /home/${USER}/lib/ RUN chown -R ${USER} ${USER_HOME}/idp \ && chown ${USER} /home/${USER}/docker-entrypoint.sh \ diff --git a/idp/idp-domain-service/docker/build.gradle b/idp/idp-domain-service/docker/build.gradle index 75f812f75..03c2890c1 100644 --- a/idp/idp-domain-service/docker/build.gradle +++ b/idp/idp-domain-service/docker/build.gradle @@ -18,20 +18,45 @@ apply from: "$projectDir/../../../common-gradle-scripts/docker.gradle" apply from: "$rootDir/../../common-gradle-scripts/copy.gradle" +apply from: "$projectDir/../../../common-gradle-scripts/java.gradle" +dependencies { + implementation libs.prometheus +} + +tasks.register('copy_dependencies', Copy) { + dependsOn create_lib + from configurations.default + into "$projectDir/../docker/lib" + finalizedBy build +} + +tasks.register('create_lib') { + dependsOn delete_lib + finalizedBy copy_dependencies +} + +tasks.register('delete_lib', Delete) { + delete "$projectDir/lib" + finalizedBy create_lib +} + +tasks.named('build').configure { + dependsOn copy_dependencies +} tasks.named('copy_dist').configure{ finalizedBy docker_build } -task build{ +task buildDockerImage{ group 'build' description 'Build docker image' dependsOn 'copy_dist' dependsOn 'docker_build' } -build.configure{ +buildDockerImage.configure{ mustRunAfter(":ballerina:build") dependsOn(":ballerina:build") } \ No newline at end of file diff --git a/idp/idp-domain-service/docker/idp/idp.sh b/idp/idp-domain-service/docker/idp/idp.sh index ffa63a2c1..03cb90968 100755 --- a/idp/idp-domain-service/docker/idp/idp.sh +++ b/idp/idp-domain-service/docker/idp/idp.sh @@ -98,9 +98,10 @@ fi echo "Using Java memory options: $JVM_MEM_OPTS" $JAVACMD \ - $JVM_MEM_OPTS \ - $JAVA_OPTS \ - -classpath "$CLASSPATH" \ - -Djava.io.tmpdir="$IDP_HOME/tmp" \ - -jar idp_domain_service.jar $* - status=$? \ No newline at end of file + $JVM_MEM_OPTS \ + $JAVA_OPTS \ + -classpath "$CLASSPATH" \ + -Djava.io.tmpdir="$IDP_HOME/tmp" \ + -javaagent:/home/wso2apk/jmx_prometheus_javaagent-0.20.0.jar=18012:/tmp/metrics/prometheus-jmx-config-idpds.yml \ + -jar idp_domain_service.jar $* +status=$? diff --git a/runtime/config-deployer-service/docker/config-deployer/config.sh b/runtime/config-deployer-service/docker/config-deployer/config.sh index 9cc37c02d..ccc254e6a 100644 --- a/runtime/config-deployer-service/docker/config-deployer/config.sh +++ b/runtime/config-deployer-service/docker/config-deployer/config.sh @@ -103,6 +103,6 @@ $JAVACMD \ $JAVA_OPTS \ -classpath "$CLASSPATH" \ -Djava.io.tmpdir="$RUNTIME_HOME/tmp" \ - -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18010:/tmp/metrics/prometheus-jmx-config-configds.yml \ + -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18009:/tmp/metrics/prometheus-jmx-config-configds.yml \ -jar config_deployer_service.jar $* status=$? From 3483bd4c069709e55fb6d9fcc60c26ade5b0eb2a Mon Sep 17 00:00:00 2001 From: sgayangi Date: Fri, 1 Mar 2024 15:55:13 +0530 Subject: [PATCH 19/24] Add Prometheus support to ratelimiter --- .../ratelimiter/ratelimiter-deployment.yaml | 16 +++++++++++++++- helm-charts/values.yaml | 12 ++++++++++++ helm-charts/values.yaml.template | 13 +++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml b/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml index 7f15be10f..5821cb0c1 100644 --- a/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml +++ b/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml @@ -35,6 +35,14 @@ spec: automountServiceAccountToken: false serviceAccountName: {{ .Values.wso2.apk.auth.serviceAccountName }} containers: + {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }} + - name: statsd + image: {{ .Values.wso2.apk.metrics.statsd.image.repository }}:{{ .Values.wso2.apk.metrics.statsd.image.tag }} + imagePullPolicy: {{ .Values.wso2.apk.metrics.statsd.imagePullPolicy }} + ports: + - name: statsd-metrics + containerPort: 9102 + {{ end }} - name: ratelimiter image: {{ .Values.wso2.apk.dp.ratelimiter.deployment.image }} imagePullPolicy: {{ .Values.wso2.apk.dp.ratelimiter.deployment.imagePullPolicy }} @@ -52,7 +60,13 @@ spec: - name: PORT value: "8090" - name: USE_STATSD - value: "false" + value: "{{ and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }}" + {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }} + - name: STATSD_HOST + value: "0.0.0.0" + - name: STATSD_PORT + value: "9125" + {{- end}} - name: LOG_LEVEL value: "DEBUG" - name: LIMIT_RESPONSE_HEADERS_ENABLED diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index 88a34f604..4f709376a 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -254,6 +254,18 @@ wso2: enabled: false # configDSBalHost: 0.0.0.0 # idpDSBalHost: 0.0.0.0 + # statsd: + # enabled: true + # image: + # repository: prom/statsd-exporter + # tag: v0.26.0 + # imagePullPolicy: IfNotPresent + # resources: + # limits: + # memory: 128Mi + # requests: + # cpu: 0.1 + # memory: 64Mi idp: enabled: true diff --git a/helm-charts/values.yaml.template b/helm-charts/values.yaml.template index ebfa2189a..9c0f1418c 100644 --- a/helm-charts/values.yaml.template +++ b/helm-charts/values.yaml.template @@ -599,6 +599,19 @@ wso2: # configDSBalHost: 0.0.0.0 # -- Configure the host for exposing the idp ds ballerina metrics. # idpDSBalHost: 0.0.0.0 + # -- Statsd is required to expose metrics from ratelimiter + # statsd: + # enabled: true + # image: + # repository: prom/statsd-exporter + # tag: v0.26.0 + # imagePullPolicy: IfNotPresent + # resources: + # limits: + # memory: 128Mi + # requests: + # cpu: 0.1 + # memory: 64Mi idp: # -- Enable Non production identity server From e532eff17dadf7376a2354394966ddb0fa6c1d69 Mon Sep 17 00:00:00 2001 From: sgayangi Date: Sun, 3 Mar 2024 09:49:46 +0530 Subject: [PATCH 20/24] Address review comments --- adapter/config/default_config.go | 7 +- adapter/go.mod | 8 +- adapter/go.sum | 13 +- adapter/internal/adapter/adapter.go | 2 +- adapter/internal/discovery/xds/server.go | 11 + .../operator/synchronizer/data_store.go | 5 - adapter/pkg/metrics/metrics.go | 256 ++++-------------- .../commoncontroller/common_controller.go | 6 +- common-controller/go.mod | 8 +- common-controller/go.sum | 9 +- .../internal/config/default_config.go | 7 +- common-controller/pkg/metrics/metrics.go | 191 +------------ common-go-libs/go.mod | 15 +- common-go-libs/go.sum | 27 +- common-go-libs/pkg/metrics/metrics.go | 179 ++++++++++++ common-go-libs/pkg/metrics/types.go | 24 ++ .../discovery/JWTIssuerDiscoveryClient.java | 3 +- .../subscription/SubscriptionDataHolder.java | 23 +- .../subscription/SubscriptionDataStore.java | 12 +- .../SubscriptionDataStoreImpl.java | 13 + .../SubscriptionDataStoreUtil.java | 9 +- .../gateway-components/common-log-conf.yaml | 6 + .../gateway-components/log-conf.yaml | 6 + .../ratelimiter/ratelimiter-deployment.yaml | 11 +- helm-charts/values.yaml | 1 - helm-charts/values.yaml.template | 1 - 26 files changed, 420 insertions(+), 433 deletions(-) create mode 100644 common-go-libs/pkg/metrics/metrics.go create mode 100644 common-go-libs/pkg/metrics/types.go diff --git a/adapter/config/default_config.go b/adapter/config/default_config.go index 1fe3847d7..72dd7cd01 100644 --- a/adapter/config/default_config.go +++ b/adapter/config/default_config.go @@ -33,10 +33,9 @@ var defaultConfig = &Config{ }, Environment: "Default", Metrics: metrics{ - Enabled: true, - Type: "prometheus", - Port: 18006, - CollectionInterval: 5, + Enabled: false, + Type: "prometheus", + Port: 18006, }, }, Envoy: envoy{ diff --git a/adapter/go.mod b/adapter/go.mod index 03faae8b7..de51aaa18 100644 --- a/adapter/go.mod +++ b/adapter/go.mod @@ -10,9 +10,7 @@ require ( github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 github.com/pelletier/go-toml v1.9.5 - github.com/prometheus/client_golang v1.18.0 - github.com/prometheus/procfs v0.12.0 - github.com/shirou/gopsutil/v3 v3.24.1 + github.com/prometheus/client_golang v1.17.0 github.com/sirupsen/logrus v1.9.0 github.com/wso2/apk/common-go-libs v0.0.0-20231208100153-24bee7b4bd81 golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb @@ -62,12 +60,14 @@ require ( github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/shirou/gopsutil/v3 v3.24.2 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/vektah/gqlparser v1.3.1 // indirect - github.com/yusufpapurcu/wmi v1.2.3 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect golang.org/x/net v0.21.0 // indirect diff --git a/adapter/go.sum b/adapter/go.sum index 0af7a43be..b59fd5b9a 100644 --- a/adapter/go.sum +++ b/adapter/go.sum @@ -117,8 +117,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= -github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= -github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= +github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= +github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= @@ -128,8 +128,8 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= -github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= +github.com/shirou/gopsutil/v3 v3.24.2 h1:kcR0erMbLg5/3LcInpw0X/rrPSqq4CDPyI6A6ZRC18Y= +github.com/shirou/gopsutil/v3 v3.24.2/go.mod h1:tSg/594BcA+8UdQU2XcW803GWYgdtauFFPgJCJKZlVk= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -159,8 +159,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= -github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= @@ -214,7 +214,6 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/adapter/internal/adapter/adapter.go b/adapter/internal/adapter/adapter.go index 83575ee23..ec8d8eb3e 100644 --- a/adapter/internal/adapter/adapter.go +++ b/adapter/internal/adapter/adapter.go @@ -160,7 +160,7 @@ func Run(conf *config.Config) { // Start the metrics server if conf.Adapter.Metrics.Enabled && strings.EqualFold(conf.Adapter.Metrics.Type, metrics.PrometheusMetricType) { logger.LoggerAPK.Info("Starting Prometheus Metrics Server ....") - go metrics.StartPrometheusMetricsServer(conf.Adapter.Metrics.Port, conf.Adapter.Metrics.CollectionInterval) + go metrics.StartPrometheusMetricsServer(conf.Adapter.Metrics.Port) } cache := xds.GetXdsCache() diff --git a/adapter/internal/discovery/xds/server.go b/adapter/internal/discovery/xds/server.go index da5dd9295..cd7607a78 100644 --- a/adapter/internal/discovery/xds/server.go +++ b/adapter/internal/discovery/xds/server.go @@ -813,3 +813,14 @@ func GetEnvoyInternalAPIClusters() int { } return totalClusters } + +// GetEnvoyInternalAPICount method gets the number of APIs deployed in Envoy +func GetEnvoyInternalAPICount() int { + totalCount := 0 + for _, apiMap := range orgAPIMap { + for range apiMap { + totalCount++ + } + } + return totalCount +} diff --git a/adapter/internal/operator/synchronizer/data_store.go b/adapter/internal/operator/synchronizer/data_store.go index 1ec062f86..80265707d 100644 --- a/adapter/internal/operator/synchronizer/data_store.go +++ b/adapter/internal/operator/synchronizer/data_store.go @@ -571,8 +571,3 @@ func (ods *OperatorDataStore) DeleteCachedGateway(gatewayName types.NamespacedNa defer ods.mu.Unlock() delete(ods.gatewayStore, gatewayName) } - -// GetAPICount gets API count -func (ods *OperatorDataStore) GetAPICount() int { - return len(ods.apiStore) -} diff --git a/adapter/pkg/metrics/metrics.go b/adapter/pkg/metrics/metrics.go index d62e21ef0..d0f797471 100644 --- a/adapter/pkg/metrics/metrics.go +++ b/adapter/pkg/metrics/metrics.go @@ -22,227 +22,89 @@ package metrics import ( "fmt" "net/http" - "os" - "runtime" "strconv" - "time" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/procfs" - "github.com/shirou/gopsutil/v3/cpu" - "github.com/shirou/gopsutil/v3/host" - "github.com/shirou/gopsutil/v3/load" - "github.com/shirou/gopsutil/v3/mem" xds "github.com/wso2/apk/adapter/internal/discovery/xds" logger "github.com/wso2/apk/adapter/internal/loggers" - synchronizer "github.com/wso2/apk/adapter/internal/operator/synchronizer" "github.com/wso2/apk/adapter/pkg/logging" + commonmetrics "github.com/wso2/apk/common-go-libs/pkg/metrics" ) var ( prometheusMetricRegistry = prometheus.NewRegistry() - - hostInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "host_info", - Help: "Host Info", - }, []string{"os"}) - - availableCPUs = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_available_cpu_total", - Help: "Number of available CPUs.", - }) - - freePhysicalMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_free_physical_memory_bytes", - Help: "Amount of free physical memory.", - }) - - totalVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_total_virtual_memory_bytes", - Help: "Amount of total virtual memory.", - }) - usedVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_used_virtual_memory_bytes", - Help: "Amount of used virtual memory.", - }) - - systemCPULoad = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_system_cpu_load_percentage", - Help: "System-wide CPU usage as a percentage.", - }) - - loadAvg = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "os_system_load_average", - Help: "Current load of CPU in the host system for the last {x} minutes", - }, []string{"duration"}) - - processStartTime = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "process_start_time_seconds", - Help: "Start time of the process since unix epoch in seconds.", - }) - - processOpenFDs = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "process_open_fds", - Help: "Number of open file descriptors.", - }) - - apis = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "api_count", - Help: "Number of APIs created.", - }) - - internalClusterCount = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "internal_cluster_count", - Help: "Number of internal clusters created.", - }) - - gwClusterCount = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "gw_cluster_count", - Help: "Number of gw clusters created.", - }) - - internalRouteCount = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "internal_route_count", - Help: "Number of internal routes created.", - }) ) -func init() { - // Register the Go collector with the registry - goCollector := collectors.NewGoCollector() - prometheusMetricRegistry.MustRegister(goCollector) - - // Register other metrics - prometheusMetricRegistry.MustRegister(hostInfo, availableCPUs, freePhysicalMemory, usedVirtualMemory, totalVirtualMemory, - systemCPULoad, loadAvg, processStartTime, processOpenFDs, apis, internalClusterCount, internalRouteCount, gwClusterCount) +// AdapterCollector contains the descriptions of the custom metrics exposed by the adapter. +// It also uses the metrics defined in common-go-libs +type AdapterCollector struct { + commonmetrics.Collector + apis *prometheus.Desc + internalClusterCount *prometheus.Desc + internalRouteCount *prometheus.Desc } -// recordMetrics record custom golang metrics -var recordMetrics = func(collectionInterval int32) { - for { - envoyInternalAPIClusterCount := xds.GetEnvoyInternalAPIClusters() - internalClusterCount.Set(float64(envoyInternalAPIClusterCount)) - - envoyInternalAPIRouteCount := xds.GetEnvoyInternalAPIRoutes() - internalRouteCount.Set(float64(envoyInternalAPIRouteCount)) - - gwClusterCount.Set(float64(xds.GetEnvoyGatewayConfigClusters())) - - apiCount := synchronizer.GetOperatorDataStore().GetAPICount() - apis.Set(float64(apiCount)) - - host, err := host.Info() - if handleError(err, "Failed to get host info") { - return - } - hostInfo.WithLabelValues(host.OS).Set(1) - availableCPUs.Set(float64(runtime.NumCPU())) - - v, err := mem.VirtualMemory() - if handleError(err, "Failed to read virtual memory metrics") { - return - } - freePhysicalMemory.Set(float64(v.Free)) - usedVirtualMemory.Set(float64(v.Used)) - totalVirtualMemory.Set(float64(v.Total)) +func adapterMetricsCollector() *AdapterCollector { + return &AdapterCollector{ + Collector: *commonmetrics.CustomMetricsCollector(), + apis: prometheus.NewDesc( + "api_count", + "Number of APIs created.", + nil, nil, + ), + internalClusterCount: prometheus.NewDesc( + "internal_cluster_count", + "Number of internal clusters created.", + nil, nil, + ), + internalRouteCount: prometheus.NewDesc( + "internal_route_count", + "Number of internal routes created.", + nil, nil, + ), + } +} - percentages, err := cpu.Percent(0, false) - if handleError(err, "Failed to read cpu usage metrics") || len(percentages) == 0 { - return - } - totalPercentage := 0.0 - for _, p := range percentages { - totalPercentage += p - } - averagePercentage := totalPercentage / float64(len(percentages)) - systemCPULoad.Set(averagePercentage) +// Describe sends all the descriptors of the metrics collected by this Collector +// to the provided channel. +func (collector *AdapterCollector) Describe(ch chan<- *prometheus.Desc) { + collector.Collector.Describe(ch) + ch <- collector.apis + ch <- collector.internalClusterCount + ch <- collector.internalRouteCount +} - pid := os.Getpid() - p, err := procfs.NewProc(pid) - if handleError(err, "Failed to get current process") { - return - } - stat, err := p.Stat() - if handleError(err, "Failed to get process stats") { - return - } - t, err := stat.StartTime() - if handleError(err, "Failed to read process start time") { - return - } - processStartTime.Set(t) - fds, err := p.FileDescriptorsLen() - if handleError(err, "Failed to read file descriptor count") { - return - } - processOpenFDs.Set(float64(fds)) +// Collect collects all the relevant Prometheus metrics. +func (collector *AdapterCollector) Collect(ch chan<- prometheus.Metric) { + collector.Collector.Collect(ch) + var apisCount float64 + var internalClusterCount float64 + var internalRouteCount float64 - avg, err := load.Avg() - if handleError(err, "Failed to read cpu load averages") { - return - } - loadAvg.WithLabelValues("1m").Set(avg.Load1) - loadAvg.WithLabelValues("5m").Set(avg.Load5) - loadAvg.WithLabelValues("15m").Set(avg.Load15) + apiCount := xds.GetEnvoyInternalAPICount() + apisCount = float64(apiCount) - // Sleep before the next measurement - time.Sleep(time.Duration(collectionInterval) * time.Second) - } + internalRouteCount = float64(xds.GetEnvoyInternalAPIRoutes()) + internalClusterCount = float64(xds.GetEnvoyInternalAPIClusters()) + ch <- prometheus.MustNewConstMetric(collector.apis, prometheus.GaugeValue, apisCount) + ch <- prometheus.MustNewConstMetric(collector.internalRouteCount, prometheus.GaugeValue, internalRouteCount) + ch <- prometheus.MustNewConstMetric(collector.internalClusterCount, prometheus.GaugeValue, internalClusterCount) } -func handleError(err error, message string) bool { +// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. +func StartPrometheusMetricsServer(port int32) { + + collector := adapterMetricsCollector() + prometheus.MustRegister(collector) + http.Handle("/metrics", promhttp.Handler()) + err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) if err != nil { logger.LoggerAPK.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf(message, err.Error()), - Severity: logging.MINOR, - ErrorCode: 1109, + Message: fmt.Sprintln("Prometheus metrics server error:", err), + Severity: logging.MAJOR, + ErrorCode: 1110, }) - return true - } - return false -} - -// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. -func StartPrometheusMetricsServer(port int32, collectionInterval int32) { - done := make(chan struct{}) // Channel to indicate recordMetrics routine exit - - // Start the Prometheus metrics server - go func() { - http.Handle("/metrics", promhttp.HandlerFor(prometheusMetricRegistry, promhttp.HandlerOpts{})) - err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) - if err != nil { - logger.LoggerAPK.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintln("Prometheus metrics server error:", err), - Severity: logging.MAJOR, - ErrorCode: 1110, - }) - } - }() - - for { - // Start the recordMetrics goroutine - go func() { - defer func() { - if r := recover(); r != nil { - logger.LoggerAPK.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintln("recordMetrics goroutine exited with error:", r), - Severity: logging.MAJOR, - ErrorCode: 1111, - }) - } - }() - recordMetrics(collectionInterval) - done <- struct{}{} // Signal that the goroutine has completed - }() - - // Wait for the previous recordMetrics goroutine to complete - <-done - - // Log and restart the goroutine - logger.LoggerAPK.Info("Restarting recordMetrics goroutine...") - time.Sleep(3 * time.Second) } } diff --git a/common-controller/commoncontroller/common_controller.go b/common-controller/commoncontroller/common_controller.go index 676c87bff..d270085b2 100644 --- a/common-controller/commoncontroller/common_controller.go +++ b/common-controller/commoncontroller/common_controller.go @@ -206,14 +206,14 @@ func InitCommonControllerServer(conf *config.Config) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - loggers.LoggerAPKOperator.Info("Starting common controller ....") - // Start the metrics server if conf.CommonController.Metrics.Enabled && strings.EqualFold(conf.CommonController.Metrics.Type, metrics.PrometheusMetricType) { loggers.LoggerAPKOperator.Info("Starting Prometheus Metrics Server ....") - go metrics.StartPrometheusMetricsServer(conf.CommonController.Metrics.Port, conf.CommonController.Metrics.CollectionInterval) + go metrics.StartPrometheusMetricsServer(conf.CommonController.Metrics.Port) } + loggers.LoggerAPKOperator.Info("Starting common controller ....") + rateLimiterCache := xds.GetRateLimiterCache() rlsSrv := xdsv3.NewServer(ctx, rateLimiterCache, &xds.Callbacks{}) diff --git a/common-controller/go.mod b/common-controller/go.mod index 9013a7ac6..fa2172190 100644 --- a/common-controller/go.mod +++ b/common-controller/go.mod @@ -6,7 +6,7 @@ require ( github.com/onsi/ginkgo/v2 v2.11.0 github.com/onsi/gomega v1.27.10 github.com/prometheus/client_golang v1.18.0 - github.com/prometheus/procfs v0.12.0 + github.com/prometheus/procfs v0.12.0 // indirect github.com/sirupsen/logrus v1.9.0 k8s.io/apimachinery v0.28.3 k8s.io/client-go v0.28.3 @@ -20,9 +20,8 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/pelletier/go-toml v1.9.5 github.com/redis/go-redis/v9 v9.2.1 - github.com/shirou/gopsutil/v3 v3.24.1 github.com/wso2/apk/adapter v0.0.0-20231207051518-6dd728943082 - github.com/wso2/apk/common-go-libs v0.0.0-20231208100153-24bee7b4bd81 + github.com/wso2/apk/common-go-libs v0.0.0-20240304050809-a382bc6b0d82 google.golang.org/grpc v1.62.0 ) @@ -51,13 +50,14 @@ require ( github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shirou/gopsutil/v3 v3.24.2 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/vektah/gqlparser v1.3.1 // indirect - github.com/yusufpapurcu/wmi v1.2.3 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect diff --git a/common-controller/go.sum b/common-controller/go.sum index b678ced88..b98da4f27 100644 --- a/common-controller/go.sum +++ b/common-controller/go.sum @@ -186,8 +186,8 @@ github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0 github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI= -github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU= +github.com/shirou/gopsutil/v3 v3.24.2 h1:kcR0erMbLg5/3LcInpw0X/rrPSqq4CDPyI6A6ZRC18Y= +github.com/shirou/gopsutil/v3 v3.24.2/go.mod h1:tSg/594BcA+8UdQU2XcW803GWYgdtauFFPgJCJKZlVk= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -227,8 +227,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= -github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= @@ -304,7 +304,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/common-controller/internal/config/default_config.go b/common-controller/internal/config/default_config.go index 269b19bd4..396ec2b16 100644 --- a/common-controller/internal/config/default_config.go +++ b/common-controller/internal/config/default_config.go @@ -44,10 +44,9 @@ var defaultConfig = &Config{ Persistence: persistence{Type: "K8s"}, }, Metrics: metrics{ - Enabled: true, - Type: "prometheus", - Port: 18010, - CollectionInterval: 5, + Enabled: false, + Type: "prometheus", + Port: 18010, }, }, } diff --git a/common-controller/pkg/metrics/metrics.go b/common-controller/pkg/metrics/metrics.go index ef7824ebb..c2da1fa33 100644 --- a/common-controller/pkg/metrics/metrics.go +++ b/common-controller/pkg/metrics/metrics.go @@ -16,200 +16,33 @@ * under the License. */ -// Package metrics holds the implementation for exposing common controller metrics to prometheus +// Package metrics holds the implementation for exposing adapter metrics to prometheus package metrics import ( "fmt" "net/http" - "os" - "runtime" "strconv" - "time" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/procfs" - "github.com/shirou/gopsutil/v3/cpu" - "github.com/shirou/gopsutil/v3/host" - "github.com/shirou/gopsutil/v3/load" - "github.com/shirou/gopsutil/v3/mem" "github.com/wso2/apk/adapter/pkg/logging" logger "github.com/wso2/apk/common-controller/internal/loggers" + metrics "github.com/wso2/apk/common-go-libs/pkg/metrics" ) -var ( - prometheusMetricRegistry = prometheus.NewRegistry() - - hostInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "host_info", - Help: "Host Info", - }, []string{"os"}) - - availableCPUs = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_available_cpu_total", - Help: "Number of available CPUs.", - }) - - freePhysicalMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_free_physical_memory_bytes", - Help: "Amount of free physical memory.", - }) - - totalVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_total_virtual_memory_bytes", - Help: "Amount of total virtual memory.", - }) - usedVirtualMemory = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_used_virtual_memory_bytes", - Help: "Amount of used virtual memory.", - }) - - systemCPULoad = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "os_system_cpu_load_percentage", - Help: "System-wide CPU usage as a percentage.", - }) - - loadAvg = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "os_system_load_average", - Help: "Current load of CPU in the host system for the last {x} minutes", - }, []string{"duration"}) - - processStartTime = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "process_start_time_seconds", - Help: "Start time of the process since unix epoch in seconds.", - }) - - processOpenFDs = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "process_open_fds", - Help: "Number of open file descriptors.", - }) -) - -func init() { - // Register the Go collector with the registry - goCollector := collectors.NewGoCollector() - prometheusMetricRegistry.MustRegister(goCollector) - - // Register other metrics - prometheusMetricRegistry.MustRegister(hostInfo, availableCPUs, freePhysicalMemory, usedVirtualMemory, totalVirtualMemory, - systemCPULoad, loadAvg, processStartTime, processOpenFDs) -} - -// recordMetrics record custom golang metrics -var recordMetrics = func(collectionInterval int32) { - for { - host, err := host.Info() - if handleError(err, "Failed to get host info") { - return - } - hostInfo.WithLabelValues(host.OS).Set(1) - availableCPUs.Set(float64(runtime.NumCPU())) - - v, err := mem.VirtualMemory() - if handleError(err, "Failed to read virtual memory metrics") { - return - } - freePhysicalMemory.Set(float64(v.Free)) - usedVirtualMemory.Set(float64(v.Used)) - totalVirtualMemory.Set(float64(v.Total)) - - percentages, err := cpu.Percent(0, false) - if handleError(err, "Failed to read cpu usage metrics") || len(percentages) == 0 { - return - } - totalPercentage := 0.0 - for _, p := range percentages { - totalPercentage += p - } - averagePercentage := totalPercentage / float64(len(percentages)) - systemCPULoad.Set(averagePercentage) - - pid := os.Getpid() - p, err := procfs.NewProc(pid) - if handleError(err, "Failed to get current process") { - return - } - stat, err := p.Stat() - if handleError(err, "Failed to get process stats") { - return - } - t, err := stat.StartTime() - if handleError(err, "Failed to read process start time") { - return - } - processStartTime.Set(t) - fds, err := p.FileDescriptorsLen() - if handleError(err, "Failed to read file descriptor count") { - return - } - processOpenFDs.Set(float64(fds)) - - avg, err := load.Avg() - if handleError(err, "Failed to read cpu load averages") { - return - } - loadAvg.WithLabelValues("1m").Set(avg.Load1) - loadAvg.WithLabelValues("5m").Set(avg.Load5) - loadAvg.WithLabelValues("15m").Set(avg.Load15) - - // Sleep before the next measurement - time.Sleep(time.Duration(collectionInterval) * time.Second) - } - -} +// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. +func StartPrometheusMetricsServer(port int32) { -func handleError(err error, message string) bool { + collector := metrics.CustomMetricsCollector() + prometheus.MustRegister(collector) + http.Handle("/metrics", promhttp.Handler()) + err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) if err != nil { - logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf(message, err.Error()), - Severity: logging.MINOR, - ErrorCode: 1109, + logger.LoggerAPK.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintln("Prometheus metrics server error:", err), + Severity: logging.MAJOR, + ErrorCode: 1110, }) - return true - } - return false -} - -// StartPrometheusMetricsServer initializes and starts the metrics server to expose metrics to prometheus. -func StartPrometheusMetricsServer(port int32, collectionInterval int32) { - done := make(chan struct{}) // Channel to indicate recordMetrics routine exit - - // Start the Prometheus metrics server - go func() { - http.Handle("/metrics", promhttp.HandlerFor(prometheusMetricRegistry, promhttp.HandlerOpts{})) - err := http.ListenAndServe(":"+strconv.Itoa(int(port)), nil) - if err != nil { - logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintln("Prometheus metrics server error:", err), - Severity: logging.MAJOR, - ErrorCode: 1110, - }) - } - }() - - for { - // Start the recordMetrics goroutine - go func() { - defer func() { - if r := recover(); r != nil { - logger.LoggerAPKOperator.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintln("recordMetrics goroutine exited with error:", r), - Severity: logging.MAJOR, - ErrorCode: 1111, - }) - } - }() - recordMetrics(collectionInterval) - done <- struct{}{} // Signal that the goroutine has completed - }() - - // Wait for the previous recordMetrics goroutine to complete - <-done - - // Log and restart the goroutine - logger.LoggerAPKOperator.Info("Restarting recordMetrics goroutine...") - time.Sleep(3 * time.Second) } } diff --git a/common-go-libs/go.mod b/common-go-libs/go.mod index 37ab6563a..fcb0a6169 100644 --- a/common-go-libs/go.mod +++ b/common-go-libs/go.mod @@ -21,6 +21,16 @@ require ( sigs.k8s.io/gateway-api v0.7.1 ) +require ( + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect +) + require ( github.com/agnivade/levenshtein v1.1.1 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -55,18 +65,19 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.17.0 // indirect + github.com/prometheus/client_golang v1.17.0 github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/sergi/go-diff v1.3.1 // indirect + github.com/shirou/gopsutil/v3 v3.24.2 github.com/spf13/pflag v1.0.5 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.13.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.17.0 // indirect golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect diff --git a/common-go-libs/go.sum b/common-go-libs/go.sum index aedc921d5..9db5ea8a8 100644 --- a/common-go-libs/go.sum +++ b/common-go-libs/go.sum @@ -43,6 +43,8 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo= github.com/go-logr/zapr v1.2.4/go.mod h1:FyHWQIzQORZ0QVE1BtVHv3cKtNLuXsbNLtpuhNapBOA= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= @@ -69,6 +71,7 @@ github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvR github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -95,6 +98,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= @@ -117,6 +122,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -131,6 +138,12 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/shirou/gopsutil/v3 v3.24.2 h1:kcR0erMbLg5/3LcInpw0X/rrPSqq4CDPyI6A6ZRC18Y= +github.com/shirou/gopsutil/v3 v3.24.2/go.mod h1:tSg/594BcA+8UdQU2XcW803GWYgdtauFFPgJCJKZlVk= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -148,6 +161,10 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqfU= github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74= github.com/wso2/apk/adapter v0.0.0-20231207051518-6dd728943082 h1:l+OdeDCNWPgie7L1fCjpfH04mAL3rFi4U+/idE8eduA= @@ -156,6 +173,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= @@ -207,17 +226,21 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= diff --git a/common-go-libs/pkg/metrics/metrics.go b/common-go-libs/pkg/metrics/metrics.go new file mode 100644 index 000000000..40abd594e --- /dev/null +++ b/common-go-libs/pkg/metrics/metrics.go @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Package metrics holds the implementation for exposing adapter metrics to prometheus +package metrics + +import ( + "fmt" + "runtime" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/host" + "github.com/shirou/gopsutil/v3/load" + "github.com/shirou/gopsutil/v3/mem" + "github.com/wso2/apk/adapter/pkg/logging" + logger "github.com/wso2/apk/common-go-libs/loggers" +) + +var ( + prometheusMetricRegistry = prometheus.NewRegistry() +) + +// Collector contains the descriptions of the custom metrics exposed +type Collector struct { + internalRouteCount *prometheus.Desc + hostInfo *prometheus.Desc + availableCPUs *prometheus.Desc + freePhysicalMemory *prometheus.Desc + totalVirtualMemory *prometheus.Desc + usedVirtualMemory *prometheus.Desc + systemCPULoad *prometheus.Desc + loadAvg *prometheus.Desc +} + +// CustomMetricsCollector contains the descriptions of the custom metrics exposed +func CustomMetricsCollector() *Collector { + return &Collector{ + internalRouteCount: prometheus.NewDesc( + "internal_route_count", + "Number of internal routes created.", + nil, nil, + ), + hostInfo: prometheus.NewDesc( + "host_info", + "Host Info", + []string{"os"}, nil, + ), + availableCPUs: prometheus.NewDesc( + "os_available_cpu_total", + "Number of available CPUs.", + nil, nil, + ), + freePhysicalMemory: prometheus.NewDesc( + "os_free_physical_memory_bytes", + "Amount of free physical memory.", + nil, nil, + ), + totalVirtualMemory: prometheus.NewDesc( + "os_total_virtual_memory_bytes", + "Amount of total virtual memory.", + nil, nil, + ), + usedVirtualMemory: prometheus.NewDesc( + "os_used_virtual_memory_bytes", + "Amount of used virtual memory.", + nil, nil, + ), + systemCPULoad: prometheus.NewDesc( + "os_system_cpu_load_percentage", + "System-wide CPU usage as a percentage.", + nil, nil, + ), + loadAvg: prometheus.NewDesc( + "os_system_load_average", + "Current load of CPU in the host system for the last {x} minutes", + []string{"duration"}, nil, + ), + } +} + +// Describe sends all the descriptors of the metrics collected by this Collector +// to the provided channel. +func (collector *Collector) Describe(ch chan<- *prometheus.Desc) { + ch <- collector.internalRouteCount + ch <- collector.hostInfo + ch <- collector.availableCPUs + ch <- collector.freePhysicalMemory + ch <- collector.totalVirtualMemory + ch <- collector.usedVirtualMemory + ch <- collector.systemCPULoad + ch <- collector.loadAvg +} + +// Collect collects all the relevant Prometheus metrics. +func (collector *Collector) Collect(ch chan<- prometheus.Metric) { + + var hostInfoValue float64 + var availableCPUs float64 + var freePhysicalMemory float64 + var totalVirtualMemory float64 + var usedVirtualMemory float64 + var systemCPULoad float64 + + host, err := host.Info() + if handleError(err, "Failed to get host info") { + return + } + hostInfoValue = 1 + availableCPUs = float64(runtime.NumCPU()) + + v, err := mem.VirtualMemory() + if handleError(err, "Failed to read virtual memory metrics") { + return + } + freePhysicalMemory = float64(v.Free) + usedVirtualMemory = float64(v.Used) + totalVirtualMemory = float64(v.Total) + + percentages, err := cpu.Percent(0, false) + if handleError(err, "Failed to read cpu usage metrics") || len(percentages) == 0 { + return + } + totalPercentage := 0.0 + for _, p := range percentages { + totalPercentage += p + } + averagePercentage := totalPercentage / float64(len(percentages)) + systemCPULoad = averagePercentage + + avg, err := load.Avg() + if handleError(err, "Failed to read cpu load averages") { + return + } + + ch <- prometheus.MustNewConstMetric(collector.hostInfo, prometheus.GaugeValue, hostInfoValue, host.OS) + ch <- prometheus.MustNewConstMetric(collector.availableCPUs, prometheus.GaugeValue, availableCPUs) + ch <- prometheus.MustNewConstMetric(collector.freePhysicalMemory, prometheus.GaugeValue, freePhysicalMemory) + ch <- prometheus.MustNewConstMetric(collector.usedVirtualMemory, prometheus.GaugeValue, usedVirtualMemory) + ch <- prometheus.MustNewConstMetric(collector.totalVirtualMemory, prometheus.GaugeValue, totalVirtualMemory) + ch <- prometheus.MustNewConstMetric(collector.systemCPULoad, prometheus.GaugeValue, systemCPULoad) + ch <- prometheus.MustNewConstMetric(collector.loadAvg, prometheus.GaugeValue, avg.Load1, "1m") + ch <- prometheus.MustNewConstMetric(collector.loadAvg, prometheus.GaugeValue, avg.Load5, "5m") + ch <- prometheus.MustNewConstMetric(collector.loadAvg, prometheus.GaugeValue, avg.Load15, "15m") +} + +func init() { + // Register the Go collector with the registry + goCollector := collectors.NewGoCollector() + prometheusMetricRegistry.MustRegister(goCollector) +} + +func handleError(err error, message string) bool { + if err != nil { + logger.LoggerAPK.ErrorC(logging.ErrorDetails{ + Message: fmt.Sprintf(message, err.Error()), + Severity: logging.MINOR, + ErrorCode: 1109, + }) + return true + } + return false +} diff --git a/common-go-libs/pkg/metrics/types.go b/common-go-libs/pkg/metrics/types.go new file mode 100644 index 000000000..07761ebaf --- /dev/null +++ b/common-go-libs/pkg/metrics/types.go @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package metrics + +const ( + // PrometheusMetricType prometheus metric type + PrometheusMetricType = "prometheus" +) diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java index 42ae752ed..e4311e4c9 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/discovery/JWTIssuerDiscoveryClient.java @@ -162,9 +162,8 @@ public void onNext(DiscoveryResponse response) { } subscriptionDataStore.addJWTIssuers(v); }); - if (JMXUtils.isJMXMetricsEnabled()) { - ExtAuthMetrics.getInstance().recordJWTIssuerMetrics(jwtIssuers.size()); + ExtAuthMetrics.getInstance().recordJWTIssuerMetrics(SubscriptionDataHolder.getInstance().getTotalJWTIssuerCount()); } logger.info("Number of jwt issuers received : " + jwtIssuers.size()); ack(); diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataHolder.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataHolder.java index 4454ef588..c90bdcf14 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataHolder.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataHolder.java @@ -27,7 +27,8 @@ public class SubscriptionDataHolder { private static final SubscriptionDataHolder instance = new SubscriptionDataHolder(); - Map subscriptionDataStoreMap = new HashMap<>(); + Map subscriptionDataStoreMap = new HashMap<>(); + public static SubscriptionDataHolder getInstance() { return instance; } @@ -35,9 +36,27 @@ public static SubscriptionDataHolder getInstance() { public SubscriptionDataStore getSubscriptionDataStore(String organization) { return subscriptionDataStoreMap.get(organization); } + public SubscriptionDataStore initializeSubscriptionDataStore(String organization) { SubscriptionDataStore subscriptionDataStore = new SubscriptionDataStoreImpl(); - subscriptionDataStoreMap.put(organization,subscriptionDataStore); + subscriptionDataStoreMap.put(organization, subscriptionDataStore); return subscriptionDataStore; } + + public int getTotalSubscriptionCount() { + int totalSubCount = 0; + for (SubscriptionDataStore store : subscriptionDataStoreMap.values()) { + totalSubCount += store.getSubscriptionCount(); + } + return totalSubCount; + } + + public int getTotalJWTIssuerCount() { + int totalJWTIssuerCount = 0; + for (SubscriptionDataStore store : subscriptionDataStoreMap.values()) { + totalJWTIssuerCount += store.getJWTIssuerCount(); + } + return totalJWTIssuerCount; + } + } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStore.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStore.java index 33be66ea2..3fca55d2d 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStore.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStore.java @@ -51,7 +51,6 @@ public interface SubscriptionDataStore { void addApplications(List applicationList); - void addApplicationKeyMappings( List applicationKeyMappingList); @@ -73,7 +72,7 @@ void addApplicationKeyMappings( * @return ApplicationKeyMapping which match the given parameters */ ApplicationKeyMapping getMatchingApplicationKeyMapping(String applicationIdentifier, String keyType, - String securityScheme, String envType); + String securityScheme, String envType); /** * Filter the applications map based on the provided parameters. @@ -108,11 +107,13 @@ ApplicationKeyMapping getMatchingApplicationKeyMapping(String applicationIdentif void addApplicationMapping(org.wso2.apk.enforcer.discovery.subscription.ApplicationMapping applicationMapping); - void addApplicationKeyMapping(org.wso2.apk.enforcer.discovery.subscription.ApplicationKeyMapping applicationKeyMapping); + void addApplicationKeyMapping( + org.wso2.apk.enforcer.discovery.subscription.ApplicationKeyMapping applicationKeyMapping); void removeApplicationMapping(org.wso2.apk.enforcer.discovery.subscription.ApplicationMapping applicationMapping); - void removeApplicationKeyMapping(org.wso2.apk.enforcer.discovery.subscription.ApplicationKeyMapping applicationKeyMapping); + void removeApplicationKeyMapping( + org.wso2.apk.enforcer.discovery.subscription.ApplicationKeyMapping applicationKeyMapping); void removeSubscription(org.wso2.apk.enforcer.discovery.subscription.Subscription subscription); @@ -120,4 +121,7 @@ ApplicationKeyMapping getMatchingApplicationKeyMapping(String applicationIdentif public void addApplicationMappings(List applicationMappingList); + int getSubscriptionCount(); + + int getJWTIssuerCount(); } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreImpl.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreImpl.java index 33c132e65..04eaf413c 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreImpl.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreImpl.java @@ -370,6 +370,7 @@ public void removeApplicationKeyMapping(org.wso2.apk.enforcer.discovery.subscrip public void removeSubscription(org.wso2.apk.enforcer.discovery.subscription.Subscription subscription) { subscriptionMap.remove(subscription.getUuid()); + } @Override @@ -398,4 +399,16 @@ private String getMapKey(String environment, String issuer) { return environment + DELEM_PERIOD + issuer; } + @Override + public int getSubscriptionCount() { + + return subscriptionMap.size(); + } + + @Override + public int getJWTIssuerCount() { + + return jwtValidatorMap.size(); + } + } diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java index 6c4905201..de2aa497d 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/subscription/SubscriptionDataStoreUtil.java @@ -160,7 +160,7 @@ private static void loadSubscriptions() { SubscriptionListDto subscriptions = subscriptionValidationDataRetrievalRestClient.getAllSubscriptions(); List list = subscriptions.getList(); if (JMXUtils.isJMXMetricsEnabled()) { - ExtAuthMetrics.getInstance().recordSubscriptionMetrics(list.size()); + ExtAuthMetrics.getInstance().recordSubscriptionMetrics(SubscriptionDataHolder.getInstance().getTotalSubscriptionCount()); } Map> orgWizeMAp = new HashMap<>(); for (SubscriptionDto subscriptionDto : list) { @@ -193,6 +193,9 @@ public static void addSubscription(Subscription subscription) { SubscriptionDataStore subscriptionDataStore = getSubscriptionDataStore(subscription.getOrganization()); subscriptionDataStore.addSubscription(subscription); + if (JMXUtils.isJMXMetricsEnabled()) { + ExtAuthMetrics.getInstance().recordSubscriptionMetrics(SubscriptionDataHolder.getInstance().getTotalSubscriptionCount()); + } } @@ -245,8 +248,10 @@ public static void removeApplicationKeyMapping(ApplicationKeyMapping application public static void removeSubscription(Subscription subscription) { SubscriptionDataStore subscriptionDataStore = getSubscriptionDataStore(subscription.getOrganization()); - subscriptionDataStore.removeSubscription(subscription); + if (JMXUtils.isJMXMetricsEnabled()) { + ExtAuthMetrics.getInstance().recordSubscriptionMetrics(SubscriptionDataHolder.getInstance().getTotalSubscriptionCount()); + } } diff --git a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml index ad7d5adb8..8da6a1fd7 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml @@ -10,6 +10,12 @@ data: {{- if and .Values.wso2.apk.dp.environment .Values.wso2.apk.dp.environment.name }} environment = "{{ .Values.wso2.apk.dp.environment.name }}" {{- end }} + {{if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + [commoncontroller.metrics] + enabled = {{.Values.wso2.apk.metrics.enabled}} + type = "{{.Values.wso2.apk.metrics.type| default "prometheus" }}" + port = 18010 + {{ end}} [commoncontroller.server] label = "ratelimiter" {{ if and .Values.wso2.apk.dp.commonController.configs .Values.wso2.apk.dp.commonController.configs.apiNamespaces }} diff --git a/helm-charts/templates/data-plane/gateway-components/log-conf.yaml b/helm-charts/templates/data-plane/gateway-components/log-conf.yaml index 7b775168b..2fc6b24fd 100644 --- a/helm-charts/templates/data-plane/gateway-components/log-conf.yaml +++ b/helm-charts/templates/data-plane/gateway-components/log-conf.yaml @@ -14,6 +14,12 @@ data: [adapter.operator] namespaces = [{{ include "commaJoinedQuotedList" .Values.wso2.apk.dp.adapter.configs.apiNamespaces}}] {{ end}} + {{if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} + [adapter.metrics] + enabled = {{.Values.wso2.apk.metrics.enabled}} + type = "{{.Values.wso2.apk.metrics.type| default "prometheus" }}" + port = 18006 + {{ end}} {{ if and .Values.wso2.apk.dp.gatewayRuntime.deployment .Values.wso2.apk.dp.gatewayRuntime.deployment.router .Values.wso2.apk.dp.gatewayRuntime.deployment.router.configs }} [router] diff --git a/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml b/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml index 5821cb0c1..a56500cd5 100644 --- a/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml +++ b/helm-charts/templates/data-plane/ratelimiter/ratelimiter-deployment.yaml @@ -35,7 +35,7 @@ spec: automountServiceAccountToken: false serviceAccountName: {{ .Values.wso2.apk.auth.serviceAccountName }} containers: - {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }} + {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd }} - name: statsd image: {{ .Values.wso2.apk.metrics.statsd.image.repository }}:{{ .Values.wso2.apk.metrics.statsd.image.tag }} imagePullPolicy: {{ .Values.wso2.apk.metrics.statsd.imagePullPolicy }} @@ -59,14 +59,17 @@ spec: value: "0.0.0.0" - name: PORT value: "8090" + {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd}} - name: USE_STATSD - value: "{{ and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }}" - {{if and .Values.wso2.apk.metrics.enabled .Values.wso2.apk.metrics.statsd.enabled }} + value: "true" - name: STATSD_HOST value: "0.0.0.0" - name: STATSD_PORT value: "9125" - {{- end}} + {{ else }} + - name: USE_STATSD + value: "false" + {{ end }} - name: LOG_LEVEL value: "DEBUG" - name: LIMIT_RESPONSE_HEADERS_ENABLED diff --git a/helm-charts/values.yaml b/helm-charts/values.yaml index 4f709376a..bbc801126 100644 --- a/helm-charts/values.yaml +++ b/helm-charts/values.yaml @@ -255,7 +255,6 @@ wso2: # configDSBalHost: 0.0.0.0 # idpDSBalHost: 0.0.0.0 # statsd: - # enabled: true # image: # repository: prom/statsd-exporter # tag: v0.26.0 diff --git a/helm-charts/values.yaml.template b/helm-charts/values.yaml.template index 9c0f1418c..550602951 100644 --- a/helm-charts/values.yaml.template +++ b/helm-charts/values.yaml.template @@ -601,7 +601,6 @@ wso2: # idpDSBalHost: 0.0.0.0 # -- Statsd is required to expose metrics from ratelimiter # statsd: - # enabled: true # image: # repository: prom/statsd-exporter # tag: v0.26.0 From 287c2c3e180e1a24841352fafff45545ba876927 Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 28 Feb 2024 10:27:21 +0530 Subject: [PATCH 21/24] Watch for CM and secrets in token issuer controller --- .../controllers/dp/tokenissuer_controller.go | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/adapter/internal/operator/controllers/dp/tokenissuer_controller.go b/adapter/internal/operator/controllers/dp/tokenissuer_controller.go index cc0708136..e402786dd 100644 --- a/adapter/internal/operator/controllers/dp/tokenissuer_controller.go +++ b/adapter/internal/operator/controllers/dp/tokenissuer_controller.go @@ -21,6 +21,7 @@ import ( "context" "encoding/json" + "github.com/wso2/apk/adapter/config" "github.com/wso2/apk/adapter/internal/discovery/xds" "github.com/wso2/apk/adapter/internal/loggers" "github.com/wso2/apk/adapter/internal/operator/constants" @@ -38,6 +39,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/source" + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "k8s.io/apimachinery/pkg/fields" ) const ( @@ -102,11 +106,84 @@ func NewTokenIssuerReconciler(mgr manager.Manager) error { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2656, logging.BLOCKER, "Error watching TokenIssuer resources: %v", err.Error())) return err } + conf := config.ReadConfigs() + predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.Adapter.Operator.Namespaces))} + + + if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.ConfigMap{}), handler.EnqueueRequestsFromMapFunc(r.populateTokenReconcileRequestsForConfigMap), + predicates...); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2644, logging.BLOCKER, "Error watching ConfigMap resources: %v", err)) + return err + } + + if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.Secret{}), handler.EnqueueRequestsFromMapFunc(r.populateTokenReconcileRequestsForSecret), + predicates...); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2645, logging.BLOCKER, "Error watching Secret resources: %v", err)) + return err + } loggers.LoggerAPKOperator.Debug("TokenIssuer Controller successfully started. Watching TokenIssuer Objects...") return nil } +func (r *TokenssuerReconciler) populateTokenReconcileRequestsForConfigMap(ctx context.Context, obj k8client.Object) []reconcile.Request { + configMap, ok := obj.(*corev1.ConfigMap) + if !ok { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, + "Unexpected object type, bypassing reconciliation: %v", configMap)) + return []reconcile.Request{} + } + tokenIssuerList := &dpv1alpha1.TokenIssuerList{} + err := r.client.List(ctx, tokenIssuerList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(configmapIssuerIndex, utils.NamespacedName(configMap).String()), + }) + requests := []reconcile.Request{} + if err == nil && len(tokenIssuerList.Items) > 0 { + + for _, tokenIssuer := range tokenIssuerList.Items { + req := reconcile.Request{ + NamespacedName: types.NamespacedName{ + Name: tokenIssuer.Name, + Namespace: tokenIssuer.Namespace}, + } + requests = append(requests, req) + loggers.LoggerAPKOperator.Infof("Adding reconcile request for TokenIssuer: %s/%s due to configmap change: %v", + tokenIssuer.Namespace, tokenIssuer.Name, utils.NamespacedName(configMap).String()) + } + return requests + } + return requests +} + +func (r *TokenssuerReconciler) populateTokenReconcileRequestsForSecret(ctx context.Context, obj k8client.Object) []reconcile.Request { + secret, ok := obj.(*corev1.Secret) + if !ok { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2622, logging.TRIVIAL, + "Unexpected object type, bypassing reconciliation: %v", secret)) + return []reconcile.Request{} + } + tokenIssuerList := &dpv1alpha1.TokenIssuerList{} + err := r.client.List(ctx, tokenIssuerList, &k8client.ListOptions{ + FieldSelector: fields.OneTermEqualSelector(secretTokenIssuerIndex, utils.NamespacedName(secret).String()), + }) + requests := []reconcile.Request{} + if err == nil && len(tokenIssuerList.Items) > 0 { + + for _, tokenIssuer := range tokenIssuerList.Items { + req := reconcile.Request{ + NamespacedName: types.NamespacedName{ + Name: tokenIssuer.Name, + Namespace: tokenIssuer.Namespace}, + } + requests = append(requests, req) + loggers.LoggerAPKOperator.Infof("Adding reconcile request for TokenIssuer: %s/%s due to secret change: %v", + tokenIssuer.Namespace, tokenIssuer.Name, utils.NamespacedName(secret).String()) + } + return requests + } + return requests +} + // addTokenIssuerIndexes adds indexers related to Gateways func addTokenIssuerIndexes(ctx context.Context, mgr manager.Manager) error { From 923f35b3e2d5d863988f27f48a0d31c50aa7b04d Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 6 Mar 2024 10:10:46 +0530 Subject: [PATCH 22/24] Add predicates to tokenissuer watch --- .../operator/controllers/dp/tokenissuer_controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adapter/internal/operator/controllers/dp/tokenissuer_controller.go b/adapter/internal/operator/controllers/dp/tokenissuer_controller.go index e402786dd..7f46e52ef 100644 --- a/adapter/internal/operator/controllers/dp/tokenissuer_controller.go +++ b/adapter/internal/operator/controllers/dp/tokenissuer_controller.go @@ -101,14 +101,14 @@ func NewTokenIssuerReconciler(mgr manager.Manager) error { return err } + conf := config.ReadConfigs() + predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.Adapter.Operator.Namespaces))} + if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha1.TokenIssuer{}), &handler.EnqueueRequestForObject{}, - predicate.NewPredicateFuncs(utils.FilterByNamespaces([]string{utils.GetOperatorPodNamespace()}))); err != nil { + predicates...); err != nil { loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2656, logging.BLOCKER, "Error watching TokenIssuer resources: %v", err.Error())) return err } - conf := config.ReadConfigs() - predicates := []predicate.Predicate{predicate.NewPredicateFuncs(utils.FilterByNamespaces(conf.Adapter.Operator.Namespaces))} - if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.ConfigMap{}), handler.EnqueueRequestsFromMapFunc(r.populateTokenReconcileRequestsForConfigMap), predicates...); err != nil { From c4be1eda38f049712621abce3a5f6647f2540fcc Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 6 Mar 2024 11:44:24 +0530 Subject: [PATCH 23/24] Revert "Test api resource modifications" --- .../modifyAPI/aNewResourceAddedAPI.yaml | 31 ------------ .../modifyAPI/aResourceRemovedAPI.yaml | 27 ----------- .../apk-confs/modifyAPI/originalAPI.yaml | 27 ----------- .../resources/tests/api/ModifyAPITest.feature | 48 ------------------- 4 files changed, 133 deletions(-) delete mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml delete mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml delete mode 100644 test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml delete mode 100644 test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml deleted file mode 100644 index ebe29160d..000000000 --- a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: "EmployeeServiceAPI" -basePath: "/test" -version: "3.14" -type: "REST" -defaultVersion: false -id: "modify-api-test" -endpointConfigurations: - production: - endpoint: "http://backend:80/anything" -operations: - - target: "/employee" - verb: "GET" - secured: true - scopes: [] - - target: "/employee1" - verb: "GET" - secured: true - scopes: [] - - target: "/employee" - verb: "POST" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "PUT" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "DELETE" - secured: true - scopes: [] diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml deleted file mode 100644 index e6fdd91a0..000000000 --- a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: "EmployeeServiceAPI" -basePath: "/test" -version: "3.14" -type: "REST" -defaultVersion: false -id: "modify-api-test" -endpointConfigurations: - production: - endpoint: "http://backend:80/anything" -operations: - - target: "/employee1" - verb: "GET" - secured: true - scopes: [] - - target: "/employee" - verb: "POST" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "PUT" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "DELETE" - secured: true - scopes: [] diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml deleted file mode 100644 index 35a766609..000000000 --- a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/modifyAPI/originalAPI.yaml +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: "EmployeeServiceAPI" -basePath: "/test" -version: "3.14" -type: "REST" -defaultVersion: false -id: "modify-api-test" -endpointConfigurations: - production: - endpoint: "http://backend:80/anything" -operations: - - target: "/employee" - verb: "GET" - secured: true - scopes: [] - - target: "/employee" - verb: "POST" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "PUT" - secured: true - scopes: [] - - target: "/employee/{employeeId}" - verb: "DELETE" - secured: true - scopes: [] diff --git a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature b/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature deleted file mode 100644 index 80e180ab0..000000000 --- a/test/cucumber-tests/src/test/resources/tests/api/ModifyAPITest.feature +++ /dev/null @@ -1,48 +0,0 @@ -Feature: API Deployment and invocation - Scenario: Deploying an API and basic http method invocations - Given The system is ready - And I have a valid subscription - When I use the APK Conf file "artifacts/apk-confs/modifyAPI/originalAPI.yaml" - And the definition file "artifacts/definitions/employees_api.json" - And make the API deployment request - Then the response status code should be 200 - Then I set headers - |Authorization|bearer ${accessToken}| - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" - And I eventually receive 200 response code, not accepting - |429| - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" - And the response status code should be 404 - When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aNewResourceAddedAPI.yaml" - And the definition file "artifacts/definitions/employees_api.json" - And make the API deployment request - Then the response status code should be 200 - Then I set headers - | Authorization | bearer ${accessToken} | - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" - And I eventually receive 200 response code, not accepting - | 429 | - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" - And the response status code should be 200 - When I use the APK Conf file "artifacts/apk-confs/modifyAPI/aResourceRemovedAPI.yaml" - And the definition file "artifacts/definitions/employees_api.json" - And make the API deployment request - Then the response status code should be 200 - Then I set headers - | Authorization | bearer ${accessToken} | - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee/" with body "" - And I eventually receive 404 response code, not accepting - | 429 | - And I send "GET" request to "https://default.gw.wso2.com:9095/test/3.14/employee1/" with body "" - And the response status code should be 200 - - Scenario Outline: Undeploy API - Given The system is ready - And I have a valid subscription - When I undeploy the API whose ID is "" - Then the response status code should be - - Examples: - | apiID | expectedStatusCode | - | modify-api-test | 202 | - From 826c877f2a3a536cec1ff675ee46337c67e8944d Mon Sep 17 00:00:00 2001 From: sgayangi Date: Wed, 6 Mar 2024 15:29:57 +0530 Subject: [PATCH 24/24] Update ports used for Prometheus --- common-controller/internal/config/default_config.go | 2 +- .../data-plane/config-deployer/config-ds-configmap.yaml | 2 +- .../data-plane/config-deployer/config-ds-deployment.yaml | 4 ++-- .../common-controller/common-controller-deployment.yaml | 2 +- .../data-plane/gateway-components/common-log-conf.yaml | 2 +- .../gateway-runtime/gateway-runtime-deployment.yaml | 4 ++-- helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml | 2 +- helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml | 4 ++-- idp/idp-domain-service/build.gradle | 2 +- idp/idp-domain-service/docker/build.gradle | 2 +- idp/idp-domain-service/docker/idp/idp.sh | 2 +- .../config-deployer-service/docker/config-deployer/config.sh | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common-controller/internal/config/default_config.go b/common-controller/internal/config/default_config.go index 396ec2b16..40971fea6 100644 --- a/common-controller/internal/config/default_config.go +++ b/common-controller/internal/config/default_config.go @@ -46,7 +46,7 @@ var defaultConfig = &Config{ Metrics: metrics{ Enabled: false, Type: "prometheus", - Port: 18010, + Port: 18006, }, }, } diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml index 1f6c3f6f3..bf2f22fb3 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-configmap.yaml @@ -31,7 +31,7 @@ data: metricsEnabled=true metricsReporter="prometheus" [ballerinax.prometheus] - port=18008 + port=18006 {{if .Values.wso2.apk.metrics.configDSBalHost}} host="{{ .Values.wso2.apk.metrics.configDSBalHost}}" {{else}} diff --git a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml index e4d520600..27d71680b 100644 --- a/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml +++ b/helm-charts/templates/data-plane/config-deployer/config-ds-deployment.yaml @@ -43,9 +43,9 @@ spec: - containerPort: 9443 protocol: "TCP" {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - containerPort: 18008 + - containerPort: 18006 protocol: "TCP" - - containerPort: 18009 + - containerPort: 18007 protocol: "TCP" {{ end }} readinessProbe: diff --git a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml index 133cd8441..eead36fcc 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-controller/common-controller-deployment.yaml @@ -49,7 +49,7 @@ spec: - containerPort: 18003 protocol: TCP {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - containerPort: 18010 + - containerPort: 18006 protocol: "TCP" {{ end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.commonController.deployment.resources | indent 10 }} diff --git a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml index 8da6a1fd7..cff5c7f04 100644 --- a/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml +++ b/helm-charts/templates/data-plane/gateway-components/common-log-conf.yaml @@ -14,7 +14,7 @@ data: [commoncontroller.metrics] enabled = {{.Values.wso2.apk.metrics.enabled}} type = "{{.Values.wso2.apk.metrics.type| default "prometheus" }}" - port = 18010 + port = 18006 {{ end}} [commoncontroller.server] label = "ratelimiter" diff --git a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml index e9e696a1f..bf2883c1e 100644 --- a/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml +++ b/helm-charts/templates/data-plane/gateway-components/gateway-runtime/gateway-runtime-deployment.yaml @@ -53,7 +53,7 @@ spec: - containerPort: 18002 protocol: "TCP" {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled}} - - containerPort: 18007 + - containerPort: 18006 protocol: "TCP" {{- end }} {{ include "apk-helm.deployment.resources" .Values.wso2.apk.dp.gatewayRuntime.deployment.enforcer.resources | indent 10 }} @@ -92,7 +92,7 @@ spec: value: admin - name: JAVA_OPTS {{- if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config-enforcer.yml + value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 -Dapk.jmx.metrics.enabled=true -javaagent:/home/wso2/lib/jmx_prometheus_javaagent-0.20.0.jar=18006:/tmp/metrics/prometheus-jmx-config-enforcer.yml {{- else }} value: -Dhttpclient.hostnameVerifier=AllowAll -Xms512m -Xmx512m -XX:MaxRAMFraction=2 {{- end }} diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml index d33cea731..a97122786 100644 --- a/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml +++ b/helm-charts/templates/idp/idp-ds/idp-ds-configmap.yaml @@ -31,7 +31,7 @@ data: metricsEnabled=true metricsReporter="prometheus" [ballerinax.prometheus] - port=18011 + port=18006 {{if .Values.wso2.apk.metrics.idpDSBalHost}} host="{{ .Values.wso2.apk.metrics.idpDSBalHost}}" {{else}} diff --git a/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml b/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml index 079209c48..466b4da4a 100644 --- a/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml +++ b/helm-charts/templates/idp/idp-ds/idp-ds-deployment.yaml @@ -52,9 +52,9 @@ spec: - containerPort: 9443 protocol: "TCP" {{ if and .Values.wso2.apk.metrics .Values.wso2.apk.metrics.enabled }} - - containerPort: 18011 + - containerPort: 18006 protocol: "TCP" - - containerPort: 18012 + - containerPort: 18007 protocol: "TCP" {{ end }} readinessProbe: diff --git a/idp/idp-domain-service/build.gradle b/idp/idp-domain-service/build.gradle index 612190f25..cfe38cb8e 100644 --- a/idp/idp-domain-service/build.gradle +++ b/idp/idp-domain-service/build.gradle @@ -36,7 +36,7 @@ release { unSnapshotVersion.finalizedBy ":ballerina:commit_toml_files" afterReleaseBuild.dependsOn ":docker:docker_push" task build{ - dependsOn("docker:build") + dependsOn("docker:buildDockerImage") } build.configure { dependsOn(":docker:build") diff --git a/idp/idp-domain-service/docker/build.gradle b/idp/idp-domain-service/docker/build.gradle index 03c2890c1..25d8b11f0 100644 --- a/idp/idp-domain-service/docker/build.gradle +++ b/idp/idp-domain-service/docker/build.gradle @@ -59,4 +59,4 @@ task buildDockerImage{ buildDockerImage.configure{ mustRunAfter(":ballerina:build") dependsOn(":ballerina:build") - } \ No newline at end of file +} \ No newline at end of file diff --git a/idp/idp-domain-service/docker/idp/idp.sh b/idp/idp-domain-service/docker/idp/idp.sh index 03cb90968..dc8c6e8bc 100755 --- a/idp/idp-domain-service/docker/idp/idp.sh +++ b/idp/idp-domain-service/docker/idp/idp.sh @@ -102,6 +102,6 @@ $JAVACMD \ $JAVA_OPTS \ -classpath "$CLASSPATH" \ -Djava.io.tmpdir="$IDP_HOME/tmp" \ - -javaagent:/home/wso2apk/jmx_prometheus_javaagent-0.20.0.jar=18012:/tmp/metrics/prometheus-jmx-config-idpds.yml \ + -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config-idpds.yml \ -jar idp_domain_service.jar $* status=$? diff --git a/runtime/config-deployer-service/docker/config-deployer/config.sh b/runtime/config-deployer-service/docker/config-deployer/config.sh index ccc254e6a..3d9253f7e 100644 --- a/runtime/config-deployer-service/docker/config-deployer/config.sh +++ b/runtime/config-deployer-service/docker/config-deployer/config.sh @@ -103,6 +103,6 @@ $JAVACMD \ $JAVA_OPTS \ -classpath "$CLASSPATH" \ -Djava.io.tmpdir="$RUNTIME_HOME/tmp" \ - -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18009:/tmp/metrics/prometheus-jmx-config-configds.yml \ + -javaagent:/home/wso2apk/lib/jmx_prometheus_javaagent-0.20.0.jar=18007:/tmp/metrics/prometheus-jmx-config-configds.yml \ -jar config_deployer_service.jar $* status=$?