com.amazonaws.services.logs.AWSLogsClient Java Examples
The following examples show how to use
com.amazonaws.services.logs.AWSLogsClient.
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: CloudWatchMonitor.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 5 votes |
public CloudWatchMonitor(AWSLogsClient client, boolean cwlStreamingDisabled) { this.logsClient = client; this.cwlStreamingDisabled = cwlStreamingDisabled; if(!CodeBuilderValidation.checkCloudWatchMonitorConfig(logsClient)) { latestLogs = Arrays.asList(failedConfigurationLogsMessage); return; } if(cwlStreamingDisabled) { latestLogs = Arrays.asList(streamingDisabledMessage); } lastPollTime = 0L; }
Example #2
Source File: CloudWatchAppender.java From cloudwatch-logback-appender with ISC License | 4 votes |
void setAwsLogsClient(AWSLogsClient awsLogsClient) { this.awsLogsClient = awsLogsClient; }
Example #3
Source File: CloudWatchAppenderTest.java From cloudwatch-logback-appender with ISC License | 4 votes |
@Test(timeout = 5000) public void testBasic() throws InterruptedException { CloudWatchAppender appender = new CloudWatchAppender(); AWSLogsClient awsLogClient = createMock(AWSLogsClient.class); appender.setAwsLogsClient(awsLogClient); appender.setMaxBatchSize(1); appender.setRegion("region"); final String logGroup = "pfqoejpfqe"; appender.setLogGroup(logGroup); final String logStream = "pffqjfqjpoqoejpfqe"; appender.setLogStream(logStream); PatternLayout layout = new PatternLayout(); layout.setContext(new LoggerContext()); layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable"); layout.start(); appender.setLayout(layout); LoggingEvent event = new LoggingEvent(); event.setTimeStamp(System.currentTimeMillis()); String loggerName = "name"; event.setLoggerName(loggerName); Level level = Level.DEBUG; event.setLevel(level); String message = "fjpewjfpewjfpewjfepowf"; event.setMessage(message); String threadName = Thread.currentThread().getName(); final String fullMessage = "[" + threadName + "] " + level + " " + loggerName + " - " + message + "\n"; final PutLogEventsResult result = new PutLogEventsResult(); String sequence = "ewopjfewfj"; result.setNextSequenceToken(sequence); expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() { @Override public PutLogEventsResult answer() { PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0]; assertEquals(logGroup, request.getLogGroupName()); assertEquals(logStream, request.getLogStreamName()); List<InputLogEvent> events = request.getLogEvents(); assertEquals(1, events.size()); assertEquals(fullMessage, events.get(0).getMessage()); return result; } }).times(2); awsLogClient.shutdown(); // ===================================== replay(awsLogClient); appender.start(); // for coverage appender.start(); appender.append(event); Thread.sleep(10); appender.append(event); while (appender.getEventsWrittenCount() < 2) { Thread.sleep(10); } appender.stop(); verify(awsLogClient); }
Example #4
Source File: CloudWatchAppenderTest.java From cloudwatch-logback-appender with ISC License | 4 votes |
@Test(timeout = 5000) public void testInstanceName() throws InterruptedException { CloudWatchAppender appender = new CloudWatchAppender(); AWSLogsClient awsLogClient = createMock(AWSLogsClient.class); appender.setAwsLogsClient(awsLogClient); appender.setMaxBatchSize(1); appender.setRegion("region"); final String logGroup = "pfqoejpfqe"; appender.setLogGroup(logGroup); String prefix = "logstream-"; appender.setLogStream(prefix + "%instanceName"); final String expectedLogStream = prefix + "unknown"; PatternLayout layout = new PatternLayout(); layout.setPattern("%msg"); layout.start(); appender.setLayout(layout); LoggingEvent event = new LoggingEvent(); event.setTimeStamp(System.currentTimeMillis()); event.setLoggerName("name"); event.setLevel(Level.DEBUG); event.setMessage("message"); final PutLogEventsResult result = new PutLogEventsResult(); result.setNextSequenceToken("ewopjfewfj"); expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() { @Override public PutLogEventsResult answer() { PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0]; assertEquals(logGroup, request.getLogGroupName()); assertEquals(expectedLogStream, request.getLogStreamName()); return result; } }); awsLogClient.shutdown(); // ===================================== replay(awsLogClient); appender.start(); appender.append(event); while (appender.getEventsWrittenCount() < 1) { Thread.sleep(10); } appender.stop(); verify(awsLogClient); }
Example #5
Source File: CloudwatchMetricFilterTest.java From lambda-monitoring with Apache License 2.0 | 4 votes |
@Ignore @Test public void testMetricFilters() { List<String> lines; PrintStream original = System.out; try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(outputStream, true)); Logger logger = LoggerFactory.getLogger("TEST-LOGGER"); logger.info("TEST-MESSAGE"); TestMetricSet metricSet = new TestMetricSet(); MetricRegistry registry = new MetricRegistry(); registry.registerAll(metricSet); metricSet.testCounter.inc(); metricSet.testMeter.mark(1L); metricSet.testHistogram.update(1L); metricSet.testTimer.update(1L, TimeUnit.MINUTES); Slf4jReporter reporter = Slf4jReporter.forRegistry(registry) .markWith(MarkerFactory.getMarker("METRIC")) .outputTo(logger) .build(); reporter.report(); lines = Arrays.asList(outputStream.toString().split("\\n")); } finally { System.setOut(original); } assertNotNull(lines); AWSLogsClient client = new AWSLogsClient(); // TODO: Loop for each kind of metric String metricFilterPattern = String.format(COMPLETE_FILTER_PATTERN_MAP.get("COUNTER"), "test.namespace/testCounter"); TestMetricFilterRequest request = new TestMetricFilterRequest() .withFilterPattern(metricFilterPattern) .withLogEventMessages(lines); TestMetricFilterResult result = client.testMetricFilter(request); MetricFilterMatchRecord matchRecord = result.getMatches().get(0); assertEquals("test.namespace/testCounter", matchRecord.getExtractedValues().get("$name")); assertEquals("1", matchRecord.getExtractedValues().get("$count")); MetricFilterMatchRecord matchRecord2 = result.getMatches().get(1); assertEquals("test.namespace/testGauge", matchRecord2.getExtractedValues().get("$name")); assertEquals("42", matchRecord2.getExtractedValues().get("$value")); }
Example #6
Source File: CodeBuilderValidation.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 4 votes |
public static boolean checkCloudWatchMonitorConfig(AWSLogsClient client) { if(client == null) { return false; } return true; }
Example #7
Source File: AWSClientFactory.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 4 votes |
public AWSLogsClient getCloudWatchLogsClient() throws InvalidInputException { AWSLogsClient client = new AWSLogsClient(awsCredentialsProvider, getClientConfiguration()); client.setEndpoint("https://logs." + region + getAwsClientSuffix(region)); return client; }