Skip to content

Commit 7916d90

Browse files
author
Brendan Doyle
committed
feedback
1 parent 5881bc6 commit 7916d90

File tree

8 files changed

+150
-52
lines changed

8 files changed

+150
-52
lines changed

common/scala/src/main/resources/application.conf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,18 @@ whisk {
438438
# uniqueName + displayName 253 (max pod name length in Kube)
439439
serdes-overhead = 6068 // 3034 bytes of metadata * 2 for extra headroom
440440

441+
# DEPRECATED, use store-blocking-result-level
441442
# Disables database store for blocking + successful activations
442443
# invocations made with `X-OW-EXTRA-LOGGING: on` header, will force the activation to be stored
443444
disable-store-result = false
444445

445-
# Disables database store for non-blocking + successful activations
446+
# Result level to store in db for blocking activations (STORE_ALWAYS, STORE_FAILURES, STORE_FAILURES_NOT_APPLICATION_ERRORS)
446447
# invocations made with `X-OW-EXTRA-LOGGING: on` header, will force the activation to be stored
447-
disable-store-non-blocking-result = false
448+
store-blocking-result-level = "STORE_ALWAYS"
449+
450+
# Result level to store in db for blocking activations (STORE_ALWAYS, STORE_FAILURES, STORE_FAILURES_NOT_APPLICATION_ERRORS)
451+
# invocations made with `X-OW-EXTRA-LOGGING: on` header, will force the activation to be stored
452+
store-non-blocking-result-level = "STORE_ALWAYS"
448453

449454
# Enable metadata logging of activations not stored in the database
450455
unstored-logs-enabled = false

common/scala/src/main/scala/org/apache/openwhisk/core/WhiskConfig.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ object ConfigKeys {
285285
val sharedPackageExecuteOnly = s"whisk.shared-packages-execute-only"
286286
val swaggerUi = "whisk.swagger-ui"
287287

288+
/* DEPRECATED: disableStoreResult is deprecated for storeBlockingResultLevel */
288289
val disableStoreResult = s"$activation.disable-store-result"
289-
val disableStoreNonBlockingResult = s"$activation.disable-store-non-blocking-result"
290+
val storeBlockingResultLevel = s"$activation.store-blocking-result-level"
291+
val storeNonBlockingResultLevel = s"$activation.store-non-blocking-result-level"
290292
val unstoredLogsEnabled = s"$activation.unstored-logs-enabled"
291293

292294
val apacheClientConfig = "whisk.apache-client"

common/scala/src/main/scala/org/apache/openwhisk/core/database/ActivationStore.scala

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.openwhisk.core.database
1919

2020
import java.time.Instant
21-
2221
import akka.actor.ActorSystem
2322
import akka.http.scaladsl.model.HttpRequest
2423
import spray.json.JsObject
@@ -33,9 +32,13 @@ import scala.concurrent.Future
3332
case class UserContext(user: Identity, request: HttpRequest = HttpRequest())
3433

3534
trait ActivationStore {
36-
35+
/* DEPRECATED: disableStoreResult config is now deprecated replaced with blocking activation store level */
3736
protected val disableStoreResultConfig = loadConfigOrThrow[Boolean](ConfigKeys.disableStoreResult)
38-
protected val disableStoreNonBlockingResultConfig = loadConfigOrThrow[Boolean](ConfigKeys.disableStoreNonBlockingResult)
37+
protected val storeBlockingResultLevelConfig =
38+
if (disableStoreResultConfig) ActivationStoreLevel.STORE_FAILURES
39+
else ActivationStoreLevel.valueOf(loadConfigOrThrow[String](ConfigKeys.storeBlockingResultLevel))
40+
protected val storeNonBlockingResultLevelConfig =
41+
ActivationStoreLevel.valueOf(loadConfigOrThrow[String](ConfigKeys.storeNonBlockingResultLevel))
3942
protected val unstoredLogsEnabledConfig = loadConfigOrThrow[Boolean](ConfigKeys.unstoredLogsEnabled)
4043

4144
/**
@@ -44,26 +47,26 @@ trait ActivationStore {
4447
* @param activation activation to store
4548
* @param isBlockingActivation is activation blocking
4649
* @param disableBlockingStore do not store activation if successful and blocking
47-
* @param disableNonBlockingStore do not store activation if successful and non-blocking
50+
* @param nonBlockingStoreLevel do not store activation if successful and non-blocking
4851
* @param context user and request context
4952
* @param transid transaction ID for request
5053
* @param notifier cache change notifier
5154
* @return Future containing DocInfo related to stored activation
5255
*/
5356
def storeAfterCheck(activation: WhiskActivation,
5457
isBlockingActivation: Boolean,
55-
disableBlockingStore: Option[Boolean],
56-
disableNonBlockingStore: Option[Boolean],
58+
blockingStoreLevel: Option[ActivationStoreLevel.Value],
59+
nonBlockingStoreLevel: Option[ActivationStoreLevel.Value],
5760
context: UserContext)(implicit transid: TransactionId,
5861
notifier: Option[CacheChangeNotification],
5962
logging: Logging): Future[DocInfo] = {
6063
if (context.user.limits.storeActivations.getOrElse(true) &&
6164
shouldStoreActivation(
62-
activation.response.isSuccess,
65+
activation,
6366
isBlockingActivation,
6467
transid.meta.extraLogging,
65-
disableBlockingStore.getOrElse(disableStoreResultConfig),
66-
disableNonBlockingStore.getOrElse(disableStoreNonBlockingResultConfig))) {
68+
blockingStoreLevel.getOrElse(storeBlockingResultLevelConfig),
69+
nonBlockingStoreLevel.getOrElse(storeNonBlockingResultLevelConfig))) {
6770

6871
store(activation, context)
6972
} else {
@@ -188,18 +191,29 @@ trait ActivationStore {
188191
* - an activation in debug mode
189192
* - activation stores is not disabled via a configuration parameter
190193
*
191-
* @param isSuccess is successful activation
194+
* @param activation to check
192195
* @param isBlocking is blocking activation
193196
* @param debugMode is logging header set to "on" for the invocation
194-
* @param disableBlockingStore is disable store configured
197+
* @param blockingStoreLevel level of activation status to store for blocking invocations
198+
* @param nonBlockingStoreLevel level of activation status to store for blocking invocations
195199
* @return Should the activation be stored to the database
196200
*/
197-
private def shouldStoreActivation(isSuccess: Boolean,
201+
private def shouldStoreActivation(activation: WhiskActivation,
198202
isBlocking: Boolean,
199203
debugMode: Boolean,
200-
disableBlockingStore: Boolean,
201-
disableNonBlockingStore: Boolean): Boolean = {
202-
!isSuccess || debugMode || (!isBlocking && !disableNonBlockingStore) || (isBlocking && !disableBlockingStore)
204+
blockingStoreLevel: ActivationStoreLevel.Value,
205+
nonBlockingStoreLevel: ActivationStoreLevel.Value): Boolean = {
206+
def shouldStoreOnLevel(storageLevel: ActivationStoreLevel.Value): Boolean = {
207+
storageLevel match {
208+
case ActivationStoreLevel.STORE_ALWAYS => true
209+
case ActivationStoreLevel.STORE_FAILURES => !activation.response.isSuccess
210+
case ActivationStoreLevel.STORE_FAILURES_NOT_APPLICATION_ERRORS =>
211+
!activation.response.isSuccess && !activation.response.isApplicationError
212+
}
213+
}
214+
215+
debugMode || (isBlocking && shouldStoreOnLevel(blockingStoreLevel)) || (!isBlocking && shouldStoreOnLevel(
216+
nonBlockingStoreLevel))
203217
}
204218
}
205219

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.openwhisk.core.database
19+
20+
object ActivationStoreLevel extends Enumeration {
21+
type ActivationStoreLevel = Value
22+
val STORE_ALWAYS, STORE_FAILURES, STORE_FAILURES_NOT_APPLICATION_ERRORS = Value
23+
24+
def valueOf(value: String): Value = {
25+
values
26+
.find(_.toString == value.toUpperCase())
27+
.getOrElse(throw new IllegalArgumentException(s"Invalid log level: $value"))
28+
}
29+
}

core/controller/src/main/scala/org/apache/openwhisk/core/controller/actions/PrimitiveActions.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,10 @@ protected[actions] trait PrimitiveActions {
600600
}
601601
}
602602

603-
activationStore.storeAfterCheck(activation, blockingComposition, None, None, context)(transid, notifier = None, logging)
603+
activationStore.storeAfterCheck(activation, blockingComposition, None, None, context)(
604+
transid,
605+
notifier = None,
606+
logging)
604607

605608
activation
606609
}

tests/src/test/scala/org/apache/openwhisk/core/controller/test/ActionsApiWithDbPollingTests.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
package org.apache.openwhisk.core.controller.test
1919

2020
import java.time.Instant
21-
2221
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport.sprayJsonUnmarshaller
2322
import akka.http.scaladsl.model.StatusCodes._
2423
import akka.http.scaladsl.model.headers.RawHeader
2524
import akka.http.scaladsl.server.Route
2625
import org.apache.openwhisk.core.controller.WhiskActionsApi
2726
import org.apache.openwhisk.core.controller.actions.ControllerActivationConfig
28-
import org.apache.openwhisk.core.database.UserContext
27+
import org.apache.openwhisk.core.database.{ActivationStoreLevel, UserContext}
2928
import org.apache.openwhisk.core.entity._
3029
import org.junit.runner.RunWith
3130
import org.scalatest.junit.JUnitRunner
@@ -79,7 +78,7 @@ class ActionsApiWithDbPollingTests extends ControllerTestCommon with WhiskAction
7978
// storing the activation in the db will allow the db polling to retrieve it
8079
// the test harness makes sure the activation id observed by the test matches
8180
// the one generated by the api handler
82-
storeActivation(activation, false, false, false, context)
81+
storeActivation(activation, false, ActivationStoreLevel.STORE_ALWAYS, ActivationStoreLevel.STORE_ALWAYS, context)
8382
try {
8483
Post(s"$collectionPath/${action.name}?blocking=true") ~> Route.seal(routes(creds)) ~> check {
8584
status should be(OK)
@@ -114,7 +113,7 @@ class ActionsApiWithDbPollingTests extends ControllerTestCommon with WhiskAction
114113
// storing the activation in the db will allow the db polling to retrieve it
115114
// the test harness makes sure the activation id observed by the test matches
116115
// the one generated by the api handler
117-
storeActivation(activation, false, false, false, context)
116+
storeActivation(activation, false, ActivationStoreLevel.STORE_ALWAYS, ActivationStoreLevel.STORE_ALWAYS, context)
118117
try {
119118
Post(s"$collectionPath/${action.name}?blocking=true") ~> Route.seal(routes(creds)) ~> check {
120119
status should be(InternalServerError)

0 commit comments

Comments
 (0)