use of com.amazonaws.services.logs.model.DescribeLogStreamsRequest in project cloudbreak by hortonworks.
the class CloudwatchRecordWorker method describeLogStreams.
@VisibleForTesting
DescribeLogStreamsResult describeLogStreams() {
DescribeLogStreamsRequest describeLogStreams = new DescribeLogStreamsRequest();
describeLogStreams.setLogGroupName(logGroup);
describeLogStreams.setLogStreamNamePrefix(logStream);
try {
DescribeLogStreamsResult describeLogStreamsResult = getAwsLogsClient().describeLogStreams(describeLogStreams);
if (!describeLogStreamsResult.getLogStreams().isEmpty()) {
return describeLogStreamsResult;
} else {
CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest();
createLogStreamRequest.setLogGroupName(logGroup);
createLogStreamRequest.setLogStreamName(logStream);
getAwsLogsClient().createLogStream(createLogStreamRequest);
return getAwsLogsClient().describeLogStreams(describeLogStreams);
}
} catch (ResourceNotFoundException re) {
LOGGER.error("Error during describing AWS CloudWatch log streams: log group '{}' not found", logGroup, re);
throw re;
}
}
use of com.amazonaws.services.logs.model.DescribeLogStreamsRequest in project cloudbreak by hortonworks.
the class CloudwatchRecordWorkerTest method testDescribeLogStreamsWhenLogStreamDoesNotExist.
@Test
public void testDescribeLogStreamsWhenLogStreamDoesNotExist() {
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest();
describeLogStreamsRequest.setLogGroupName("TestGroup");
describeLogStreamsRequest.setLogStreamNamePrefix(underTest.initLogStream("TestStream"));
DescribeLogStreamsResult describeLogStreamsResult = new DescribeLogStreamsResult();
Set<LogStream> logStreams = new HashSet<>();
describeLogStreamsResult.setLogStreams(logStreams);
when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest();
createLogStreamRequest.setLogGroupName("TestGroup");
createLogStreamRequest.setLogStreamName(underTest.initLogStream("TestStream"));
when(awsLogsClient.createLogStream(createLogStreamRequest)).thenReturn(new CreateLogStreamResult());
underTest.describeLogStreams();
verify(awsLogsClient, times(2)).describeLogStreams(describeLogStreamsRequest);
verify(awsLogsClient, times(1)).createLogStream(createLogStreamRequest);
}
use of com.amazonaws.services.logs.model.DescribeLogStreamsRequest in project cloudbreak by hortonworks.
the class CloudwatchRecordWorkerTest method testDescribeLogStreamsWhenLogStreamExists.
@Test
public void testDescribeLogStreamsWhenLogStreamExists() {
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest();
describeLogStreamsRequest.setLogGroupName("TestGroup");
describeLogStreamsRequest.setLogStreamNamePrefix(underTest.initLogStream("TestStream"));
DescribeLogStreamsResult describeLogStreamsResult = new DescribeLogStreamsResult();
Set<LogStream> logStreams = new HashSet<>();
LogStream logStream = new LogStream();
logStreams.add(logStream);
describeLogStreamsResult.setLogStreams(logStreams);
when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
underTest.describeLogStreams();
verify(awsLogsClient, times(1)).describeLogStreams(describeLogStreamsRequest);
}
use of com.amazonaws.services.logs.model.DescribeLogStreamsRequest in project quarkus-logging-cloudwatch by quarkiverse.
the class LoggingCloudWatchHandlerValueFactory method createLogStreamIfNeeded.
private String createLogStreamIfNeeded(AWSLogs awsLogs, LoggingCloudWatchConfig config) {
String token = null;
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest(config.logGroup.get());
// We need to filter down, as CW returns by default only 50 streams and ours may not be in it.
describeLogStreamsRequest.withLogStreamNamePrefix(config.logStreamName.get());
List<LogStream> logStreams = awsLogs.describeLogStreams(describeLogStreamsRequest).getLogStreams();
boolean found = false;
for (LogStream ls : logStreams) {
if (ls.getLogStreamName().equals(config.logStreamName.get())) {
found = true;
token = ls.getUploadSequenceToken();
}
}
if (!found) {
awsLogs.createLogStream(new CreateLogStreamRequest(config.logGroup.get(), config.logStreamName.get()));
}
return token;
}
use of com.amazonaws.services.logs.model.DescribeLogStreamsRequest in project aws-athena-query-federation by awslabs.
the class CloudwatchMetadataHandler method doListTables.
/**
* List LogStreams within the requested schema (aka LogGroup) in your Cloudwatch account treating each as a 'table'.
*
* @see MetadataHandler
*/
@Override
public ListTablesResponse doListTables(BlockAllocator blockAllocator, ListTablesRequest listTablesRequest) throws TimeoutException {
String nextToken = null;
String logGroupName = tableResolver.validateSchema(listTablesRequest.getSchemaName());
DescribeLogStreamsRequest request = new DescribeLogStreamsRequest(logGroupName);
DescribeLogStreamsResult result;
List<TableName> tables = new ArrayList<>();
if (listTablesRequest.getPageSize() == UNLIMITED_PAGE_SIZE_VALUE) {
do {
if (tables.size() > MAX_RESULTS) {
throw new RuntimeException("Too many log streams, exceeded max metadata results for table count.");
}
result = invoker.invoke(() -> awsLogs.describeLogStreams(request));
result.getLogStreams().forEach(next -> tables.add(toTableName(listTablesRequest, next)));
request.setNextToken(result.getNextToken());
logger.info("doListTables: Listing log streams with token {} and size {}", result.getNextToken(), tables.size());
} while (result.getNextToken() != null);
} else {
request.setNextToken(listTablesRequest.getNextToken());
request.setLimit(listTablesRequest.getPageSize());
result = invoker.invoke(() -> awsLogs.describeLogStreams(request));
result.getLogStreams().forEach(next -> tables.add(toTableName(listTablesRequest, next)));
nextToken = result.getNextToken();
logger.info("doListTables: Listing log streams with token {} and size {}", result.getNextToken(), tables.size());
}
// We add a special table that represents all log streams. This is helpful depending on how
// you have your logs organized.
tables.add(new TableName(listTablesRequest.getSchemaName(), ALL_LOG_STREAMS_TABLE));
return new ListTablesResponse(listTablesRequest.getCatalogName(), tables, nextToken);
}
Aggregations