Search in sources :

Example 6 with PressureMeasureError

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

the class ShadowEsClientHolder method createShadowRestClient.

private static RestClient createShadowRestClient(RestClient target) {
    List<String> nodesAddressAsString = getNodesAddressAsString(target);
    ShadowEsServerConfig shadowEsServerConfig = findMatchShadowEsServerConfig(nodesAddressAsString);
    if (shadowEsServerConfig == null) {
        throw new PressureMeasureError(String.format("影子集群未配置,业务节点:%s", StringUtils.join(nodesAddressAsString, ",")));
    }
    RestClientDefinition restClientDefinition = RestClientDefinitionStrategy.match(target);
    return restClientDefinition.solve(target, shadowEsServerConfig);
}
Also used : ShadowEsServerConfig(com.pamirs.pradar.internal.config.ShadowEsServerConfig) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) RestClientDefinition(com.pamirs.attach.plugin.es.shadowserver.rest.definition.RestClientDefinition)

Example 7 with PressureMeasureError

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

the class WrapperRequest method readRequest.

private byte[] readRequest(HttpServletRequest request) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ServletInputStream in = request.getInputStream();
        byte[] data = new byte[1024];
        int len = 0;
        while ((len = in.read(data)) != -1) {
            bos.write(data, 0, len);
        }
        return bos.toByteArray();
    } catch (IOException e) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
        return null;
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 8 with PressureMeasureError

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

the class CacheAsMapInterceptor method getResult0.

@Override
protected Object getResult0(Advice advice) {
    /**
     * 压测状态为关闭,如果当前为压测流量则直接报错
     */
    if (!PradarSwitcher.isClusterTestEnabled()) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(PradarSwitcher.PRADAR_SWITCHER_OFF + ":" + AppNameUtils.appName());
        }
        return advice.getReturnObj();
    }
    boolean clusterTest = Pradar.isClusterTest();
    ConcurrentMap returnObj = (ConcurrentMap) advice.getReturnObj();
    Set<Map.Entry> set = returnObj.entrySet();
    ConcurrentMap concurrentMap = Maps.newConcurrentMap();
    for (Map.Entry o : set) {
        if (clusterTest && o.getKey() instanceof ClusterTestCacheWrapperKey) {
            concurrentMap.put(((ClusterTestCacheWrapperKey) o.getKey()).getKey(), o.getValue());
        } else if (!clusterTest && !(o.getKey() instanceof ClusterTestCacheWrapperKey)) {
            concurrentMap.put(o.getKey(), o.getValue());
        }
    }
    return concurrentMap;
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) ClusterTestCacheWrapperKey(com.pamirs.pradar.cache.ClusterTestCacheWrapperKey) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 9 with PressureMeasureError

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

the class CacheOperationInterceptor method getParameter0.

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

Example 10 with PressureMeasureError

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

the class AbstractTransportClientDefinition method addPtTransportAddress.

protected void addPtTransportAddress(TransportClient transportClient, ShadowEsServerConfig shadowEsServerConfig) {
    for (String performanceTestNode : shadowEsServerConfig.getPerformanceTestNodes()) {
        try {
            HostAndPort hostAndPort = new HostAndPort(performanceTestNode);
            transportClient.addTransportAddress(hostAndPort.toTransportAddress());
        } catch (UnknownHostException e) {
            throw new PressureMeasureError("影子sever nodes配置错误!", e);
        }
    }
}
Also used : HostAndPort(com.pamirs.attach.plugin.es.shadowserver.utils.HostAndPort) UnknownHostException(java.net.UnknownHostException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

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