Skip to content
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

Revamp Filters, Support for HTTP Filters, AccessLog Filters #71

Merged
merged 66 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8952324
added http access log
ajay-jalgaonkar Jul 19, 2024
0f99aca
added enableAccessLogs flag
ajay-jalgaonkar Jul 19, 2024
60c54a2
Added GrpcAccessLogFilter
ajay-jalgaonkar Jul 19, 2024
bf39538
added default true for access log filters
ajay-jalgaonkar Jul 19, 2024
df8105b
added default true for access log filters
ajay-jalgaonkar Jul 19, 2024
40d375e
using arraylist instead of linkedlist
ajay-jalgaonkar Jul 19, 2024
68c472e
author
ajay-jalgaonkar Jul 19, 2024
30da9b9
added example
ajay-jalgaonkar Jul 19, 2024
1f686fd
added example
ajay-jalgaonkar Jul 19, 2024
845bb19
added access log separate for logging
ajay-jalgaonkar Jul 20, 2024
e7e5fc7
added access log separate for logging
ajay-jalgaonkar Jul 20, 2024
0fb3927
added access log separate for logging
ajay-jalgaonkar Jul 20, 2024
c3f72e0
added common filters interfaces for http and grpc
ajay-jalgaonkar Jul 23, 2024
09b8a45
added filter configs
ajay-jalgaonkar Jul 23, 2024
a8f033e
added filter configs
ajay-jalgaonkar Jul 23, 2024
f5303c8
uncommented
ajay-jalgaonkar Jul 23, 2024
91ff9ad
template changes
ajay-jalgaonkar Jul 23, 2024
b293189
template changes
ajay-jalgaonkar Jul 23, 2024
0072103
template changes
ajay-jalgaonkar Jul 23, 2024
bf4c094
template changes
ajay-jalgaonkar Jul 23, 2024
8305794
template changes
ajay-jalgaonkar Jul 23, 2024
9b90533
template changes
ajay-jalgaonkar Jul 23, 2024
0d3f242
template changes
ajay-jalgaonkar Jul 23, 2024
fab2122
template changes
ajay-jalgaonkar Jul 23, 2024
3bf1922
template changes
ajay-jalgaonkar Jul 23, 2024
af09b38
template changes
ajay-jalgaonkar Jul 23, 2024
a1c1c48
changed creation of requestparams
ajay-jalgaonkar Jul 23, 2024
1fe6d27
template
ajay-jalgaonkar Jul 23, 2024
401f0a0
template
ajay-jalgaonkar Jul 23, 2024
5f6e76e
template
ajay-jalgaonkar Jul 23, 2024
c40e70d
template
ajay-jalgaonkar Jul 23, 2024
eb157b2
renamed filters
ajay-jalgaonkar Jul 23, 2024
a5ab4dd
adding removing default impls
ajay-jalgaonkar Jul 23, 2024
cd9439f
renamed
ajay-jalgaonkar Jul 23, 2024
01602ba
renamed
ajay-jalgaonkar Jul 23, 2024
02c8946
template
ajay-jalgaonkar Jul 23, 2024
f6ce472
rename
ajay-jalgaonkar Jul 23, 2024
bb985c2
rename
ajay-jalgaonkar Jul 23, 2024
8cb8ac1
extended AccessLogHttpFilter
ajay-jalgaonkar Jul 23, 2024
7122c2e
extended AccessLogHttpFilter
ajay-jalgaonkar Jul 23, 2024
f29d4a3
extended AccessLogHttpFilter
ajay-jalgaonkar Jul 24, 2024
0372965
added stringbuilder in AccessLogGrpcFilter
ajay-jalgaonkar Jul 24, 2024
f5a71dc
no change
ajay-jalgaonkar Jul 24, 2024
c6b69df
renaming
ajay-jalgaonkar Jul 24, 2024
d181572
fucntion name updated
ajay-jalgaonkar Jul 24, 2024
b965c83
uncommented
ajay-jalgaonkar Jul 24, 2024
8801ca8
Split Request & Request Params
kingster Jul 24, 2024
a0f93cf
docs
kingster Jul 24, 2024
3ef92b3
Update mvn template files
kingster Jul 24, 2024
44a11d2
Update hello_world_config.yml
kingster Jul 24, 2024
d12fe01
docs
kingster Jul 24, 2024
56fdef2
fixes
kingster Jul 24, 2024
cf26e64
docs
kingster Jul 24, 2024
38a2b4a
adding MDC, updated logging pattern
ajay-jalgaonkar Jul 25, 2024
87ed452
FilterInteceptor
kingster Jul 25, 2024
497c035
Update HttpFilterInterceptor.java
kingster Jul 25, 2024
07abf21
tests
kingster Jul 25, 2024
ed035f0
Revert "adding MDC, updated logging pattern"
kingster Jul 25, 2024
1f62b1f
Merge branch 'http-filters' into http-accesslog
kingster Jul 25, 2024
1e5d26e
updated pattern
ajay-jalgaonkar Jul 25, 2024
50d5f76
added healthcheck in dashboard
ajay-jalgaonkar Jul 25, 2024
888fab5
author
ajay-jalgaonkar Jul 25, 2024
1c9601c
author
ajay-jalgaonkar Jul 25, 2024
04c6d6d
author
ajay-jalgaonkar Jul 25, 2024
8a91c93
minor rename
kingster Jul 25, 2024
c18d63b
minor fixes
kingster Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/java/com/flipkart/gjex/core/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import java.util.List;
import java.util.Map;

import com.flipkart.gjex.core.filter.grpc.GrpcFilter;
import com.flipkart.gjex.core.job.ScheduledJob;
import org.glassfish.jersey.server.ResourceConfig;

import io.dropwizard.metrics5.health.HealthCheck;
import com.flipkart.gjex.core.filter.Filter;
import com.flipkart.gjex.core.service.Service;
import com.flipkart.gjex.core.setup.Bootstrap;
import com.flipkart.gjex.core.setup.Environment;
Expand Down Expand Up @@ -59,7 +59,7 @@ public interface Bundle<T extends GJEXConfiguration, U extends Map> {
* Returns Filter instances loaded by this Bundle
* @return List containing Filter instances
*/
List<Filter> getFilters();
List<GrpcFilter> getGrpcFilters();

/**
* Returns HealthCheck instances loaded by this Bundle
Expand Down
40 changes: 2 additions & 38 deletions core/src/main/java/com/flipkart/gjex/core/GJEXConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import com.flipkart.gjex.core.config.DashboardService;
import com.flipkart.gjex.core.config.GrpcConfig;
import com.flipkart.gjex.core.config.Tracing;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Data
public class GJEXConfiguration {

@Valid
Expand All @@ -51,45 +53,7 @@ public class GJEXConfiguration {
@JsonProperty("ScheduledJobs.executorThreads")
private int scheduledJobExecutorThreads;

public GrpcConfig getGrpc() {
return grpc;
}

public void setGrpc(GrpcConfig grpc) {
this.grpc = grpc;
}

public ApiService getApiService() {
return apiService;
}

public void setApiService(ApiService apiService) {
this.apiService = apiService;
}

public DashboardService getDashboardService() {
return dashboardService;
}

public void setDashboardService(DashboardService dashboardService) {
this.dashboardService = dashboardService;
}

public Tracing getTracing() {
return tracing;
}

public void setTracing(Tracing tracing) {
this.tracing = tracing;
}

public int getScheduledJobExecutorThreads() {
return scheduledJobExecutorThreads;
}

public void setScheduledJobExecutorThreads(int scheduledJobExecutorThreads) {
this.scheduledJobExecutorThreads = scheduledJobExecutorThreads;
}

@Override
public String toString() {
Expand Down
44 changes: 5 additions & 39 deletions core/src/main/java/com/flipkart/gjex/core/config/ApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
package com.flipkart.gjex.core.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.flipkart.gjex.core.filter.http.HttpFilterConfig;
import lombok.Data;

import javax.validation.constraints.Min;

@Data
public class ApiService {

@Min(1)
Expand All @@ -38,43 +41,6 @@ public class ApiService {
@JsonProperty("scheduledexecutor.threadpool.size")
private int scheduledExecutorThreadPoolSize;

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

public int getAcceptors() {
return acceptors;
}

public void setAcceptors(int acceptors) {
this.acceptors = acceptors;
}

public int getSelectors() {
return selectors;
}

public void setSelectors(int selectors) {
this.selectors = selectors;
}

public int getWorkers() {
return workers;
}

public void setWorkers(int workers) {
this.workers = workers;
}

public int getScheduledExecutorThreadPoolSize() {
return scheduledExecutorThreadPoolSize;
}

public void setScheduledExecutorThreadPoolSize(int scheduledExecutorThreadPoolSize) {
this.scheduledExecutorThreadPoolSize = scheduledExecutorThreadPoolSize;
}
@JsonProperty("filterConfig")
private HttpFilterConfig httpFilterConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.flipkart.gjex.core.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class DashboardService {

@JsonProperty("service.port")
Expand All @@ -30,36 +32,4 @@ public class DashboardService {

@JsonProperty("service.workers")
private int workers;

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

public int getAcceptors() {
return acceptors;
}

public void setAcceptors(int acceptors) {
this.acceptors = acceptors;
}

public int getSelectors() {
return selectors;
}

public void setSelectors(int selectors) {
this.selectors = selectors;
}

public int getWorkers() {
return workers;
}

public void setWorkers(int workers) {
this.workers = workers;
}
}
28 changes: 5 additions & 23 deletions core/src/main/java/com/flipkart/gjex/core/config/GrpcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package com.flipkart.gjex.core.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.flipkart.gjex.core.filter.grpc.GrpcFilterConfig;
import lombok.Data;

@Data
public class GrpcConfig {

@JsonProperty("server.port")
Expand All @@ -28,27 +31,6 @@ public class GrpcConfig {
@JsonProperty("server.executorThreads")
private int executorThreads = 0;

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

public int getMaxMessageSize() {
return maxMessageSize;
}

public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}

public int getExecutorThreads() {
return executorThreads;
}

public void setExecutorThreads(int executorThreads) {
this.executorThreads = executorThreads;
}
@JsonProperty("filterConfig")
private GrpcFilterConfig grpcFilterConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, should be filterConfig simply

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

}
10 changes: 2 additions & 8 deletions core/src/main/java/com/flipkart/gjex/core/config/Tracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class Tracing {

@NotNull
@JsonProperty("collector.endpoint")
private String collectorEndpoint;

public String getCollectorEndpoint() {
return collectorEndpoint;
}

public void setCollectorEndpoint(String collectorEndpoint) {
this.collectorEndpoint = collectorEndpoint;
}
}
79 changes: 26 additions & 53 deletions core/src/main/java/com/flipkart/gjex/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,37 @@
*/
package com.flipkart.gjex.core.filter;

import com.google.protobuf.GeneratedMessageV3;
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import com.flipkart.gjex.core.logging.Logging;

/**
* A Filter interface for processing Request, Request-Headers, Response and Response-Headers around gRPC method invocation
*
* @author regu.b
* A Filter interface for processing Request, Request-Headers, Response and Response-Headers
* around gRPC and HTTP method invocation
*
* @param <Req> Proto V3 message
* @param <Res> Proto V3 message
* @author regu.b
*/
public interface Filter<Req extends GeneratedMessageV3, Res extends GeneratedMessageV3> {
public abstract class Filter<Req, Res, M> {

/** Lifecycle methods for cleaning up resources used by this Filter*/
public void destroy(){}

/** Lifecycle methods for initializing and cleaning up resources used by this Filter*/
default void init() {}
default void destroy() {}
/**
* Call-back to decorate or inspect the Request body/message. This Filter cannot fail processing of the Request body and hence there is no support for indicating failure.
* This method should be viewed almost like a proxy for the Request body.
* @param req the Request body/message
* @param requestParams prams
*/
public void doProcessRequest(Req req, RequestParams<M> requestParams){}

/**
* Function for creating an instance of this {@link Filter}
* Use only this function to get the {@link Filter} instance
*/
Filter<Req, Res> getInstance();
/**
* Call-back to decorate or inspect the Response headers. Implementations may use this method to set additional headers in the response.
* @param responseHeaders the Response Headers
*/
public void doProcessResponseHeaders(M responseHeaders) {}

/**
* Call-back to process Request headers and Filter out processing of the next incoming Request Proto V3 body/message.
* @param requestHeaders Request Headers
* @throws StatusRuntimeException thrown with suitable {@link Status} to indicate reason for failing the request
*/
default void doFilterRequest(ServerRequestParams serverRequestParams, Metadata requestHeaders) throws StatusRuntimeException{}

/**
* Call-back to decorate or inspect the Reauest Proto V3 body/message. This Filter cannot fail processing of the Request body and hence there is no support for indicating failure.
* This method should be viewed almost like a proxy for the Request body.
* @param request the Request Proto V3 body/message
*/
default void doProcessRequest(Req request) {}

/**
* Call-back to decorate or inspect the Response headers. Implementations may use this method to set additional headers in the response.
* @param responseHeaders the Response Headers
*/
default void doProcessResponseHeaders(Metadata responseHeaders) {}

/**
* Call-back to decorate or inspect the Response Proto V3 body/message. This Filter cannot fail processing of the Response body and hence there is no support for indicating failure.
* This method should be viewed almost like a proxy for the Response body.
* @param response the Response Proto V3 body/message
*/
default void doProcessResponse(Res response) {}

/**
* Returns array of {@link Key} identifiers for headers to be forwarded
* @return array of {@link Key}
*/
@SuppressWarnings("rawtypes")
default Metadata.Key[] getForwardHeaderKeys(){
return new Metadata.Key[] {};
}
/**
* Call-back to decorate or inspect the Response body/message. This Filter cannot fail processing of the Response body and hence there is no support for indicating failure.
* This method should be viewed almost like a proxy for the Response body.
* @param response the Response body/message
*/
public void doProcessResponse(Res response) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) The original author or authors
*
* Licensed 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 com.flipkart.gjex.core.filter;

import lombok.Builder;
import lombok.Getter;

/**
* Represents the parameters of a request within the GJEX framework.
* This class encapsulates common request parameters such as client IP, resource path,
* and any additional metadata associated with the request.
*
* @param <M> The type of the metadata associated with the request. This allows for flexibility
* in the type of metadata that can be attached to a request, making the class
* adaptable to various needs.
*
* @author ajay.jalgaonkar
*/
@Getter
@Builder
public class RequestParams<M> {
// IP address of the client making the request.
String clientIp;

// Path of the resource being requested.
String resourcePath;

// Metadata associated with the request, of generic type M.
M metadata;
}
Loading
Loading