The skip managers for web applications

Depending on your context and your objectives, you may want to skip some data.

This can be done in writing classes that implements the interface org.appspy.perf.servlet.skip.SkipManager.

The skip managers are configured in the webapp configuration file (appspy-webapp-${appspy-mode}.xml).

Every skip manager have to be declared in this file and added to the list "skipManagers" of the bean "skipManager".

There are some implementations that comes with Appspy :

  • org.appspy.perf.servlet.skip.HeaderBasedSkipManager : This implementation can be used to skip the data collection when a header value corresponds to a regular expression.
            <bean id="skipManager" class="org.appspy.perf.servlet.skip.CompositeSkipManager">
                    <property name="skipManagers">
                            <list>
                                    <ref bean="headerBasedSkipManager"/>
                                    ...
                            </list>
                    </property>
            </bean>
    
            <bean id="headerBasedSkipManager" class="org.appspy.perf.servlet.skip.HeaderBasedSkipManager">
                    <property name="headerName" value="User-Agent"/>
                    <property name="headerValuePattern" value=".*Health-Check.*"/>
            </bean>
  • org.appspy.perf.servlet.skip.URLBasedSkipManager : This implementation can be used to skip the data collection when the URL corresponds to a regular expression.
            <bean id="skipManager" class="org.appspy.perf.servlet.skip.CompositeSkipManager">
                    <property name="skipManagers">
                            <list>
                                    ...
                                    <ref bean="urlBasedSkipManager"/>
                                    ...
                            </list>
                    </property>
            </bean>
    
            <bean id="urlBasedSkipManager" class="org.appspy.perf.servlet.skip.URLBasedSkipManager">
                    <property name="URLPattern" value="(.*\.gif)|(.*\.jpg)|(.*\.png)|(.*\.css)|(.*\.js)"/>
            </bean>
  • org.appspy.perf.servlet.skip.SessionSamplingSkipManager : This implementation can be used to skip the data collection based on sampling. If the session is elected, all the hits corresponding to this session will be collected.
            <bean id="skipManager" class="org.appspy.perf.servlet.skip.CompositeSkipManager">
                    <property name="skipManagers">
                            <list>
                                    ...
                                    <ref bean="sessionSamplingSkipManager"/>
                                    ...
                            </list>
                    </property>
            </bean>
    
            <bean id="sessionSamplingSkipManager" class="org.appspy.perf.servlet.skip.SessionSamplingSkipManager">
                    <property name="sampling" value="${collectionSampling}"/>
            </bean>
  • org.appspy.perf.servlet.skip.NoSessionSamplingSkipManager : This implementation can be used to skip the data collection based on sampling. It is used only when no user session has been created.
            <bean id="skipManager" class="org.appspy.perf.servlet.skip.CompositeSkipManager">
                    <property name="skipManagers">
                            <list>
                                    ...
                                    <ref bean="noSessionSamplingSkipManager"/>
                                    ...
                            </list>
                    </property>
            </bean>
    
            <bean id="noSessionSamplingSkipManager" class="org.appspy.perf.servlet.skip.NoSessionSamplingSkipManager">
                    <property name="sampling" value="${collectionSampling}"/>
            </bean>

Create your own data provider

For different reasons you may need to create your own skip manager. This can be achieved by implementing the interface org.appspy.perf.servlet.skip.SkipManager :

public interface SkipManager
{
        public static final int UNDEFINED = 0;
        public static final int SKIP = 1;
        public static final int COLLECT = 2;
        
        public int skipRequest(ServletRequest req, ServletResponse res, ServletContext sc);
}

If this method return SKIP or COLLECT, the other SkipManagers won't be asked. Implementation example (URLBasedSkipManager) : the value SKIP is returned only if the URL matches the regular expression, otherwise UNDEFINED is returned.

        public int skipRequest(ServletRequest req, ServletResponse res, ServletContext sc)
        {
                int skip = SkipManager.UNDEFINED;

                if (req instanceof HttpServletRequest)
                {
                        HttpServletRequest request = (HttpServletRequest) req;
                        
                        try
                        {
                                String contextPath = request.getContextPath();
                                String requestURI = request.getRequestURI();
                                String result = requestURI.replaceFirst(contextPath, "");
                                
                                if (result.matches(mURLPattern))
                                {
                                        if (sLog.isDebugEnabled())
                                        {
                                                sLog.debug("Skipping this request : " + result + " matches the URLPattern : " + mURLPattern);
                                        }
                                        skip = SkipManager.SKIP;
                                }
                        }
                        catch (Exception ex)
                        {
                                sLog.warn(ex.getMessage(), ex);
                        }
                }

                return skip;
        }