Search in sources :

Example 86 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class TransportClientExecuteInterceptor method doShadowIndexInterceptor.

private CutOffResult doShadowIndexInterceptor(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args[1] == null) {
        return CutOffResult.PASSED;
    }
    RequestIndexRename requestIndexRename = RequestIndexRenameProvider.get(args[1]);
    if (requestIndexRename == null) {
        throw new PressureMeasureError("elasticsearch " + args[1].getClass().getName() + " is not supported");
    }
    requestIndexRename.reindex(args[1]);
    return CutOffResult.PASSED;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) RequestIndexRename(com.pamirs.attach.plugin.es.common.RequestIndexRename)

Example 87 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class TransportClientTraceInterceptor method check.

private void check(Object target, String methodName, Object[] args) {
    if (GlobalConfig.getInstance().isShadowEsServer()) {
        return;
    }
    RequestIndexRename requestIndexRename = RequestIndexRenameProvider.get(args[1]);
    Collection<String> indexs = new HashSet<String>(requestIndexRename.getIndex(args[1]));
    if (Pradar.isClusterTest()) {
        for (String index : indexs) {
            if (!Pradar.isClusterTestPrefix(index)) {
                /**
                 * 如果索引在白名单中,则不需要走
                 */
                if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
                    continue;
                }
                throw new PressureMeasureError("[error] forbidden pressurement into biz index. index = " + index);
            }
        }
    } else {
        for (String index : indexs) {
            if (Pradar.isClusterTestPrefix(index)) {
                logger.error("[error]  biz data into pressurement index.");
            }
        }
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) RequestIndexRename(com.pamirs.attach.plugin.es.common.RequestIndexRename) HashSet(java.util.HashSet)

Example 88 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class IndexRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    IndexRequest req = (IndexRequest) target;
    String index = req.index();
    /**
     * 如果在白名单中则不允许写
     */
    if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
        throw new PressureMeasureError("Cluster Test request can't write business index ! " + index);
    }
    if (!Pradar.isClusterTestPrefix(index)) {
        index = Pradar.addClusterTestPrefixLower(req.index());
    }
    req.index(index);
    return Arrays.asList(index);
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 89 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class IndicesAliasesRequestIndexRename method reindex0.

@Override
public List<String> reindex0(Object target) {
    IndicesAliasesRequest req = (IndicesAliasesRequest) target;
    final List<IndicesAliasesRequest.AliasActions> aliasActions = req.getAliasActions();
    List<String> indexes = new ArrayList<String>();
    for (int i = 0, len = aliasActions.size(); i < len; i++) {
        IndicesAliasesRequest.AliasActions aliasAction = aliasActions.get(i);
        String[] indices = aliasAction.indices();
        for (String index : indices) {
            /**
             * 如果在白名单中则不允许写
             */
            if (GlobalConfig.getInstance().getSearchWhiteList().contains(index)) {
                throw new PressureMeasureError("Cluster Test request can't refresh business index !");
            }
            if (!Pradar.isClusterTestPrefix(index)) {
                index = Pradar.addClusterTestPrefixLower(index);
                indices[i] = index;
            }
        }
        aliasAction.indices(indices);
        indexes.addAll(Arrays.asList(indices));
    }
    return indexes;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ArrayList(java.util.ArrayList) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)

Example 90 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.

the class CacheOperationGetAllResInterceptor method getParameter0.

@Override
protected Object[] getParameter0(Advice advice) throws Throwable {
    /**
     * 压测状态为关闭,如果当前为压测流量则直接报错
     */
    if (!PradarSwitcher.isClusterTestEnabled()) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(PradarSwitcher.PRADAR_SWITCHER_OFF + ":" + AppNameUtils.appName());
        }
        return advice.getParameterArray();
    }
    if (!Pradar.isClusterTest()) {
        // 非压测流量
        return advice.getParameterArray();
    }
    Object[] parameterArray = advice.getParameterArray();
    if (null == parameterArray || parameterArray.length == 0) {
        return advice.getParameterArray();
    }
    if (parameterArray[0] instanceof Map) {
        Map o = (Map) parameterArray[0];
        Set<Map.Entry> set = o.entrySet();
        LinkedHashMap<Object, Object> objectObjectLinkedHashMap = Maps.newLinkedHashMap();
        for (Map.Entry o1 : set) {
            if (o1.getKey() instanceof ClusterTestCacheWrapperKey) {
                objectObjectLinkedHashMap.put(((ClusterTestCacheWrapperKey) o1.getKey()).getKey(), o1.getValue());
            } else {
                objectObjectLinkedHashMap.put(o1.getKey(), o1.getValue());
            }
        }
        parameterArray[0] = objectObjectLinkedHashMap;
    } else if (parameterArray[0] instanceof Iterable) {
        Iterable<? extends Map.Entry> o = (Iterable) parameterArray[0];
        if (null != o) {
            ArrayList<? extends Map.Entry> objects = Lists.newArrayList();
            Iterator iterator = o.iterator();
            HashMap objectObjectHashMap = Maps.newHashMap();
            while (iterator.hasNext()) {
                Map.Entry next = (Map.Entry) iterator.next();
                Object key = next.getKey();
                if (key instanceof ClusterTestCacheWrapperKey) {
                    objectObjectHashMap.put(((ClusterTestCacheWrapperKey) key).getKey(), next.getValue());
                } else {
                    objectObjectHashMap.put(key, next.getValue());
                }
            }
            objects.addAll(objectObjectHashMap.entrySet());
            parameterArray[0] = objects;
        }
    }
    return parameterArray;
}
Also used : ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)150 PradarException (com.pamirs.pradar.exception.PradarException)34 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)14 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)13 ArrayList (java.util.ArrayList)13 Map (java.util.Map)11 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)8 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)8 HashMap (java.util.HashMap)8 MongoNamespace (com.mongodb.MongoNamespace)7 RequestIndexRename (com.pamirs.attach.plugin.es.common.RequestIndexRename)7 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)7 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)6 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)6 List (java.util.List)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)5 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)5