-
Notifications
You must be signed in to change notification settings - Fork 224
Test: Add Influx db coverage #4284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
53e9599
3504d22
2d0a8e9
3fc9391
34a2b3c
aa507fc
8ecb203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.prebid.server.functional.model.response.influx | ||
|
|
||
| class InfluxResponse { | ||
|
|
||
| List<InfluxResult> results | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.prebid.server.functional.model.response.influx | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
|
|
||
| class InfluxResult { | ||
|
|
||
| @JsonProperty("statement_id") | ||
| Integer statementId | ||
| List<Series> series | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.prebid.server.functional.model.response.influx | ||
|
|
||
| class Series { | ||
|
|
||
| String name | ||
| List<String> columns | ||
| List<List<String>> values | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package org.prebid.server.functional.testcontainers | |
|
|
||
| import org.prebid.server.functional.testcontainers.container.NetworkServiceContainer | ||
| import org.prebid.server.functional.util.SystemProperties | ||
| import org.testcontainers.containers.InfluxDBContainer | ||
| import org.testcontainers.containers.MySQLContainer | ||
| import org.testcontainers.containers.Network | ||
| import org.testcontainers.containers.localstack.LocalStackContainer | ||
|
|
@@ -34,6 +35,14 @@ class Dependencies { | |
| .withInitScript("org/prebid/server/functional/db_psql_schema.sql") | ||
| .withNetwork(network) | ||
|
|
||
| static final InfluxDBContainer influxdbContainer = new InfluxDBContainer<>(DockerImageName.parse("influxdb:1.8.10")) | ||
| .withUsername("prebid") | ||
| .withUsername("prebid") | ||
|
||
| .withPassword("prebid") | ||
| .withAuthEnabled(false) | ||
| .withDatabase("prebid") | ||
osulzhenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .withNetwork(network) | ||
|
|
||
| static final NetworkServiceContainer networkServiceContainer = new NetworkServiceContainer(MOCKSERVER_VERSION) | ||
| .withNetwork(network) | ||
|
|
||
|
|
@@ -44,13 +53,13 @@ class Dependencies { | |
| localStackContainer = new LocalStackContainer(DockerImageName.parse("localstack/localstack:s3-latest")) | ||
| .withNetwork(network) | ||
| .withServices(S3) | ||
| Startables.deepStart([networkServiceContainer, mysqlContainer, localStackContainer]).join() | ||
| Startables.deepStart([networkServiceContainer, mysqlContainer, localStackContainer, influxdbContainer]).join() | ||
| } | ||
| } | ||
|
|
||
| static void stop() { | ||
| if (IS_LAUNCH_CONTAINERS) { | ||
| [networkServiceContainer, mysqlContainer, localStackContainer].parallelStream() | ||
| [networkServiceContainer, mysqlContainer, localStackContainer, influxdbContainer].parallelStream() | ||
| .forEach({ it.stop() }) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package org.prebid.server.functional.testcontainers | ||
|
|
||
| import org.testcontainers.containers.InfluxDBContainer | ||
| import org.testcontainers.containers.MySQLContainer | ||
| import org.testcontainers.containers.PostgreSQLContainer | ||
|
|
||
|
|
@@ -10,6 +11,7 @@ import static org.prebid.server.functional.util.CurrencyUtil.DEFAULT_CURRENCY | |
|
|
||
| final class PbsConfig { | ||
|
|
||
| static final String PREBID_DATABASE = "prebid" | ||
| private static final String DB_ACCOUNT_QUERY = """ | ||
| SELECT JSON_MERGE_PATCH(JSON_OBJECT('id', uuid, | ||
| 'status', status, | ||
|
|
@@ -101,6 +103,20 @@ LIMIT 1 | |
| ].asImmutable() | ||
| } | ||
|
|
||
| static Map<String, String> getInfluxContainer(InfluxDBContainer influx = Dependencies.influxdbContainer) { | ||
| ["metrics.influxdb.enabled" : "true", | ||
| "metrics.influxdb.prefix" : "influx.metric.", | ||
| "metrics.influxdb.host" : influx.getNetworkAliases().get(0), | ||
| "metrics.influxdb.port" : influx.getExposedPorts().get(0) as String, | ||
| "metrics.influxdb.protocol" : "http", | ||
| "metrics.influxdb.database" : PREBID_DATABASE, | ||
| "metrics.influxdb.auth" : "prebid:prebid", | ||
|
||
| "metrics.influxdb.interval" : "1", | ||
| "metrics.influxdb.connectTimeout": "5000", | ||
| "metrics.influxdb.readTimeout" : "100", | ||
| ].asImmutable() | ||
| } | ||
|
|
||
| static Map<String, String> getPostgreSqlConfig(PostgreSQLContainer postgres = Dependencies.postgresqlContainer) { | ||
| ["settings.database.type" : "postgres", | ||
| "settings.database.host" : postgres.getNetworkAliases().get(0), | ||
|
|
@@ -145,7 +161,7 @@ LIMIT 1 | |
| "currency-converter.external-rates.refresh-period-ms" : "900000"] | ||
| } | ||
|
|
||
| static Map<String,String> getTargetingConfig() { | ||
| static Map<String, String> getTargetingConfig() { | ||
| ["settings.targeting.truncate-attr-chars": '255'] | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package org.prebid.server.functional.tests | ||
|
|
||
| import org.prebid.server.functional.model.AccountStatus | ||
| import org.prebid.server.functional.model.config.AccountConfig | ||
| import org.prebid.server.functional.model.db.Account | ||
| import org.prebid.server.functional.model.request.auction.BidRequest | ||
| import org.prebid.server.functional.service.PrebidServerException | ||
| import org.prebid.server.functional.service.PrebidServerService | ||
| import org.prebid.server.functional.util.PBSUtils | ||
|
|
||
| import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED | ||
|
|
||
| class InfluxDBSpec extends BaseSpec { | ||
|
|
||
| private static final PrebidServerService pbsServiceWithEnforceValidAccount | ||
| = pbsServiceFactory.getService(["settings.enforce-valid-account": true as String]) | ||
|
||
| private static final Closure<String> REJECT_INVALID_ACCOUNT_METRIC = { accountId -> | ||
| "influx.metric.account.${accountId}.requests.rejected.invalid-account" | ||
| } | ||
|
||
|
|
||
| def "PBS should reject request with error and metrics when inactive account"() { | ||
| given: "Inactive account id" | ||
| def accountId = PBSUtils.randomNumber | ||
| def account = new Account(uuid: accountId, config: new AccountConfig(status: AccountStatus.INACTIVE)) | ||
| accountDao.save(account) | ||
|
|
||
| and: "Default basic BidRequest with inactive account id" | ||
| def bidRequest = BidRequest.defaultBidRequest.tap { | ||
| site.publisher.id = accountId | ||
| } | ||
|
||
|
|
||
| when: "PBS processes auction request" | ||
| pbsServiceWithEnforceValidAccount.sendAuctionRequest(bidRequest) | ||
|
|
||
| then: "PBS should reject the entire auction" | ||
| def exception = thrown(PrebidServerException) | ||
| assert exception.statusCode == UNAUTHORIZED.code() | ||
| assert exception.responseBody == "Account $accountId is inactive" | ||
|
|
||
| and: "PBs should emit proper metric" | ||
| PBSUtils.waitUntil({ | ||
| pbsServiceWithEnforceValidAccount.sendInfluxMetricsRequest() | ||
| .containsKey(REJECT_INVALID_ACCOUNT_METRIC(bidRequest.accountId) as String) | ||
| }) | ||
| def influxMetricsRequest = pbsServiceWithEnforceValidAccount.sendInfluxMetricsRequest() | ||
| assert influxMetricsRequest[REJECT_INVALID_ACCOUNT_METRIC(bidRequest.accountId) as String] == 1 | ||
|
||
| } | ||
|
|
||
| def "PBS shouldn't reject request with error and metrics when active account"() { | ||
| given: "Inactive account id" | ||
| def accountId = PBSUtils.randomNumber | ||
| def account = new Account(uuid: accountId, config: new AccountConfig(status: AccountStatus.ACTIVE)) | ||
| accountDao.save(account) | ||
|
|
||
| and: "Default basic BidRequest with inactive account id" | ||
| def bidRequest = BidRequest.defaultBidRequest.tap { | ||
| site.publisher.id = accountId | ||
| } | ||
|
|
||
| when: "PBS processes auction request" | ||
| def response = pbsServiceWithEnforceValidAccount.sendAuctionRequest(bidRequest) | ||
|
|
||
| then: "Bid response should contain seatBid" | ||
| assert response.seatbid.size() == 1 | ||
|
|
||
| and: "PBs shouldn't emit metric" | ||
| PBSUtils.waitUntil({ | ||
| !pbsServiceWithEnforceValidAccount.sendInfluxMetricsRequest() | ||
| .containsKey(REJECT_INVALID_ACCOUNT_METRIC(bidRequest.accountId) as String) | ||
| }) | ||
| } | ||
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.