com.alibaba.csp.sentinel.log.RecordLog Java Examples
The following examples show how to use
com.alibaba.csp.sentinel.log.RecordLog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlowRuleChecker.java From Sentinel with Apache License 2.0 | 6 votes |
private static boolean passClusterCheck(FlowRule rule, Context context, DefaultNode node, int acquireCount, boolean prioritized) { try { TokenService clusterService = pickClusterService(); if (clusterService == null) { return fallbackToLocalOrPass(rule, context, node, acquireCount, prioritized); } long flowId = rule.getClusterConfig().getFlowId(); TokenResult result = clusterService.requestToken(flowId, acquireCount, prioritized); return applyTokenResult(result, rule, context, node, acquireCount, prioritized); // If client is absent, then fallback to local mode. } catch (Throwable ex) { RecordLog.warn("[FlowRuleChecker] Request cluster token unexpected failed", ex); } // Fallback to local flow control when token client or server for this rule is not available. // If fallback is not enabled, then directly pass. return fallbackToLocalOrPass(rule, context, node, acquireCount, prioritized); }
Example #2
Source File: ApolloDataSource.java From Sentinel with Apache License 2.0 | 6 votes |
/** * Constructs the Apollo data source * * @param namespaceName the namespace name in Apollo, should not be null or empty * @param ruleKey the rule key in the namespace, should not be null or empty * @param defaultRuleValue the default rule value when the ruleKey is not found or any error * occurred * @param parser the parser to transform string configuration to actual flow rules */ public ApolloDataSource(String namespaceName, String ruleKey, String defaultRuleValue, Converter<String, T> parser) { super(parser); Preconditions.checkArgument(!Strings.isNullOrEmpty(namespaceName), "Namespace name could not be null or empty"); Preconditions.checkArgument(!Strings.isNullOrEmpty(ruleKey), "RuleKey could not be null or empty!"); this.ruleKey = ruleKey; this.defaultRuleValue = defaultRuleValue; this.config = ConfigService.getConfig(namespaceName); initialize(); RecordLog.info(String.format("Initialized rule for namespace: %s, rule key: %s", namespaceName, ruleKey)); }
Example #3
Source File: AbstractSentinelProccesser.java From jboot with Apache License 2.0 | 6 votes |
private Method findMethod(boolean mustStatic, Class<?> clazz, String name, Class<?> returnType, Class<?>... parameterTypes) { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (name.equals(method.getName()) && checkStatic(mustStatic, method) && returnType.isAssignableFrom(method.getReturnType()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { RecordLog.info("Resolved method [{0}] in class [{1}]", name, clazz.getCanonicalName()); return method; } } // Current class not found, find in the super classes recursively. Class<?> superClass = clazz.getSuperclass(); if (superClass != null && !Object.class.equals(superClass)) { return findMethod(mustStatic, superClass, name, returnType, parameterTypes); } else { String methodType = mustStatic ? " static" : ""; RecordLog.warn("Cannot find{0} method [{1}] in class [{2}] with parameters {3}", methodType, name, clazz.getCanonicalName(), Arrays.toString(parameterTypes)); return null; } }
Example #4
Source File: UpdateGatewayApiDefinitionGroupCommandHandler.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
@Override public CommandResponse<String> handle(CommandRequest request) { String data = request.getParam("data"); if (StringUtil.isBlank(data)) { return CommandResponse.ofFailure(new IllegalArgumentException("Bad data")); } try { data = URLDecoder.decode(data, "utf-8"); } catch (Exception e) { RecordLog.info("Decode gateway API definition data error", e); return CommandResponse.ofFailure(e, "decode gateway API definition data error"); } RecordLog.info("[API Server] Receiving data change (type: gateway API definition): {0}", data); String result = SUCCESS_MSG; Set<ApiDefinition> apiDefinitions = parseJson(data); GatewayApiDefinitionManager.loadApiDefinitions(apiDefinitions); return CommandResponse.ofSuccess(result); }
Example #5
Source File: FlowRuleChecker.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private static boolean passClusterCheck(FlowRule rule, Context context, DefaultNode node, int acquireCount, boolean prioritized) { try { TokenService clusterService = pickClusterService(); if (clusterService == null) { return fallbackToLocalOrPass(rule, context, node, acquireCount, prioritized); } long flowId = rule.getClusterConfig().getFlowId(); TokenResult result = clusterService.requestToken(flowId, acquireCount, prioritized); return applyTokenResult(result, rule, context, node, acquireCount, prioritized); // If client is absent, then fallback to local mode. } catch (Throwable ex) { RecordLog.warn("[FlowRuleChecker] Request cluster token unexpected failed", ex); } // Fallback to local flow control when token client or server for this rule is not available. // If fallback is not enabled, then directly pass. return fallbackToLocalOrPass(rule, context, node, acquireCount, prioritized); }
Example #6
Source File: NettyTransportClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private void connect(Bootstrap b) { if (currentState.compareAndSet(ClientConstants.CLIENT_STATUS_OFF, ClientConstants.CLIENT_STATUS_PENDING)) { b.connect(host, port) .addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) { if (future.cause() != null) { RecordLog.warn( String.format("[NettyTransportClient] Could not connect to <%s:%d> after %d times", host, port, failConnectedTime.get()), future.cause()); failConnectedTime.incrementAndGet(); channel = null; } else { failConnectedTime.set(0); channel = future.channel(); RecordLog.info( "[NettyTransportClient] Successfully connect to server <" + host + ":" + port + ">"); } } }); } }
Example #7
Source File: NettyTransportServer.java From Sentinel with Apache License 2.0 | 6 votes |
@Override public void stop() { // If still initializing, wait for ready. while (currentState.get() == SERVER_STATUS_STARTING) { try { Thread.sleep(500); } catch (InterruptedException e) { // Ignore. } } if (currentState.compareAndSet(SERVER_STATUS_STARTED, SERVER_STATUS_OFF)) { try { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); connectionPool.shutdownAll(); failedTimes.set(0); RecordLog.info("[NettyTransportServer] Sentinel token server stopped"); } catch (Exception ex) { RecordLog.warn("[NettyTransportServer] Failed to stop token server (port=" + port + ")", ex); } } }
Example #8
Source File: DefaultRequestEntityDecoder.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
@Override public ClusterRequest decode(ByteBuf source) { if (source.readableBytes() >= 5) { int xid = source.readInt(); int type = source.readByte(); EntityDecoder<ByteBuf, ?> dataDecoder = RequestDataDecodeRegistry.getDecoder(type); if (dataDecoder == null) { RecordLog.warn("Unknown type of request data decoder: {0}", type); return null; } Object data; if (source.readableBytes() == 0) { data = null; } else { data = dataDecoder.decode(source); } return new ClusterRequest<>(xid, type, data); } return null; }
Example #9
Source File: ServerEntityCodecProvider.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private static void resolveInstance() { ResponseEntityWriter writer = SpiLoader.loadFirstInstance(ResponseEntityWriter.class); if (writer == null) { RecordLog.warn("[ServerEntityCodecProvider] No existing response entity writer, resolve failed"); } else { responseEntityWriter = writer; RecordLog.info( "[ServerEntityCodecProvider] Response entity writer resolved: " + responseEntityWriter.getClass() .getCanonicalName()); } RequestEntityDecoder decoder = SpiLoader.loadFirstInstance(RequestEntityDecoder.class); if (decoder == null) { RecordLog.warn("[ServerEntityCodecProvider] No existing request entity decoder, resolve failed"); } else { requestEntityDecoder = decoder; RecordLog.info( "[ServerEntityCodecProvider] Request entity decoder resolved: " + requestEntityDecoder.getClass() .getCanonicalName()); } }
Example #10
Source File: ClientEntityCodecProvider.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private static void resolveInstance() { RequestEntityWriter writer = SpiLoader.loadFirstInstance(RequestEntityWriter.class); if (writer == null) { RecordLog.warn("[ClientEntityCodecProvider] No existing request entity writer, resolve failed"); } else { requestEntityWriter = writer; RecordLog.info("[ClientEntityCodecProvider] Request entity writer resolved: " + requestEntityWriter.getClass().getCanonicalName()); } ResponseEntityDecoder decoder = SpiLoader.loadFirstInstance(ResponseEntityDecoder.class); if (decoder == null) { RecordLog.warn("[ClientEntityCodecProvider] No existing response entity decoder, resolve failed"); } else { responseEntityDecoder = decoder; RecordLog.info("[ClientEntityCodecProvider] Response entity decoder resolved: " + responseEntityDecoder.getClass().getCanonicalName()); } }
Example #11
Source File: AbstractSentinelInterceptorSupport.java From Sentinel with Apache License 2.0 | 6 votes |
private Method findMethod(boolean mustStatic, Class<?> clazz, String name, Class<?> returnType, Class<?>... parameterTypes) { Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (name.equals(method.getName()) && checkStatic(mustStatic, method) && returnType.isAssignableFrom(method.getReturnType()) && Arrays.equals(parameterTypes, method.getParameterTypes())) { RecordLog.info("Resolved method [{}] in class [{}]", name, clazz.getCanonicalName()); return method; } } // Current class not found, find in the super classes recursively. Class<?> superClass = clazz.getSuperclass(); if (superClass != null && !Object.class.equals(superClass)) { return findMethod(mustStatic, superClass, name, returnType, parameterTypes); } else { String methodType = mustStatic ? " static" : ""; RecordLog.warn("Cannot find{} method [{}] in class [{}] with parameters {}", methodType, name, clazz.getCanonicalName(), Arrays.toString(parameterTypes)); return null; } }
Example #12
Source File: SystemRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
@Override public void configUpdate(List<SystemRule> rules) { restoreSetting(); // systemRules = rules; if (rules != null && rules.size() >= 1) { for (SystemRule rule : rules) { loadSystemConf(rule); } } else { checkSystemStatus.set(false); } RecordLog.info(String.format("[SystemRuleManager] Current system check status: %s, " + "highestSystemLoad: %e, " + "highestCpuUsage: %e, " + "maxRt: %d, " + "maxThread: %d, " + "maxQps: %e", checkSystemStatus.get(), highestSystemLoad, highestCpuUsage, maxRt, maxThread, qps)); }
Example #13
Source File: SystemRuleManager.java From Sentinel with Apache License 2.0 | 6 votes |
@Override public synchronized void configUpdate(List<SystemRule> rules) { restoreSetting(); // systemRules = rules; if (rules != null && rules.size() >= 1) { for (SystemRule rule : rules) { loadSystemConf(rule); } } else { checkSystemStatus.set(false); } RecordLog.info(String.format("[SystemRuleManager] Current system check status: %s, " + "highestSystemLoad: %e, " + "highestCpuUsage: %e, " + "maxRt: %d, " + "maxThread: %d, " + "maxQps: %e", checkSystemStatus.get(), highestSystemLoad, highestCpuUsage, maxRt, maxThread, qps)); }
Example #14
Source File: DefaultResponseEntityDecoder.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
@Override public ClusterResponse decode(ByteBuf source) { if (source.readableBytes() >= 6) { int xid = source.readInt(); int type = source.readByte(); int status = source.readByte(); EntityDecoder<ByteBuf, ?> decoder = ResponseDataDecodeRegistry.getDecoder(type); if (decoder == null) { RecordLog.warn("Unknown type of response data decoder: {0}", type); return null; } Object data; if (source.readableBytes() == 0) { data = null; } else { data = decoder.decode(source); } return new ClusterResponse<>(xid, type, status, data); } return null; }
Example #15
Source File: DefaultClusterTokenClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private void initNewConnection() { if (transportClient != null) { return; } String host = ClusterClientConfigManager.getServerHost(); int port = ClusterClientConfigManager.getServerPort(); if (StringUtil.isBlank(host) || port <= 0) { return; } try { this.transportClient = new NettyTransportClient(host, port); this.serverDescriptor = new TokenServerDescriptor(host, port); RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor); } catch (Exception ex) { RecordLog.warn("[DefaultClusterTokenClient] Failed to initialize new token client", ex); } }
Example #16
Source File: DefaultClusterTokenClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private void changeServer(/*@Valid*/ ClusterClientAssignConfig config) { if (serverEqual(serverDescriptor, config)) { return; } try { if (transportClient != null) { transportClient.stop(); } // Replace with new, even if the new client is not ready. this.transportClient = new NettyTransportClient(config.getServerHost(), config.getServerPort()); this.serverDescriptor = new TokenServerDescriptor(config.getServerHost(), config.getServerPort()); startClientIfScheduled(); RecordLog.info("[DefaultClusterTokenClient] New client created: " + serverDescriptor); } catch (Exception ex) { RecordLog.warn("[DefaultClusterTokenClient] Failed to change remote token server", ex); } }
Example #17
Source File: SentinelEnvoyRlsServer.java From Sentinel with Apache License 2.0 | 6 votes |
private static int resolvePort() { final int defaultPort = SentinelEnvoyRlsConstants.DEFAULT_GRPC_PORT; // Order: system env > property String portStr = Optional.ofNullable(System.getenv(SentinelEnvoyRlsConstants.GRPC_PORT_ENV_KEY)) .orElse(SentinelConfig.getConfig(SentinelEnvoyRlsConstants.GRPC_PORT_PROPERTY_KEY)); if (StringUtil.isBlank(portStr)) { return defaultPort; } try { int port = Integer.parseInt(portStr); if (port <= 0 || port > 65535) { RecordLog.warn("[SentinelEnvoyRlsServer] Invalid port <" + portStr + ">, using default" + defaultPort); return defaultPort; } return port; } catch (Exception ex) { RecordLog.warn("[SentinelEnvoyRlsServer] Failed to resolve port, using default " + defaultPort); System.err.println("[SentinelEnvoyRlsServer] Failed to resolve port, using default " + defaultPort); return defaultPort; } }
Example #18
Source File: NettyTransportClient.java From Sentinel with Apache License 2.0 | 6 votes |
private void connect(Bootstrap b) { if (currentState.compareAndSet(ClientConstants.CLIENT_STATUS_OFF, ClientConstants.CLIENT_STATUS_PENDING)) { b.connect(host, port) .addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) { if (future.cause() != null) { RecordLog.warn( String.format("[NettyTransportClient] Could not connect to <%s:%d> after %d times", host, port, failConnectedTime.get()), future.cause()); failConnectedTime.incrementAndGet(); channel = null; } else { failConnectedTime.set(0); channel = future.channel(); RecordLog.info( "[NettyTransportClient] Successfully connect to server <" + host + ":" + port + ">"); } } }); } }
Example #19
Source File: ContextUtil.java From Sentinel with Apache License 2.0 | 5 votes |
private static void setNullContext() { contextHolder.set(NULL_CONTEXT); // Don't need to be thread-safe. if (shouldWarn) { RecordLog.warn("[SentinelStatusChecker] WARN: Amount of context exceeds the threshold " + Constants.MAX_CONTEXT_NAME_SIZE + ". Entries in new contexts will NOT take effect!"); shouldWarn = false; } }
Example #20
Source File: DefaultClusterServerInitFunc.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Override public void init() throws Exception { initDefaultEntityDecoders(); initDefaultEntityWriters(); initDefaultProcessors(); // Eagerly-trigger the SPI pre-load of token service. TokenServiceProvider.getService(); RecordLog.info("[DefaultClusterServerInitFunc] Default entity codec and processors registered"); }
Example #21
Source File: SystemRuleManager.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Listen to the {@link SentinelProperty} for {@link SystemRule}s. The property is the source * of {@link SystemRule}s. System rules can also be set by {@link #loadRules(List)} directly. * * @param property the property to listen. */ public static void register2Property(SentinelProperty<List<SystemRule>> property) { synchronized (listener) { RecordLog.info("[SystemRuleManager] Registering new property to system rule manager"); currentProperty.removeListener(listener); property.addListener(listener); currentProperty = property; } }
Example #22
Source File: FileInJarReadableDataSource.java From Sentinel with Apache License 2.0 | 5 votes |
private void firstLoad() { try { T newValue = loadConfig(); getProperty().updateValue(newValue); } catch (Throwable e) { RecordLog.warn("[FileInJarReadableDataSource] Error when loading config", e); } }
Example #23
Source File: SentinelDefaultTokenServer.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private void startServerIfScheduled() throws Exception { if (shouldStart.get()) { if (server != null) { server.start(); ClusterStateManager.markToServer(); if (embedded) { RecordLog.info("[SentinelDefaultTokenServer] Running in embedded mode"); handleEmbeddedStart(); } } } }
Example #24
Source File: ClusterFlowRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Remove cluster flow rule property for a specific namespace. * * @param namespace valid namespace */ public static void removeProperty(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); synchronized (UPDATE_LOCK) { NamespaceFlowProperty<FlowRule> property = PROPERTY_MAP.get(namespace); if (property != null) { property.getProperty().removeListener(property.getListener()); PROPERTY_MAP.remove(namespace); } RecordLog.info("[ClusterFlowRuleManager] Removing property from cluster flow rule manager" + " for namespace <{0}>", namespace); } }
Example #25
Source File: NacosDataSource.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private void initNacosListener() { try { this.configService = NacosFactory.createConfigService(this.properties); // Add config listener. configService.addListener(dataId, groupId, configListener); } catch (Exception e) { RecordLog.warn("[NacosDataSource] Error occurred when initializing Nacos data source", e); e.printStackTrace(); } }
Example #26
Source File: DegradeRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Listen to the {@link SentinelProperty} for {@link DegradeRule}s. The property is the source * of {@link DegradeRule}s. Degrade rules can also be set by {@link #loadRules(List)} directly. * * @param property the property to listen. */ public static void register2Property(SentinelProperty<List<DegradeRule>> property) { AssertUtil.notNull(property, "property cannot be null"); synchronized (LISTENER) { RecordLog.info("[DegradeRuleManager] Registering new property to degrade rule manager"); currentProperty.removeListener(LISTENER); property.addListener(LISTENER); currentProperty = property; } }
Example #27
Source File: ParamFlowRuleManager.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Load parameter flow rules. Former rules will be replaced. * * @param rules new rules to load. */ public static void loadRules(List<ParamFlowRule> rules) { try { currentProperty.updateValue(rules); } catch (Throwable e) { RecordLog.info("[ParamFlowRuleManager] Failed to load rules", e); } }
Example #28
Source File: EtcdDataSource.java From Sentinel with Apache License 2.0 | 5 votes |
private void loadInitialConfig() { try { T newValue = loadConfig(); if (newValue == null) { RecordLog.warn( "[EtcdDataSource] Initial configuration is null, you may have to check your data source"); } getProperty().updateValue(newValue); } catch (Exception ex) { RecordLog.warn("[EtcdDataSource] Error when loading initial configuration", ex); } }
Example #29
Source File: RedisDataSource.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Build Redis client fromm {@code RedisConnectionConfig}. * * @return a new {@link RedisClient} */ private RedisClient getRedisClient(RedisConnectionConfig connectionConfig) { if (connectionConfig.getRedisSentinels().size() == 0) { RecordLog.info("[RedisDataSource] Creating stand-alone mode Redis client"); return getRedisStandaloneClient(connectionConfig); } else { RecordLog.info("[RedisDataSource] Creating Redis Sentinel mode Redis client"); return getRedisSentinelClient(connectionConfig); } }
Example #30
Source File: EagleEyeLogUtilTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Test public void testWriteLog() throws Exception { EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1); final File file = new File(RecordLog.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME); await().timeout(2, TimeUnit.SECONDS) .until(new Callable<File>() { @Override public File call() throws Exception { return file; } }, FileMatchers.anExistingFile()); }