Advanced Configuration

Authentication

User authentication

You can provide your user credentials using the MONITORING_USER and MONITORING_PASSWORD default environment variables:

AuthProviderBuilder.OAuth2()

.env();

Or using your custom environment variables:

AuthProviderBuilder.OAuth2()

.env("CUSTOM_MONITORING_USER", "CUSTOM_MONITORING_PASSWORD");

Or you can provide a path to a file that contains your Smart Trading user credentials.

AuthProviderBuilder.OAuth2()

.file("any/path/to/file");

The format of this file should be the following:

username=<username>

password=<password>

Note We do not recommend that you directly enter the password to ensure its safety.

Application user authentication

To use the Cloud Monitoring service through the application user, you have to get an application token at https://auth.sandbox.kollab.link.

  1. On the toolbar, click , and then click Manage Orginization Account. You are redirected to your Smart Trading Cloud profile.
  2. Go to Users and select an application in the Applications group.
  3. Create a new token or use an existing token. After you click Reset and download credentials, you get the credentials.stcc file that contains the application token.
  4. Specify the token as follows:
  5. MonitoringServiceClient.create()

    .withCredentials(AuthProviderBuilder.applicationToken()

    .token("tokengoeshere"))

    .build();

    - or -

    Provide a token using the MONITORING_APP_KEY environment variable:

    AuthProviderBuilder.applicationToken().env();

    - or -

    Use a custom environment variable:

    AuthProviderBuilder.applicationToken().env("CUSTOM_MONITORING_APP_KEY");

    - or -

    Provide a path to a file that contains the application token:

    AuthProviderBuilder.applicationToken().file("apathtothefile");

Default Configuration

To create the MonitoringServiceClient with a default configuration, use the defaultConfig method:

MonitoringServiceClient.defaultConfig()

If you use the default configuration (the defaultConfig method), the authentication in the Cloud Monitoring service is performed using the MONITORING_APP_KEY environment variable and the client with the following HTTP configuration is created:

  • SSL enabled
  • Connect, socket, connectionRequest timeouts and connection TTL set to 30s
  • 100 maximum connections

You can change the HTTP client configuration or create your custom client.

HTTP Client Configuration

The Cloud Monitoring service client uses the Apache HttpClient. You can change the default configuration or provide your custom pre-configured CloseableHttpClient. The following are the examples that you can use to change the default HTTP client configuration, as well as to change timeout settings.

MonitoringServiceClient.create()

.withHttpClient(HttpClientBuilder.defaultBuilder()

.httpTimeouts(120))

.build();

You can configure a request (for example, provide additional header) using a separate method:

MonitoringServiceClient.create()

.withRequestConfig(RequestConfig.custom()

.setConnectionRequestTimeout(10)

.build())

.build();

You can also create a new HTTP client. Note that in this case, the RequestConfig from the example above will override the defaultRequestConfig of the HTTP client.

The following is an example of the new pre-configured client:

MonitoringServiceClient.create().withHttpClient(HttpClientBuilder.custom(

HttpClientBuilder.create()

.setConnectionTimeToLive(20, TimeUnit.SECONDS)

.evictIdleConnections(10, TimeUnit.SECONDS)

.evictExpiredConnections()

.setMaxConnPerRoute(20)

.setMaxConnTotal(150)

.build()))

.build();

If you have complex network configuration, you can provide a custom base URL, for example:

MonitoringServiceClient.create().serviceUrl("https://monitoring.sandbox.kollab.link");