-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[New Scheduler]Implement FPCEntitlementProvider #5029
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 all commits
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,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.openwhisk.core.entitlement | ||
|
||
import scala.concurrent.Future | ||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.model.StatusCodes.TooManyRequests | ||
import org.apache.openwhisk.common.{Logging, TransactionId, UserEvents} | ||
import org.apache.openwhisk.core.WhiskConfig | ||
import org.apache.openwhisk.core.connector.{EventMessage, Metric} | ||
import org.apache.openwhisk.core.controller.RejectRequest | ||
import org.apache.openwhisk.core.entitlement.Privilege.ACTIVATE | ||
import org.apache.openwhisk.core.entity.{ControllerInstanceId, Identity} | ||
import org.apache.openwhisk.core.loadBalancer.LoadBalancer | ||
|
||
protected[core] class FPCEntitlementProvider( | ||
private val config: WhiskConfig, | ||
private val loadBalancer: LoadBalancer, | ||
private val controllerInstance: ControllerInstanceId)(implicit actorSystem: ActorSystem, logging: Logging) | ||
extends LocalEntitlementProvider(config, loadBalancer, controllerInstance) { | ||
|
||
override protected[core] def checkThrottles(user: Identity, right: Privilege, resources: Set[Resource])( | ||
implicit transid: TransactionId): Future[Unit] = { | ||
if (right == ACTIVATE) { | ||
val checks = resources.filter(_.collection.path == Collection.ACTIONS).map { res => | ||
loadBalancer.checkThrottle(user.namespace.name.toPath, res.fqname) | ||
} | ||
if (checks.contains(true)) { | ||
val metric = Metric("ConcurrentRateLimit", 1) | ||
UserEvents.send( | ||
eventProducer, | ||
EventMessage( | ||
s"controller${controllerInstance.asString}", | ||
metric, | ||
user.subject, | ||
user.namespace.name.toString, | ||
user.namespace.uuid, | ||
metric.typeName)) | ||
Future.failed(RejectRequest(TooManyRequests, "Too many requests")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be consistent with the other throttling rejections where it differentiates between per minute and concurrent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So now we only have one throttling limit that is the number of concurrent containers. |
||
} else Future.successful(()) | ||
} else Future.successful(()) | ||
} | ||
|
||
} | ||
|
||
private object FPCEntitlementProvider extends EntitlementSpiProvider { | ||
|
||
override def instance(config: WhiskConfig, loadBalancer: LoadBalancer, instance: ControllerInstanceId)( | ||
implicit actorSystem: ActorSystem, | ||
logging: Logging) = | ||
new FPCEntitlementProvider(config: WhiskConfig, loadBalancer: LoadBalancer, instance) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,9 @@ trait LoadBalancer { | |
|
||
/** Gets the size of the cluster all loadbalancers are acting in */ | ||
def clusterSize: Int = 1 | ||
|
||
/** Gets the throttling for given action. */ | ||
def checkThrottle(namespace: EntityPath, action: String): Boolean = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great if you share how this will work in a new load balancer. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this get used later? I don't see where this is needed in the child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, there was one metric for throttling in FPCEntitlementProvider, I will add that