Search in sources :

Example 1 with AnalyticsDataProvider

use of org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider in project carbon-apimgt by wso2.

the class SseApiHandler method isThrottled.

private boolean isThrottled(org.apache.axis2.context.MessageContext axisCtx, MessageContext synCtx) {
    AuthenticationContext authenticationContext = APISecurityUtils.getAuthenticationContext(synCtx);
    ThrottleInfo throttleInfo = getThrottlingInfo(authenticationContext, synCtx);
    boolean isThrottled = SseUtils.isRequestBlocked(authenticationContext, throttleInfo.getApiContext(), throttleInfo.getApiVersion(), authenticationContext.getUsername(), throttleInfo.getRemoteIp(), CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    if (!isThrottled) {
        // do throttling if request is not blocked by global conditions only
        isThrottled = SseUtils.isThrottled(throttleInfo.getSubscriberTenantDomain(), throttleInfo.getResourceLevelThrottleKey(), throttleInfo.getSubscriptionLevelThrottleKey(), throttleInfo.getApplicationLevelThrottleKey());
    }
    if (isThrottled) {
        handleThrottledOut(synCtx);
        return true;
    }
    if (APIUtil.isAnalyticsEnabled()) {
        AnalyticsDataProvider provider = new SseResponseEventDataProvider(synCtx);
        axisCtx.setProperty(SSE_ANALYTICS_INFO, provider);
    }
    return false;
}
Also used : SseResponseEventDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider) AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ThrottleInfo(org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.throttling.ThrottleInfo) AnalyticsDataProvider(org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider)

Example 2 with AnalyticsDataProvider

use of org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider in project carbon-apimgt by wso2.

the class WebSocketAnalyticsMetricsHandler method collectData.

private void collectData(ChannelHandlerContext ctx) {
    AnalyticsDataProvider provider = new WebSocketAnalyticsDataProvider(ctx);
    GenericRequestDataCollector collector = new GenericRequestDataCollector(provider);
    try {
        collector.collectData();
    } catch (AnalyticsException e) {
        log.error("Error Occurred when collecting analytics data", e);
    }
}
Also used : GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) AnalyticsException(org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException) AnalyticsDataProvider(org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider)

Example 3 with AnalyticsDataProvider

use of org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider in project carbon-apimgt by wso2.

the class AnalyticsMetricsHandler method handleResponseOutFlow.

@Override
public boolean handleResponseOutFlow(MessageContext messageContext) {
    if (messageContext.getPropertyKeySet().contains(InboundWebsocketConstants.WEBSOCKET_SUBSCRIBER_PATH)) {
        return true;
    }
    AnalyticsDataProvider provider;
    Object skipPublishMetrics = messageContext.getProperty(Constants.SKIP_DEFAULT_METRICS_PUBLISHING);
    if (skipPublishMetrics != null && (Boolean) skipPublishMetrics) {
        provider = new AsyncAnalyticsDataProvider(messageContext);
    } else {
        provider = new SynapseAnalyticsDataProvider(messageContext);
    }
    GenericRequestDataCollector dataCollector = new GenericRequestDataCollector(provider);
    try {
        dataCollector.collectData();
    } catch (Exception e) {
        log.error("Error Occurred when collecting data", e);
    }
    return true;
}
Also used : GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) AsyncAnalyticsDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider) AnalyticsDataProvider(org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider) AsyncAnalyticsDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider) AnalyticsException(org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException)

Aggregations

AnalyticsDataProvider (org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider)3 GenericRequestDataCollector (org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector)2 AnalyticsException (org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException)2 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)1 AsyncAnalyticsDataProvider (org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider)1 SseResponseEventDataProvider (org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider)1 ThrottleInfo (org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.throttling.ThrottleInfo)1