-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
support for headers when using collector server to pull data from monitored clients. #835
base: master
Are you sure you want to change the base?
support for headers when using collector server to pull data from monitored clients. #835
Conversation
4821f9b
to
2df4524
Compare
I understand the goal. |
Ok. I agree that having it in the URL is a better option. I will change it that way. |
bb42ed7
to
afe32f5
Compare
Can someone review this please? |
ok, I will review |
A few remarks:
|
Thanks for the review. I already fixed all of them except the compilation error. I could not see any compilation issue. Can you tell me exactly where the compilation error is? Are you using java 8 ? |
The Maven's pom.xml uses the Java 6 syntax for source and targets Java 6. |
afe32f5
to
20425a4
Compare
20425a4
to
5a13a97
Compare
5a13a97
to
dce09ae
Compare
@evernat Can we do something on this? |
When using collector server to pull data from monitored clients, HTTP headers need to be supported. During registration with the collector server, monitored clients can now provide a map of headers. This will be used by collector server when calling the monitored clients. This scenario is useful for example in cloud foundry, when there are many instances of an application behind a load balancer and we want to monitor each application separately. For such scenarios, cloud foundry uses a header X-CF-APP-INSTANCE to identify the specific instance.
dce09ae
to
ebeb7f5
Compare
@evernat I just rebased from master. I know you might be busy but can you have a quick look on this so we can finally merge this PR. Thanks again. |
String[] headerKeyValue = header.split(":"); | ||
if (headerKeyValue.length == 2) { | ||
headersMap.put(headerKeyValue[0], headerKeyValue[1]); | ||
} |
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.
I think that this code will break X-Cf-App-Instance
for Cloud Foundry, which is like YOUR-APP-GUID:YOUR-INSTANCE-INDEX
. where YOUR-APP-GUID is application_id in System.getenv("VCAP_APPLICATION")
and YOUR-INSTANCE-INDEX is System.getenv("CF_INSTANCE_INDEX")
.
See https://docs.cloudfoundry.org/concepts/http-routing.html#app-instance-routing
and https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import org.apache.logging.log4j.util.Strings; |
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.
log4j may not be available in the webapp. And there is no need for this import.
private void parseHeader(String headers) { | ||
String[] headerParts = headers.split(";"); | ||
for (String header : headerParts) { | ||
String[] headerKeyValue = header.split(":"); |
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.
extract constants :
and ;
try { | ||
clone = new LinkedHashMap<String, List<URL>>( | ||
Parameters.getCollectorUrlsByApplications()); | ||
urlHeaders = Parameters.getCollectorHeadersByApplications(); |
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.
Clone is needed for headers like for URLs : new LinkedHashMap<>(Parameters.getCollectorHeadersByApplications());
And by definition, URL has no headers. Http request has headers.
new MonitoredApplicationHeader(urlHeaderForApplication)); | ||
} | ||
}); | ||
} |
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.
if and else could be merged
Hi, Thank You Julien |
Hi @evernat If necessary I can try to resume the branch to apply the remarks indicated, but I do not have access to it. |
During registration with the collector server, monitored clients
can now provid a map of headers. This will be used by collector server
when calling the monitored clients. This scenario is useful for example
in cloud foundry, when there are many instances of an application behind
a load balancer and we want to monitor each application separately. For
such scenarios, cloud foundry uses a header X-CF-APP-INSTANCE to identify
the specific instance.