bziobrowski commented on code in PR #14226: URL: https://github.com/apache/pinot/pull/14226#discussion_r1807937451
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotApplicationQuotaRestletResource.java: ########## @@ -0,0 +1,163 @@ +/** + * 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.pinot.controller.api.resources; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiKeyAuthDefinition; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.Authorization; +import io.swagger.annotations.SecurityDefinition; +import io.swagger.annotations.SwaggerDefinition; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.helix.HelixAdmin; +import org.apache.helix.model.HelixConfigScope; +import org.apache.helix.model.builder.HelixConfigScopeBuilder; +import org.apache.pinot.controller.api.exception.ControllerApplicationException; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.core.auth.Actions; +import org.apache.pinot.core.auth.Authorize; +import org.apache.pinot.core.auth.TargetType; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.pinot.spi.utils.CommonConstants.SWAGGER_AUTHORIZATION_KEY; + + +@Api(tags = Constants.DATABASE_TAG, authorizations = {@Authorization(value = SWAGGER_AUTHORIZATION_KEY)}) +@SwaggerDefinition(securityDefinition = @SecurityDefinition(apiKeyAuthDefinitions = { + @ApiKeyAuthDefinition(name = HttpHeaders.AUTHORIZATION, in = ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = + SWAGGER_AUTHORIZATION_KEY, description = + "The format of the key is ```\"Basic <token>\" or \"Bearer " + + "<token>\"```"), @ApiKeyAuthDefinition(name = CommonConstants.APPLICATION, in = + ApiKeyAuthDefinition.ApiKeyLocation.HEADER, key = CommonConstants.APPLICATION, description = + "Application context passed through http header. If no context is provided 'default' application " + + "context will be considered.") +})) +@Path("/") +public class PinotApplicationQuotaRestletResource { + public static final Logger LOGGER = LoggerFactory.getLogger(PinotApplicationQuotaRestletResource.class); + + @Inject + PinotHelixResourceManager _pinotHelixResourceManager; + + /** + * API to get application quota configs. Will return null if application quotas are not defined + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/applicationQuotas") + @Authorize(targetType = TargetType.CLUSTER, action = Actions.Cluster.GET_APPLICATION_QUERY_QUOTA) + @ApiOperation(value = "Get all application qps quotas", notes = "Get all application qps quotas") + public Map<String, Double> getApplicationQuotas(@Context HttpHeaders httpHeaders) { + Map<String, Double> quotas = _pinotHelixResourceManager.getApplicationQuotas(); + if (quotas != null) { + return quotas; + } + + HelixConfigScope scope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster( + _pinotHelixResourceManager.getHelixClusterName()).build(); + HelixAdmin helixAdmin = _pinotHelixResourceManager.getHelixAdmin(); + String defaultQuota = + helixAdmin.getConfig(scope, Collections.singletonList(CommonConstants.Helix.APPLICATION_MAX_QUERIES_PER_SECOND)) + .getOrDefault(CommonConstants.Helix.APPLICATION_MAX_QUERIES_PER_SECOND, null); + + quotas = new HashMap<>(); + quotas.put(CommonConstants.DEFAULT_APPLICATION, defaultQuota != null ? Double.parseDouble(defaultQuota) : null); + return quotas; + } + + /** + * API to get application quota configs. Will return null if application quotas are not defined + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/applicationQuotas/{appName}") + @Authorize(targetType = TargetType.CLUSTER, action = Actions.Cluster.GET_APPLICATION_QUERY_QUOTA) + @ApiOperation(value = "Get application qps quota", notes = "Get application qps quota") + public Double getApplicationQuota(@Context HttpHeaders httpHeaders, @PathParam("appName") String appName) { + if (!appName.equals(extractApplicationFromHttpHeaders(httpHeaders))) { Review Comment: I don't know. This check was taken from db quota restlet resource. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org