-
Notifications
You must be signed in to change notification settings - Fork 16
/
ConfigSpec.scala
268 lines (240 loc) · 10.2 KB
/
ConfigSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Copyright (c) 2012-2021 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.rdbloader.common
import java.net.URI
import java.util.UUID
import java.nio.file.{Paths, Files}
import scala.concurrent.duration._
import com.snowplowanalytics.iglu.core.SchemaCriterion
import com.snowplowanalytics.snowplow.rdbloader.common.config.Config.Shredder
import com.snowplowanalytics.snowplow.rdbloader.common.config.{StorageTarget, Config, Step}
import org.specs2.mutable.Specification
import com.snowplowanalytics.snowplow.rdbloader.common.config.Config.Shredder.InitPosition
class ConfigSpec extends Specification {
"fromString" should {
"be able to parse minimal configuration HOCON" in {
val input = """
{
name = "Acme Redshift"
id = "123e4567-e89b-12d3-a456-426655440000"
region = "us-east-1"
jsonpaths = null
messageQueue = "messages"
shredder = {
"type": "batch",
"input": "s3://bucket/input/",
"output" = {
"path": "s3://bucket/good/",
"compression": "GZIP"
}
},
storage = {
"type": "redshift",
"host": "redshift.amazon.com",
"database": "snowplow",
"port": 5439,
"roleArn": "arn:aws:iam::123456789012:role/RedshiftLoadRole",
"schema": "atomic",
"username": "storage-loader",
"password": "secret",
"jdbc": { "ssl": true },
"maxError": 10,
"compRows": 100000,
"sshTunnel": null
},
monitoring = {
"snowplow": {
"collector": "http://snplow.acme.com",
"appId": "redshift-loader"
},
"sentry": {
"dsn": "http://sentry.acme.com"
},
"metrics": {
"type" : "Stdout",
"prefix": "snowplow.rdbloader."
}
},
formats = {
"default": "TSV",
"json": [
"iglu:com.acme/json-event/jsonschema/1-0-0"
],
"tsv": [
"iglu:com.acme/tsv-event/jsonschema/1-*-*",
"iglu:com.acme/tsv-event/jsonschema/2-*-*"
],
"skip": [
"iglu:com.acme/skip-event/jsonschema/1-*-*"
],
},
"steps": ["analyze"]
}"""
val result = Config.fromString(input)
result must beRight(ConfigSpec.configExample)
}
"be able to parse config.hocon.sample" in {
val configPath = Paths.get(getClass.getResource("/config.hocon.sample").toURI)
val configContent = Files.readString(configPath)
val input = Config.Shredder.StreamInput.Kinesis("acme-rdb-shredder", "enriched-events", "us-east-1", InitPosition.Latest)
val expected: Config[StorageTarget] =
(identity[Config[StorageTarget]] _)
.compose(Config.formats.set(Config.Formats.Default))
.compose(Config.monitoring.set(Config.Monitoring(
Some(Config.SnowplowMonitoring("redshift-loader","http://snplow.acme.com")),
Some(Config.Sentry(URI.create("http://sentry.acme.com"))),
Some(Config.Metrics.Stdout("snowplow.rdbloader."))
)))
.apply(ConfigSpec.configExample)
.copy(shredder = Config.Shredder.Stream(input, ConfigSpec.configExample.shredder.output, 10.minutes))
val result = Config.fromString(configContent)
result must beRight(expected)
}
"fail if there are overlapping schema criterions" in {
val input = """
{
name = "Acme Redshift"
id = "123e4567-e89b-12d3-a456-426655440000"
region = "us-east-1"
messageQueue = "messages"
shredder = {
"type": "batch",
"input": "s3://bucket/input/",
"output" = {
"path": "s3://bucket/good/",
"bad": "s3://bucket/bad/",
"compression": "GZIP"
}
},
storage = {
"type": "redshift",
"host": "redshift.amazon.com",
"database": "snowplow",
"port": 5439,
"roleArn": "${role_arn}",
"schema": "atomic",
"username": "storage-loader",
"password": "secret",
"jdbc": { "ssl": true },
"maxError": 10,
"compRows": 100000
},
monitoring = { },
formats = {
"default": "TSV",
"json": [ "iglu:com.acme/overlap/jsonschema/1-0-0" ],
"tsv": [ ],
"skip": [ "iglu:com.acme/overlap/jsonschema/1-*-*" ]
},
steps = []
}"""
val expected = "Following schema criterions overlap in different groups (TSV, JSON, skip): " +
"iglu:com.acme/overlap/jsonschema/1-0-0, iglu:com.acme/overlap/jsonschema/1-*-*. " +
"Make sure every schema can have only one format"
val result = Config.fromString(input)
result must beLeft(expected)
}
}
"Formats.overlap" should {
"confirm two identical criterions overlap" in {
val criterion = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
Config.Formats.overlap(criterion, criterion) should beTrue
}
"confirm two criterions overlap if one of them has * in place where other is concrete" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", None)
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
Config.Formats.overlap(criterionA, criterionB) should beTrue
}
"confirm two criterions do not overlap if they have different concrete models" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(2))
Config.Formats.overlap(criterionA, criterionB) should beFalse
}
"confirm two criterions do not overlap if they have different concrete models, but overlapping revisions" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1), None)
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(2), Some(1))
Config.Formats.overlap(criterionA, criterionB) should beFalse
}
"confirm two criterions do not overlap if they have same concrete models, but different revisions" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1), Some(1))
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1), Some(2))
Config.Formats.overlap(criterionA, criterionB) should beFalse
}
}
"Formats.findOverlaps" should {
"find overlapping TSV and JSON" in {
val criterion = SchemaCriterion("com.acme", "ev", "jsonschema", None)
Config.Formats(LoaderMessage.Format.TSV, List(criterion), List(criterion), List()).findOverlaps must beEqualTo(Set(criterion))
}
"find overlapping JSON and skip" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", None)
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
Config.Formats(LoaderMessage.Format.TSV, List(), List(criterionA), List(criterionB)).findOverlaps must beEqualTo(Set(criterionA, criterionB))
}
"find overlapping skip and TSV" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", None)
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
val criterionC = SchemaCriterion("com.acme", "unique", "jsonschema", Some(1))
Config.Formats(LoaderMessage.Format.TSV, List(criterionA), List(criterionC), List(criterionB)).findOverlaps must beEqualTo(Set(criterionA, criterionB))
}
"not find anything if not overlaps" in {
val criterionA = SchemaCriterion("com.acme", "ev", "jsonschema", Some(1))
val criterionB = SchemaCriterion("com.acme", "ev", "jsonschema", Some(2))
val criterionC = SchemaCriterion("com.acme", "ev", "jsonschema", Some(3))
Config.Formats(LoaderMessage.Format.TSV, List(criterionA), List(criterionB), List(criterionC)).findOverlaps must beEmpty
}
}
}
object ConfigSpec {
val configExample: Config[StorageTarget] = Config(
"Acme Redshift",
UUID.fromString("123e4567-e89b-12d3-a456-426655440000"),
"us-east-1",
None,
Config.Monitoring(
Some(Config.SnowplowMonitoring("redshift-loader","http://snplow.acme.com")),
Some(Config.Sentry(URI.create("http://sentry.acme.com"))),
Some(Config.Metrics.Stdout("snowplow.rdbloader."))
),
"messages",
Shredder.Batch(
URI.create("s3://bucket/input/"),
Shredder.Output(
URI.create("s3://bucket/good/"),
Config.Shredder.Compression.Gzip
)
),
StorageTarget.Redshift(
"redshift.amazon.com",
"snowplow",
5439,
StorageTarget.RedshiftJdbc(None, None, None, None, None, None, None, Some(true),None,None,None,None),
"arn:aws:iam::123456789012:role/RedshiftLoadRole",
"atomic",
"storage-loader",
StorageTarget.PasswordConfig.PlainText("secret"),
10,
None
),
Config.Formats(
LoaderMessage.Format.TSV,
List(
SchemaCriterion("com.acme","tsv-event","jsonschema",Some(1),None,None),
SchemaCriterion("com.acme","tsv-event","jsonschema",Some(2),None,None)
),
List(SchemaCriterion("com.acme","json-event","jsonschema",Some(1),Some(0),Some(0))),
List(SchemaCriterion("com.acme","skip-event","jsonschema",Some(1),None,None))
),
Set(Step.Analyze)
)
}