embulk-input-cloudwatch_logs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/LICENSE.txt +23 -0
- data/README.md +115 -0
- data/build.gradle +122 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +5 -0
- data/gradlew +183 -0
- data/gradlew.bat +103 -0
- data/lib/embulk/input/cloudwatch_logs.rb +3 -0
- data/src/main/java/org/embulk/input/cloudwatch_logs/AbstractCloudwatchLogsInputPlugin.java +336 -0
- data/src/main/java/org/embulk/input/cloudwatch_logs/CloudwatchLogsInputPlugin.java +57 -0
- data/src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentials.java +183 -0
- data/src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentialsConfig.java +32 -0
- data/src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentialsTask.java +41 -0
- data/src/test/java/org/embulk/input/cloudwatch_logs/TestAwsCredentials.java +188 -0
- data/src/test/java/org/embulk/input/cloudwatch_logs/TestCloudwatchLogsInputPlugin.java +144 -0
- metadata +102 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
package org.embulk.input.cloudwatch_logs;
|
2
|
+
|
3
|
+
import com.amazonaws.services.logs.AWSLogsClient;
|
4
|
+
import com.amazonaws.services.logs.AWSLogsClientBuilder;
|
5
|
+
import com.amazonaws.services.logs.AWSLogs;
|
6
|
+
import com.amazonaws.services.logs.model.DescribeLogStreamsRequest;
|
7
|
+
import com.amazonaws.services.logs.model.DescribeLogStreamsResult;
|
8
|
+
import com.amazonaws.services.logs.model.LogStream;
|
9
|
+
import com.amazonaws.services.logs.model.GetLogEventsRequest;
|
10
|
+
import com.amazonaws.services.logs.model.GetLogEventsResult;
|
11
|
+
import com.amazonaws.services.logs.model.OutputLogEvent;
|
12
|
+
|
13
|
+
import org.embulk.EmbulkTestRuntime;
|
14
|
+
import org.embulk.config.ConfigDiff;
|
15
|
+
import org.embulk.config.ConfigSource;
|
16
|
+
import org.embulk.config.TaskReport;
|
17
|
+
import org.embulk.config.TaskSource;
|
18
|
+
import org.embulk.spi.InputPlugin;
|
19
|
+
import org.embulk.spi.PageBuilder;
|
20
|
+
import org.embulk.spi.PageOutput;
|
21
|
+
import org.embulk.spi.Schema;
|
22
|
+
import org.embulk.spi.TestPageBuilderReader.MockPageOutput;
|
23
|
+
import org.embulk.spi.util.Pages;
|
24
|
+
import org.embulk.test.EmbulkTests;
|
25
|
+
import org.embulk.test.TestingEmbulk;
|
26
|
+
|
27
|
+
import org.junit.Before;
|
28
|
+
import org.junit.BeforeClass;
|
29
|
+
import org.junit.Rule;
|
30
|
+
import org.junit.Test;
|
31
|
+
import org.mockito.Mockito;
|
32
|
+
import org.mockito.Spy;
|
33
|
+
|
34
|
+
import java.io.IOException;
|
35
|
+
import java.util.ArrayList;
|
36
|
+
import java.util.List;
|
37
|
+
import org.embulk.input.cloudwatch_logs.CloudwatchLogsInputPlugin;
|
38
|
+
|
39
|
+
import static org.embulk.input.cloudwatch_logs.CloudwatchLogsInputPlugin.CloudWatchLogsPluginTask;
|
40
|
+
import static org.junit.Assert.assertEquals;
|
41
|
+
import static org.junit.Assert.assertFalse;
|
42
|
+
import static org.junit.Assert.assertNull;
|
43
|
+
import static org.junit.Assume.assumeNotNull;
|
44
|
+
import static org.junit.Assert.assertEquals;
|
45
|
+
import static org.junit.Assert.assertTrue;
|
46
|
+
import static org.mockito.Mockito.doReturn;
|
47
|
+
import static org.mockito.Mockito.times;
|
48
|
+
import static org.mockito.Mockito.verify;
|
49
|
+
import static org.mockito.Mockito.when;
|
50
|
+
|
51
|
+
public class TestCloudwatchLogsInputPlugin
|
52
|
+
{
|
53
|
+
@Rule
|
54
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
55
|
+
|
56
|
+
@Rule
|
57
|
+
public TestingEmbulk embulk = TestingEmbulk.builder()
|
58
|
+
.registerPlugin(InputPlugin.class, "cloudwatch_logs", CloudwatchLogsInputPlugin.class)
|
59
|
+
.build();
|
60
|
+
|
61
|
+
private CloudwatchLogsInputPlugin plugin;
|
62
|
+
|
63
|
+
private ConfigSource config;
|
64
|
+
private MockPageOutput output = new MockPageOutput();
|
65
|
+
private PageBuilder pageBuilder;
|
66
|
+
|
67
|
+
private static String EMBULK_LOGS_TEST_GROUP_NAME;
|
68
|
+
private static String EMBULK_LOGS_TEST_STREAM_NAME;
|
69
|
+
private static String EMBULK_LOGS_TEST_REGION;
|
70
|
+
private static String EMBULK_LOGS_TEST_ACCESS_KEY_ID;
|
71
|
+
private static String EMBULK_LOGS_TEST_SECRET_ACCESS_KEY;
|
72
|
+
|
73
|
+
/*
|
74
|
+
* This test case requires environment variables:
|
75
|
+
* EMBULK_LOGS_TEST_GROUP_NAME
|
76
|
+
* EMBULK_LOGS_TEST_STREAM_NAME
|
77
|
+
* EMBULK_LOGS_TEST_REGION
|
78
|
+
* EMBULK_LOGS_TEST_ACCESS_KEY_ID
|
79
|
+
* EMBULK_LOGS_TEST_SECRET_ACCESS_KEY
|
80
|
+
* If the variables not set, the test case is skipped.
|
81
|
+
*/
|
82
|
+
@BeforeClass
|
83
|
+
public static void initializeConstantVariables()
|
84
|
+
{
|
85
|
+
EMBULK_LOGS_TEST_GROUP_NAME = System.getenv("EMBULK_LOGS_TEST_GROUP_NAME");
|
86
|
+
EMBULK_LOGS_TEST_STREAM_NAME = System.getenv("EMBULK_LOGS_TEST_STREAM_NAME");
|
87
|
+
EMBULK_LOGS_TEST_REGION = System.getenv("EMBULK_LOGS_TEST_REGION");
|
88
|
+
EMBULK_LOGS_TEST_ACCESS_KEY_ID = System.getenv("EMBULK_LOGS_TEST_ACCESS_KEY_ID");
|
89
|
+
EMBULK_LOGS_TEST_SECRET_ACCESS_KEY = System.getenv("EMBULK_LOGS_TEST_SECRET_ACCESS_KEY");
|
90
|
+
assumeNotNull(EMBULK_LOGS_TEST_GROUP_NAME, EMBULK_LOGS_TEST_STREAM_NAME, EMBULK_LOGS_TEST_REGION, EMBULK_LOGS_TEST_ACCESS_KEY_ID, EMBULK_LOGS_TEST_SECRET_ACCESS_KEY);
|
91
|
+
}
|
92
|
+
|
93
|
+
@Before
|
94
|
+
public void setUp() throws IOException
|
95
|
+
{
|
96
|
+
if (plugin == null) {
|
97
|
+
plugin = Mockito.spy(new CloudwatchLogsInputPlugin());
|
98
|
+
config = runtime.getExec().newConfigSource()
|
99
|
+
.set("type", "cloudwatch_logs")
|
100
|
+
.set("log_group_name", EMBULK_LOGS_TEST_GROUP_NAME)
|
101
|
+
.set("log_stream_name", EMBULK_LOGS_TEST_STREAM_NAME)
|
102
|
+
.set("use_log_stream_name_prefix", "true")
|
103
|
+
.set("region", EMBULK_LOGS_TEST_REGION)
|
104
|
+
.set("aws_access_key_id", EMBULK_LOGS_TEST_ACCESS_KEY_ID)
|
105
|
+
.set("aws_secret_access_key", EMBULK_LOGS_TEST_SECRET_ACCESS_KEY);
|
106
|
+
pageBuilder = Mockito.mock(PageBuilder.class);
|
107
|
+
}
|
108
|
+
doReturn(pageBuilder).when(plugin).getPageBuilder(Mockito.any(), Mockito.any());
|
109
|
+
}
|
110
|
+
|
111
|
+
@Test
|
112
|
+
public void test_simple() throws IOException
|
113
|
+
{
|
114
|
+
plugin.transaction(config, new Control());
|
115
|
+
verify(pageBuilder, times(1)).finish();
|
116
|
+
}
|
117
|
+
|
118
|
+
@Test
|
119
|
+
public void configuredRegion()
|
120
|
+
{
|
121
|
+
CloudWatchLogsPluginTask task = this.config.deepCopy()
|
122
|
+
.set("region", "ap-southeast-2")
|
123
|
+
.remove("endpoint")
|
124
|
+
.loadConfig(CloudWatchLogsPluginTask.class);
|
125
|
+
CloudwatchLogsInputPlugin plugin = runtime.getInstance(CloudwatchLogsInputPlugin.class);
|
126
|
+
AWSLogs logsClient = plugin.newLogsClient(task);
|
127
|
+
|
128
|
+
// Should not be null
|
129
|
+
assumeNotNull(logsClient);
|
130
|
+
}
|
131
|
+
|
132
|
+
private class Control implements InputPlugin.Control
|
133
|
+
{
|
134
|
+
@Override
|
135
|
+
public List<TaskReport> run(final TaskSource taskSource, final Schema schema, final int taskCount)
|
136
|
+
{
|
137
|
+
List<TaskReport> reports = new ArrayList<>();
|
138
|
+
for (int i = 0; i < taskCount; i++) {
|
139
|
+
reports.add(plugin.run(taskSource, schema, i, output));
|
140
|
+
}
|
141
|
+
return reports;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-cloudwatch_logs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroshi Hatake
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.0'
|
19
|
+
name: bundler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '12.0'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
description: Loads records from Cloudwatch Logs.
|
42
|
+
email:
|
43
|
+
- cosmo0920.wp@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- build.gradle
|
52
|
+
- classpath/aws-java-sdk-core-1.11.749.jar
|
53
|
+
- classpath/aws-java-sdk-logs-1.11.749.jar
|
54
|
+
- classpath/aws-java-sdk-sts-1.11.749.jar
|
55
|
+
- classpath/commons-codec-1.11.jar
|
56
|
+
- classpath/commons-logging-1.2.jar
|
57
|
+
- classpath/embulk-input-cloudwatch_logs-0.1.0.jar
|
58
|
+
- classpath/httpclient-4.5.9.jar
|
59
|
+
- classpath/httpcore-4.4.11.jar
|
60
|
+
- classpath/ion-java-1.0.2.jar
|
61
|
+
- classpath/jackson-databind-2.6.7.3.jar
|
62
|
+
- classpath/jackson-dataformat-cbor-2.6.7.jar
|
63
|
+
- classpath/jmespath-java-1.11.749.jar
|
64
|
+
- config/checkstyle/checkstyle.xml
|
65
|
+
- config/checkstyle/default.xml
|
66
|
+
- gradle/wrapper/gradle-wrapper.jar
|
67
|
+
- gradle/wrapper/gradle-wrapper.properties
|
68
|
+
- gradlew
|
69
|
+
- gradlew.bat
|
70
|
+
- lib/embulk/input/cloudwatch_logs.rb
|
71
|
+
- src/main/java/org/embulk/input/cloudwatch_logs/AbstractCloudwatchLogsInputPlugin.java
|
72
|
+
- src/main/java/org/embulk/input/cloudwatch_logs/CloudwatchLogsInputPlugin.java
|
73
|
+
- src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentials.java
|
74
|
+
- src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentialsConfig.java
|
75
|
+
- src/main/java/org/embulk/input/cloudwatch_logs/aws/AwsCredentialsTask.java
|
76
|
+
- src/test/java/org/embulk/input/cloudwatch_logs/TestAwsCredentials.java
|
77
|
+
- src/test/java/org/embulk/input/cloudwatch_logs/TestCloudwatchLogsInputPlugin.java
|
78
|
+
homepage: https://github.com/cosmo0920/embulk-input-cloudwatch_logs
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Cloudwatch Logs input plugin for Embulk
|
102
|
+
test_files: []
|