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

support for headers when using collector server to pull data from monitored clients. #835

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

batigoal82
Copy link

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.

@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch from 4821f9b to 2df4524 Compare May 16, 2019 10:42
@evernat
Copy link
Member

evernat commented May 23, 2019

I understand the goal.
At the moment, it will only work for 1 minute, because headers are not stored for later data collects in CollectorServer.collectWithoutErrors() and headers are not stored on disk either in case of collector server restart.
And I would probably prefer to have headers in the URL, than java serialization, when registering the app instance.

@batigoal82
Copy link
Author

batigoal82 commented Jun 6, 2019

Ok. I agree that having it in the URL is a better option. I will change it that way.

@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch 3 times, most recently from bb42ed7 to afe32f5 Compare June 26, 2019 09:28
@batigoal82
Copy link
Author

Can someone review this please?

@evernat
Copy link
Member

evernat commented Jun 27, 2019

ok, I will review

@evernat
Copy link
Member

evernat commented Jun 29, 2019

A few remarks:

  • It does not compile.
  • You don't need to keep the method CollectorServer.collectForApplicationWithoutErrors(String, List)
  • Rename Parameters.getCollectorUrlsHeadersByApplication() to Parameters.getCollectorHeadersByApplications() with s at the end
  • Add a method CollectorServer.getHeadersByApplication(String). The headers you have saved may be useful.
  • You don't need the appHeader parameter in CollectorServer.removeCollectorApplicationNodes(...) and it is probably not given in the request anyway. Use getHeadersByApplication(appName) instead.
  • new RemoteCollector(String, List) is used in collectForApplicationForAction and new LabradorRetriever(URL) is used in doJmxValue and doProxy. These use cases should have the headers too.

@batigoal82
Copy link
Author

A few remarks:

  • It does not compile.
  • You don't need to keep the method CollectorServer.collectForApplicationWithoutErrors(String, List)
  • Rename Parameters.getCollectorUrlsHeadersByApplication() to Parameters.getCollectorHeadersByApplications() with s at the end
  • Add a method CollectorServer.getHeadersByApplication(String). The headers you have saved may be useful.
  • You don't need the appHeader parameter in CollectorServer.removeCollectorApplicationNodes(...) and it is probably not given in the request anyway. Use getHeadersByApplication(appName) instead.
  • new RemoteCollector(String, List) is used in collectForApplicationForAction and new LabradorRetriever(URL) is used in doJmxValue and doProxy. These use cases should have the headers too.

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 ?

@evernat
Copy link
Member

evernat commented Jul 1, 2019

The Maven's pom.xml uses the Java 6 syntax for source and targets Java 6.
But sorry for "not compile" remark; my IDE has rejected some diffs from 835.diff and I did not checked. Changing the Fuzz factor gives a better results. There is no more problem with that.

@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch from afe32f5 to 20425a4 Compare July 1, 2019 19:05
batigoal82 added a commit to batigoal82/javamelody that referenced this pull request Jul 1, 2019
@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch from 20425a4 to 5a13a97 Compare July 29, 2019 12:11
batigoal82 added a commit to batigoal82/javamelody that referenced this pull request Jul 29, 2019
@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch from 5a13a97 to dce09ae Compare July 29, 2019 12:27
@batigoal82
Copy link
Author

@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.
@batigoal82 batigoal82 force-pushed the support-header-for-monitored-clients-fix branch from dce09ae to ebeb7f5 Compare September 22, 2019 19:56
@batigoal82
Copy link
Author

@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]);
}
Copy link
Member

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;
Copy link
Member

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(":");
Copy link
Member

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();
Copy link
Member

@evernat evernat Jul 17, 2021

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));
}
});
}
Copy link
Member

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

@ricetrac
Copy link

ricetrac commented Sep 8, 2022

Hi,
I'm very interested in this subject, because I have the same need to identify each instance of my web application through the use of headers.
Is it possible to advance this Pull Request?

Thank You

Julien

@ricetrac
Copy link

Hi @evernat

If necessary I can try to resume the branch to apply the remarks indicated, but I do not have access to it.
Thank You.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants