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 9 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
42 changes: 2 additions & 40 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,46 +53,6 @@ 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() {
return "GJEXConfiguration{" +
Expand Down
43 changes: 4 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,11 @@
package com.flipkart.gjex.core.config;

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

import javax.validation.constraints.Min;

@Data
public class ApiService {

@Min(1)
Expand All @@ -38,43 +40,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("enableAccessLogs")
private boolean enableAccessLogs = true;
}
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;
}
}
27 changes: 4 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,9 @@
package com.flipkart.gjex.core.config;

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

@Data
public class GrpcConfig {

@JsonProperty("server.port")
Expand All @@ -28,27 +30,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("enableAccessLogs")
private boolean enableAccessLogs = true;
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.flipkart.gjex.core.filter;

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

/**
* Filter for logging grpc access log requests
* @author ajay.jalgaonkar
*
*/
public class GrpcAccessLogFilter <R extends GeneratedMessageV3,
S extends GeneratedMessageV3> implements Filter<R, S>, Logging {
private long startTime = 0;
private ServerRequestParams serverRequestParams;
@Override
public Filter<R,S> getInstance(){
return new GrpcAccessLogFilter<>();
}

@Override
public void doProcessRequest(R request) {
this.startTime = System.currentTimeMillis();
}

@Override
public void doFilterRequest(ServerRequestParams serverRequestParams, Metadata headers) {
this.serverRequestParams = serverRequestParams;
}

@Override
public void doProcessResponseHeaders(Metadata responseHeaders) {}

@Override
public void doProcessResponse(S response) {
String size = null;
if (response != null){
size = String.valueOf(response.getSerializedSize());
}
StringBuilder sb = new StringBuilder()
.append(serverRequestParams.getClientIp()).append(" ")
.append(serverRequestParams.getMethodName()).append(" ")
.append(size).append(" ")
.append(System.currentTimeMillis()-startTime);
error(sb.toString());
Copy link
Member

Choose a reason for hiding this comment

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

why error? here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added access-log separately and made it info

}
}
35 changes: 14 additions & 21 deletions core/src/main/java/com/flipkart/gjex/core/setup/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
*/
package com.flipkart.gjex.core.setup;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;
import io.dropwizard.metrics5.MetricRegistry;
import io.dropwizard.metrics5.jmx.JmxReporter;
import io.dropwizard.metrics5.jvm.BufferPoolMetricSet;
import io.dropwizard.metrics5.jvm.GarbageCollectorMetricSet;
import io.dropwizard.metrics5.jvm.MemoryUsageGaugeSet;
import io.dropwizard.metrics5.jvm.ThreadStatesGaugeSet;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flipkart.gjex.core.Application;
import com.flipkart.gjex.core.Bundle;
Expand All @@ -45,15 +28,25 @@
import com.flipkart.gjex.core.config.DefaultConfigurationFactoryFactory;
import com.flipkart.gjex.core.config.FileConfigurationSourceProvider;
import com.flipkart.gjex.core.filter.Filter;
import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;
import com.flipkart.gjex.core.job.ScheduledJob;
import com.flipkart.gjex.core.logging.Logging;
import com.flipkart.gjex.core.service.Service;
import com.flipkart.gjex.core.tracing.TracingSampler;
import com.flipkart.gjex.core.util.Pair;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.dropwizard.metrics5.MetricRegistry;
import io.prometheus.metrics.model.registry.PrometheusRegistry;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* The pre-start application container, containing services required to bootstrap a GJEX application
*
Expand Down Expand Up @@ -225,10 +218,10 @@ public void setConfigMap(U configMap) {
*/
public void run(Environment environment) throws Exception {
// Identify all Service implementations, start them and register for Runtime shutdown hook
services = new LinkedList<Service>();
filters = new LinkedList<Filter>();
tracingSamplers = new LinkedList<TracingSampler>();
scheduledJobs = new LinkedList<ScheduledJob>();
services = new ArrayList<>();
filters = new ArrayList<Filter>();
tracingSamplers = new ArrayList<TracingSampler>();
scheduledJobs = new ArrayList<ScheduledJob>();
// Set the HealthCheckRegsitry to the one initialized by the Environment
healthCheckRegistry = environment.getHealthCheckRegistry();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.flipkart.gjex.core.web.filter;

import com.flipkart.gjex.core.logging.Logging;

import javax.inject.Named;
import javax.inject.Singleton;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* Filter for logging http access log requests
* @author ajay.jalgaonkar
*
*/

@Singleton
@Named("HttpAccessLogFilter")
public class HttpAccessLogFilter implements Filter, Logging {
private long startTime;
@Override
public void init(FilterConfig filterConfig) throws ServletException {}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Copy link
Member

Choose a reason for hiding this comment

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

We should change the signature to match how the grpc filter has

public void doProcessRequest(R request)

and

public void doProcessResponse(S response)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

startTime = System.currentTimeMillis();
chain.doFilter(request, response);
StringBuilder sb = new StringBuilder();
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse){
HttpServletRequest httpServletRequest= (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
sb.append(httpServletRequest.getHeader("x-forwarded-for")).append(" ")
.append(httpServletRequest.getRequestURI()).append(" ")
.append(httpServletResponse.getStatus()).append(" ")
.append(httpServletResponse.getHeader("Content-Length")).append(" ");
} else {
sb.append("Did not get HTTP request").append(" ");
}
sb.append(request.getRemoteAddr()).append(" ");
sb.append(System.currentTimeMillis()-startTime);
error(sb.toString());
}

@Override
public void destroy() {

}
}
Loading
Loading