Search in sources :

Example 1 with PerformanceMetric

use of io.confluent.rest.annotations.PerformanceMetric in project kafka-rest by confluentinc.

the class TopicsResource method list.

@GET
@PerformanceMetric("topics.list+v2")
@ResourceName("api.v2.topics.list")
public void list(@Suspended AsyncResponse asyncResponse) {
    TopicManager topicManager = topicManagerProvider.get();
    CompletableFuture<List<String>> response = topicManager.listLocalTopics().thenApply(topics -> topics.stream().map(Topic::getName).collect(Collectors.toList()));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : TopicManager(io.confluent.kafkarest.controllers.TopicManager) List(java.util.List) Topic(io.confluent.kafkarest.entities.Topic) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 2 with PerformanceMetric

use of io.confluent.rest.annotations.PerformanceMetric in project kafka-rest by confluentinc.

the class ProduceAction method produce.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.produce.produce-to-topic")
@ResourceName("api.v3.produce.produce-to-topic")
public void produce(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, MappingIterator<ProduceRequest> requests) throws Exception {
    if (requests == null) {
        throw Errors.invalidPayloadException("Null input provided. Data is required.");
    }
    ProduceController controller = produceControllerProvider.get();
    streamingResponseFactory.from(requests).compose(request -> produce(clusterId, topicName, request, controller)).resume(asyncResponse);
}
Also used : PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) ProduceRequest(io.confluent.kafkarest.entities.v3.ProduceRequest) SerializationException(org.apache.kafka.common.errors.SerializationException) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) StacklessCompletionException(io.confluent.kafkarest.exceptions.StacklessCompletionException) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) ProduceRequestHeader(io.confluent.kafkarest.entities.v3.ProduceRequest.ProduceRequestHeader) Function(java.util.function.Function) Inject(javax.inject.Inject) NullNode(com.fasterxml.jackson.databind.node.NullNode) RateLimitExceededException(io.confluent.kafkarest.ratelimit.RateLimitExceededException) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) ProduceRequestData(io.confluent.kafkarest.entities.v3.ProduceRequest.ProduceRequestData) Objects.requireNonNull(java.util.Objects.requireNonNull) Duration(java.time.Duration) ProduceResponseData(io.confluent.kafkarest.entities.v3.ProduceResponse.ProduceResponseData) Collector(java.util.stream.Collector) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RegisteredSchema(io.confluent.kafkarest.entities.RegisteredSchema) BadRequestException(io.confluent.kafkarest.exceptions.BadRequestException) ProducerMetricsRegistry(io.confluent.kafkarest.ProducerMetricsRegistry) ExecutorService(java.util.concurrent.ExecutorService) EmbeddedFormat(io.confluent.kafkarest.entities.EmbeddedFormat) SchemaManager(io.confluent.kafkarest.controllers.SchemaManager) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) ProduceController(io.confluent.kafkarest.controllers.ProduceController) ProduceResult(io.confluent.kafkarest.entities.ProduceResult) AsyncResponse(javax.ws.rs.container.AsyncResponse) DoNotRateLimit(io.confluent.kafkarest.ratelimit.DoNotRateLimit) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) Instant(java.time.Instant) Suspended(javax.ws.rs.container.Suspended) ByteString(com.google.protobuf.ByteString) ProducerMetrics(io.confluent.kafkarest.ProducerMetrics) StreamingResponseFactory(io.confluent.kafkarest.response.StreamingResponseFactory) Errors(io.confluent.kafkarest.Errors) ProduceResponse(io.confluent.kafkarest.entities.v3.ProduceResponse) Optional(java.util.Optional) RecordSerializer(io.confluent.kafkarest.controllers.RecordSerializer) ProduceResponseThreadPool(io.confluent.kafkarest.resources.v3.V3ResourcesModule.ProduceResponseThreadPool) Collections(java.util.Collections) ProduceController(io.confluent.kafkarest.controllers.ProduceController) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)

Example 3 with PerformanceMetric

use of io.confluent.rest.annotations.PerformanceMetric in project kafka-rest by confluentinc.

the class ListAllBrokersConfigsAction method listBrokersConfigs.

@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.brokers.configs.list")
@ResourceName("api.v3.brokers-configs.list")
public void listBrokersConfigs(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) {
    BrokerConfigManager resolvedBrokerConfigManager = brokerConfigManager.get();
    CompletableFuture<ListBrokerConfigsResponse> response = brokerManager.get().listBrokers(clusterId).thenCompose(brokers -> resolvedBrokerConfigManager.listAllBrokerConfigs(clusterId, brokers.stream().map(Broker::getBrokerId).collect(Collectors.toList())).thenApply(configs -> ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "brokers", "-", "configs")).build()).setData(configs.values().stream().flatMap(brokerConfigs -> brokerConfigs.stream().sorted(Comparator.comparing(BrokerConfig::getBrokerId))).map(brokerConfig -> BrokerConfigsResource.toBrokerConfigData(brokerConfig, crnFactory, urlFactory)).collect(Collectors.toList())).build())));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Inject(javax.inject.Inject) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) Objects.requireNonNull(java.util.Objects.requireNonNull) BrokerConfig(io.confluent.kafkarest.entities.BrokerConfig) Broker(io.confluent.kafkarest.entities.Broker) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) AsyncResponse(javax.ws.rs.container.AsyncResponse) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) BrokerManager(io.confluent.kafkarest.controllers.BrokerManager) Comparator(java.util.Comparator) BrokerConfigDataList(io.confluent.kafkarest.entities.v3.BrokerConfigDataList) Broker(io.confluent.kafkarest.entities.Broker) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 4 with PerformanceMetric

use of io.confluent.rest.annotations.PerformanceMetric in project kafka-rest by confluentinc.

the class ConsumerLagsResource method listConsumerLags.

@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.consumer-lags.list")
@ResourceName("api.v3.consumer-lags.list")
public void listConsumerLags(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId) {
    CompletableFuture<ListConsumerLagsResponse> response = consumerLagManager.get().listConsumerLags(clusterId, consumerGroupId).thenApply(lags -> {
        if (lags.isEmpty()) {
            throw new NotFoundException("Consumer lags not found.");
        }
        return lags;
    }).thenApply(lags -> ListConsumerLagsResponse.create(ConsumerLagDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "lags")).build()).setData(lags.stream().map(this::toConsumerLagData).sorted(Comparator.comparing(ConsumerLagData::getLag).reversed().thenComparing(ConsumerLagData::getTopicName).thenComparing(ConsumerLagData::getPartitionId)).collect(Collectors.toList())).build()));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : PathParam(javax.ws.rs.PathParam) ConsumerLagManager(io.confluent.kafkarest.controllers.ConsumerLagManager) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) GetConsumerLagResponse(io.confluent.kafkarest.entities.v3.GetConsumerLagResponse) Inject(javax.inject.Inject) ConsumerLag(io.confluent.kafkarest.entities.ConsumerLag) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) Resource(io.confluent.kafkarest.entities.v3.Resource) Objects.requireNonNull(java.util.Objects.requireNonNull) ConsumerLagData(io.confluent.kafkarest.entities.v3.ConsumerLagData) ListConsumerLagsResponse(io.confluent.kafkarest.entities.v3.ListConsumerLagsResponse) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) AsyncResponse(javax.ws.rs.container.AsyncResponse) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) ConsumerLagDataList(io.confluent.kafkarest.entities.v3.ConsumerLagDataList) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) NotFoundException(javax.ws.rs.NotFoundException) Comparator(java.util.Comparator) NotFoundException(javax.ws.rs.NotFoundException) ConsumerLagData(io.confluent.kafkarest.entities.v3.ConsumerLagData) ListConsumerLagsResponse(io.confluent.kafkarest.entities.v3.ListConsumerLagsResponse) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 5 with PerformanceMetric

use of io.confluent.rest.annotations.PerformanceMetric in project schema-registry by confluentinc.

the class SchemasResource method getSchemas.

@GET
@Operation(summary = "Get the schemas.", responses = { @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend " + "data store\n") })
@PerformanceMetric("schemas.get-schemas")
public List<Schema> getSchemas(@Parameter(description = "Filters results by the respective subject prefix") @DefaultValue("") @QueryParam("subjectPrefix") String subjectPrefix, @Parameter(description = "Whether to return soft deleted schemas") @DefaultValue("false") @QueryParam("deleted") boolean lookupDeletedSchema, @Parameter(description = "Whether to return latest schema versions only for each matching subject") @DefaultValue("false") @QueryParam("latestOnly") boolean latestOnly, @Parameter(description = "Pagination offset for results") @DefaultValue("0") @QueryParam("offset") int offset, @Parameter(description = "Pagination size for results. Ignored if negative") @DefaultValue("-1") @QueryParam("limit") int limit) {
    Iterator<Schema> schemas;
    List<Schema> filteredSchemas = new ArrayList<>();
    String errorMessage = "Error while getting schemas for prefix " + subjectPrefix;
    try {
        schemas = schemaRegistry.getVersionsWithSubjectPrefix(subjectPrefix, lookupDeletedSchema, latestOnly);
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException(errorMessage, e);
    } catch (SchemaRegistryException e) {
        throw Errors.schemaRegistryException(errorMessage, e);
    }
    int fromIndex = offset;
    int toIndex = limit > 0 ? offset + limit : Integer.MAX_VALUE;
    int index = 0;
    while (schemas.hasNext() && index < toIndex) {
        Schema schema = schemas.next();
        if (index >= offset) {
            filteredSchemas.add(schema);
        }
        index++;
    }
    return filteredSchemas;
}
Also used : Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) ArrayList(java.util.ArrayList) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException) SchemaString(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)17 Path (javax.ws.rs.Path)11 GET (javax.ws.rs.GET)10 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)9 Operation (io.swagger.v3.oas.annotations.Operation)9 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)8 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)8 ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)8 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)7 POST (javax.ws.rs.POST)6 Produces (javax.ws.rs.Produces)6 Objects.requireNonNull (java.util.Objects.requireNonNull)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Inject (javax.inject.Inject)5 Provider (javax.inject.Provider)5 PathParam (javax.ws.rs.PathParam)5 AsyncResponse (javax.ws.rs.container.AsyncResponse)5 Suspended (javax.ws.rs.container.Suspended)5 AsyncResponses (io.confluent.kafkarest.resources.AsyncResponses)4 Collectors (java.util.stream.Collectors)4