You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/09/24 14:24:24 UTC
[incubator-openwhisk] branch master updated: Configure a default
throughput value for CosmosDB (#4037)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new ed73de6 Configure a default throughput value for CosmosDB (#4037)
ed73de6 is described below
commit ed73de694c999acf5f08f9a2109b4de2d810ed4e
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Sep 24 19:54:16 2018 +0530
Configure a default throughput value for CosmosDB (#4037)
---
common/scala/src/main/resources/application.conf | 7 ++++---
.../core/database/cosmosdb/CosmosDBArtifactStore.scala | 3 +++
.../cosmosdb/CosmosDBArtifactStoreProvider.scala | 2 +-
.../whisk/core/database/cosmosdb/CosmosDBSupport.scala | 8 +++++++-
.../database/cosmosdb/CosmosDBArtifactStoreTests.scala | 17 +++++++++++++++++
5 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/common/scala/src/main/resources/application.conf b/common/scala/src/main/resources/application.conf
index 0b92573..b2bcbc6 100644
--- a/common/scala/src/main/resources/application.conf
+++ b/common/scala/src/main/resources/application.conf
@@ -150,9 +150,10 @@ whisk {
# CosmosDB related configuration
# For example:
# cosmosdb {
- # endpoint = # Endpoint URL like https://<account>.documents.azure.com:443/
- # key = # Access key
- # db = # Database name
+ # endpoint = # Endpoint URL like https://<account>.documents.azure.com:443/
+ # key = # Access key
+ # db = # Database name
+ # throughput = 1000 # Throughput configure for each collection within this db
#}
# transaction ID related configuration
diff --git a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
index 9292d17..ca3acba 100644
--- a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
@@ -74,6 +74,9 @@ class CosmosDBArtifactStore[DocumentAbstraction <: DocumentSerializer](protected
private val countToken = createToken("count")
private val putAttachmentToken = createToken("putAttachment", read = false)
+ //Clone the returned instance as these are mutable
+ def documentCollection(): DocumentCollection = new DocumentCollection(collection.toJson)
+
override protected[core] implicit val executionContext: ExecutionContext = system.dispatcher
override protected[database] def put(d: DocumentAbstraction)(implicit transid: TransactionId): Future[DocInfo] = {
diff --git a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreProvider.scala b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreProvider.scala
index d3943bf..869baf0 100644
--- a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreProvider.scala
+++ b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreProvider.scala
@@ -33,7 +33,7 @@ import whisk.core.entity.{DocumentReader, WhiskActivation, WhiskAuth, WhiskEntit
import scala.reflect.ClassTag
-case class CosmosDBConfig(endpoint: String, key: String, db: String)
+case class CosmosDBConfig(endpoint: String, key: String, db: String, throughput: Int = 1000)
case class ClientHolder(client: AsyncDocumentClient) extends Closeable {
override def close(): Unit = client.close()
diff --git a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBSupport.scala b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBSupport.scala
index d963094..f32fc87 100644
--- a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBSupport.scala
+++ b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBSupport.scala
@@ -57,7 +57,7 @@ private[cosmosdb] trait CosmosDBSupport extends RxObservableImplicits with Cosmo
}
}
.getOrElse {
- client.createCollection(database.getSelfLink, newDatabaseCollection, null).blockingResult()
+ client.createCollection(database.getSelfLink, newDatabaseCollection, dbOptions).blockingResult()
}
}
@@ -72,6 +72,12 @@ private[cosmosdb] trait CosmosDBSupport extends RxObservableImplicits with Cosmo
defn
}
+ private def dbOptions = {
+ val opts = new RequestOptions
+ opts.setOfferThroughput(config.throughput)
+ opts
+ }
+
private def newDatabase = {
val databaseDefinition = new Database
databaseDefinition.setId(config.db)
diff --git a/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala b/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala
index bb45c72..5558b6d 100644
--- a/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala
+++ b/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala
@@ -26,4 +26,21 @@ import whisk.core.database.test.behavior.ArtifactStoreBehavior
@RunWith(classOf[JUnitRunner])
class CosmosDBArtifactStoreTests extends FlatSpec with CosmosDBStoreBehaviorBase with ArtifactStoreBehavior {
override protected def maxAttachmentSizeWithoutAttachmentStore = 1.MB
+
+ behavior of "CosmosDB Setup"
+
+ it should "be configured with default throughput" in {
+ //Trigger loading of the db
+ val stores = Seq(entityStore, authStore, activationStore)
+ stores.foreach { s =>
+ val doc = s.asInstanceOf[CosmosDBArtifactStore[_]].documentCollection()
+ val offer = client
+ .queryOffers(s"SELECT * from c where c.offerResourceId = '${doc.getResourceId}'", null)
+ .blockingOnlyResult()
+ .get
+ withClue(s"Collection ${doc.getId} : ") {
+ offer.getThroughput shouldBe storeConfig.throughput
+ }
+ }
+ }
}