Skip to content

Commit

Permalink
Update API method for GRPC analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
sgayangi committed Sep 18, 2024
1 parent 4d707a8 commit c840e78
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions adapter/internal/oasparser/model/adapter_internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoGRPCRouteCR(grpcRoute *gwap
if outputAuthScheme != nil {
authScheme = *outputAuthScheme
}
var apiPolicy *dpv1alpha2.APIPolicy
var apiPolicy *dpv1alpha3.APIPolicy
if outputAPIPolicy != nil {
apiPolicy = *outputAPIPolicy
}
Expand Down Expand Up @@ -1285,7 +1285,7 @@ func (adapterInternalAPI *AdapterInternalAPI) SetInfoGRPCRouteCR(grpcRoute *gwap
resourcePath := adapterInternalAPI.GetXWso2Basepath() + "." + *match.Method.Service + "/" + *match.Method.Method
endPoints = append(endPoints, GetEndpoints(backendName, resourceParams.BackendMapping)...)
resource := &Resource{path: resourcePath, pathMatchType: "Exact",
methods: []*Operation{{iD: uuid.New().String(), method: "post", policies: policies,
methods: []*Operation{{iD: uuid.New().String(), method: "GRPC", policies: policies,
auth: apiAuth, rateLimitPolicy: parseRateLimitPolicyToInternal(resourceRatelimitPolicy), scopes: scopes}},
iD: uuid.New().String(),
}
Expand Down
2 changes: 1 addition & 1 deletion adapter/internal/operator/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func GetBackendJWT(ctx context.Context, client k8client.Client, namespace,

// GetAIProvider reads AIProvider when aiProviderReference is given
func GetAIProvider(ctx context.Context, client k8client.Client, namespace string,
aiProviderReference string, api *dpv1alpha2.API) *dpv1alpha3.AIProvider {
aiProviderReference string, api *dpv1beta1.API) *dpv1alpha3.AIProvider {
aiProvider := &dpv1alpha3.AIProvider{}
aiProviderRef := types.NamespacedName{
Namespace: namespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.wso2.apk.enforcer.commons.analytics.publishers.dto.Target;
import org.wso2.apk.enforcer.commons.analytics.publishers.impl.SuccessRequestDataPublisher;

import java.util.Objects;

/**
* Success request data collector.
*/
Expand Down Expand Up @@ -81,6 +83,9 @@ public void collectData() throws AnalyticsException {
}

event.setApi(api);
if (Objects.equals(api.getApiType(), "GRPC")) {
operation.setApiMethod("GRPC");
}
event.setOperation(operation);
event.setTarget(target);
event.setApplication(application);
Expand All @@ -91,7 +96,6 @@ public void collectData() throws AnalyticsException {
event.setUserAgentHeader(userAgent);
event.setUserName(userName);
event.setUserIp(userIp);

this.processor.publish(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ResourceConfig {
public enum HttpMethods {
GET("get"), POST("post"), PUT("put"), DELETE("delete"), HEAD("head"),
PATCH("patch"), OPTIONS("options"), QUERY("query"), MUTATION("mutation"),
SUBSCRIPTION("subscription");
SUBSCRIPTION("subscription"), GRPC("GRPC");

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public void handleFailureRequest(RequestContext requestContext) {
analyticsSpanScope = analyticsSpan.getSpan().makeCurrent();
Utils.setTag(analyticsSpan, APIConstants.LOG_TRACE_ID,
ThreadContext.get(APIConstants.LOG_TRACE_ID));

}
if (publisher == null) {
logger.error("Cannot publish the failure event as analytics publisher is null.",
Expand Down

0 comments on commit c840e78

Please sign in to comment.