Skip to content

Commit

Permalink
Merge pull request #602 from Buddhima/parameter_for_enable_stats_glob…
Browse files Browse the repository at this point in the history
…ally

Parameter for enable stats globally for all artifacts
  • Loading branch information
Buddhima committed Jul 18, 2016
2 parents 2ce460a + 8d7a7de commit af95bb8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
Expand Up @@ -54,6 +54,11 @@ public static Integer reportEntryEvent(MessageContext messageContext, String com
AspectConfiguration aspectConfiguration, ComponentType componentType) {
boolean isCollectingStatistics = (aspectConfiguration != null && aspectConfiguration.isStatisticsEnable());

// Enable statistics, if user enabled for all artifacts
if (!isCollectingStatistics) {
isCollectingStatistics = isCollectingStatistics || RuntimeStatisticCollector.isCollectingAllStatistics();
}

boolean isCollectingTracing = false;
if (isCollectingProperties() || isCollectingPayloads()) {
isCollectingTracing = (aspectConfiguration != null && aspectConfiguration.isTracingEnabled());
Expand Down Expand Up @@ -93,7 +98,7 @@ public static Integer reportEntryEvent(MessageContext messageContext, String com
}

if (aspectConfiguration != null) {
statisticDataUnit.setIsIndividualStatisticCollected(aspectConfiguration.isStatisticsEnable());
statisticDataUnit.setIsIndividualStatisticCollected(isCollectingStatistics);
}
StatisticDataCollectionHelper.collectData(messageContext, true, isTracingEnabled, statisticDataUnit);

Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.synapse.aspects.flow.statistics.log.StatisticEventProcessor;
import org.apache.synapse.aspects.flow.statistics.log.templates.ParentReopenEvent;
import org.apache.synapse.aspects.flow.statistics.store.MessageDataStore;
import org.apache.synapse.aspects.flow.statistics.util.MediationFlowController;
import org.apache.synapse.aspects.flow.statistics.util.StatisticDataCollectionHelper;
import org.apache.synapse.aspects.flow.statistics.util.StatisticsConstants;
import org.apache.synapse.config.SynapseConfigUtils;
Expand Down Expand Up @@ -57,6 +58,11 @@ public abstract class RuntimeStatisticCollector {
*/
private static boolean isCollectingProperties;

/**
* Is collecting statistics of all artifacts
*/
private static boolean isCollectingAllStatistics;

/**
* Statistic event queue to hold statistic events.
*/
Expand Down Expand Up @@ -95,6 +101,9 @@ public static void init() {
log.debug("Property collecting is not enabled in \'synapse.properties\' file.");
}

isCollectingAllStatistics = Boolean.parseBoolean(SynapsePropertiesLoader.getPropertyValue(
StatisticsConstants.COLLECT_ALL_STATISTICS, String.valueOf(false)));

statisticEventQueue = new MessageDataStore(queueSize);
//Thread to consume queue and update data structures for publishing
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
Expand All @@ -109,7 +118,9 @@ public Thread newThread(Runnable r) {
SynapseConfigUtils.getGlobalTimeoutInterval() + SynapseConfigUtils.getTimeoutHandlerInterval() +
eventConsumerTime;
log.info("Statistics Entry Expiration time set to " + eventExpireTime + " milliseconds");

StatisticEventProcessor.initializeCleaningThread();
new MediationFlowController();
} else {
if (log.isDebugEnabled()) {
log.debug("Statistics is not enabled in \'synapse.properties\' file.");
Expand Down Expand Up @@ -181,7 +192,7 @@ public static boolean isStatisticsEnabled() {
* @return true if need to collect payloads.
*/
public static boolean isCollectingPayloads() {
return isStatisticsEnabled & isCollectingPayloads;
return isStatisticsEnabled && isCollectingPayloads;
}

/**
Expand All @@ -190,7 +201,24 @@ public static boolean isCollectingPayloads() {
* @return true if need to collect message-properties.
*/
public static boolean isCollectingProperties() {
return isStatisticsEnabled & isCollectingProperties;
return isStatisticsEnabled && isCollectingProperties;
}

/**
* Return whether collecting statistics for all artifacts is enabled (this also needs isStatisticsEnabled)
*
* @return true if need to collect statistics for all artifacts
*/
public static boolean isCollectingAllStatistics() {
return isStatisticsEnabled && isCollectingAllStatistics;
}

/**
* Allow external to alter state of collecting statistics for all artifacts, during runtime
*/
public static void setCollectingAllStatistics(boolean state) {
isCollectingAllStatistics = state;
log.info("Collecting statistics for all artifacts state changed to: " + state);
}

/**
Expand Down
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* <p/>
* WSO2 Inc. 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 org.apache.synapse.aspects.flow.statistics.util;

import org.apache.synapse.aspects.flow.statistics.collectors.RuntimeStatisticCollector;
import org.apache.synapse.commons.jmx.MBeanRegistrar;

public class MediationFlowController implements MediationFlowControllerMXBean {
public MediationFlowController() {
MBeanRegistrar.getInstance().registerMBean(this, "Mediation Flow Statistic Controller", "MediationFlowStatisticController");
}

@Override
public boolean setCollectingAllStatistics(boolean state) {
RuntimeStatisticCollector.setCollectingAllStatistics(state);
return true;
}
}
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* <p/>
* WSO2 Inc. 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 org.apache.synapse.aspects.flow.statistics.util;

public interface MediationFlowControllerMXBean {
public boolean setCollectingAllStatistics(boolean state);
}
Expand Up @@ -38,6 +38,11 @@ public class StatisticsConstants {
*/
public final static String COLLECT_MESSAGE_PROPERTIES = "mediation.flow.statistics.tracer.collect.properties";

/**
* Enable statistics collecting for all artifacts
*/
public final static String COLLECT_ALL_STATISTICS = "mediation.flow.statistics.collect.all";

/**
* Flow statistic queue size.
*/
Expand Down

0 comments on commit af95bb8

Please sign in to comment.