Metrics logging in Springboot to Signalfx using management.metrics.export.signalfx - java

I am calling a third party API using the
org.springframework.web.client.RestTemplate
in my application.yml file
management.metrics.export.signalfx.enabled:true
we have 2 type of api call
/api/users/update
/api/users/byUserId/123
in the signalFX the first one is showing the count of call correctly but for the second one as the URI has the last 3 digit which changes based on the ID i count is not proper what we want is that irrespective of the ID the count should show the the number of time the second URI is called. we want some metrics customisation that we can apply.

The change that we did for this is that instead of call the restTemplate method with the URI having the ID we actually used
restTemplate.delete("/api/users/byUserId/{id}", Collections.singletonMap("id", id));
using this we were able to group the metrics with the URI /api/users/byUserId/{id}.

Related

Using of Cache component in order to save variables as global in Apache Camel

The goal is to make reusable a variable taken from the body in order to use it also for other transitions through the route. More specific, the intent was to obtain a token from the interface and using it for further accesses as in the image.Flow chart
The Requirements were:
Keeping the variable saved for a settable time.
Managing of the variable in order to obtain it when required.
In order to save it, it is possible to use a Cache component called Caffeine.
In the following, some useful key steps to accomplish the goal:
//get of the token from the cache
.setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_GET))
.setHeader(CaffeineConstants.KEY, constant("<KEY>")))
.toF("caffeine-cache://%s", cacheName?evictionType=TIME_BASED&expireAfterWriteTime=60) //options settings
.choice()
//if is not valid
.when(header(CaffeineConstants.ACTION_HAS_RESULT).isEqualTo(Boolean.FALSE))
.to("direct-some-external-service") //token obtaining
// save resulting token into cache
.setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_PUT))
.setHeader(CaffeineConstants.KEY, constant(constant(<KEY>")))
.toF("caffeine-cache://%s", cacheName?evictionType=TIME_BASED&expireAfterWriteTime=60)
.otherwise()
.end()
//some other steps
This is the procedure to save the token as global variable and make it available for 60 seconds.
Here a direct link of the documentation of this component:
https://camel.apache.org/components/latest/caffeine-cachecomponent.html#_examples
And one useful example:
https://danielblancocuadrado.medium.com/apache-camel-use-of-cache-with-caffeine-63a147aac785.

micrometer statistics for RestTemplate

I am trying to get metric for rest uri using micrometer. I read this, this, and also bunch of SO posts. After reading all these, I have a some questions about it.
For micrometer to work correctly uri should be parameterized(Reference). I assume this is only path variable not request params. Am i correct?
should we not use UriComponentsBuilder at all because we don't want to expand uri outside resttemplate and let resttemplate do it for us.
lets say if i use this restClient.getForObject( fooSvcUrl, FooBar.class, uriVariables );, does micrometer looks at fooSvcUrl and it should be parametertized at this point ?
I am asking this because if i do following, it will not work. AM I correct ? restClient.getForObject(UriComponentsBuilder.fromUriString(fooSvcUrl).buildAndExpand(uriVariables ).toUri() , FooBar.class);
I recently had to deal with all that stuff, so I can give you the following answers:
1. "Parametrized" means here that you apply placeholders into the URI, regardless of their position. Basically, you can parametrize everything in the URI - the scheme, the host, path variables and even query parameters, as long as you provide values to replace the placeholders.
As such, the following URIs will work when passed to RestTemplate:
https://www.foo.bar/baz/{id} with {"id":1}
https://www.foo.bar/baz?id={id} with {"id":1}
https://{host}/foo/{id}?target={target} with {"host":"www.foo.bar", "id":1, "target":"baz"}
2. You should not, especially if you would expect reserved symbols that would be put into your URI, as UriComponentsBuilder will try to encode them immediately which results in RestTemplate doing a double tap on the encoding, turning a non-fragment # first into a %23 and then into a %2523.
3. You are right, the URI should be parametrized when used as an argument for RestTemplate.getForObject, as the overloaded methods taking parameter value arguments will expand it before actually performing the request.

How can I set signing order by using DocusignApi

I want to set the signing order in an embedded signing envelope, which means that I have 2 recipients that sign the document one by one. On the sandbox UI that I can tick the checkbox to set the signing order and have 2 recipients there. The second one receives the email after the first one finished. I am wondering how can I implement the same logic by code.
I ve already tried to set the routing order but not what I want.
TemplateRole signer = new TemplateRole();
signer.setEmail(signerEmail);
signer.setName(signerName);
signer.clientUserId(String.valueOf(xxx));
signer.setRoleName("signer");
signer.setRoutingOrder("1");
TemplateRole signer1 = new TemplateRole();
signer1.setEmail("xxx");
signer1.setName("xxx");
signer1.clientUserId(String.valueOf(123));
signer1.setRoleName("signer1");
signer1.setRoutingOrder("2");
envelopeDefinition.setTemplateRoles(Arrays.asList(signer, signer1));
This is what I want:
enter image description here
Not this:
enter image description here
First, if you're referencing a template you'll need to set up the routing order there. When using using TemplateRoles, it's not necessary to set the routing order in the signer definition.
Second, in your code you're hitting signer.setRoutingOrder() twice, looks like you left the 1 off the second reference.
Third, I don't believe "0" is a valid position in the routing order. Try 1 & 2 instead.

Simple GET request with Facebooks API

I am currently taking a course in app development and I am trying to use Facebooks API for GET requests on certain events. My goal is the get a JSON file containing all comments made on a certain event.
However some events return only a an "id" key with an id number such as this:
{
"id": "116445769058883"
}
That happends with this event:
https://www.facebook.com/events/116445769058883/
However other events such as (https://www.facebook.com/events/1964003870536124/) : returns only the latest comment for some reason.
I am experementing with facebook explore API:
https://developers.facebook.com/tools/explorer/
This is the following GET requests that I have been using in the explorer:
GET -> /v.10/facebook-id/?fields=comments
Any ideas? It's really tricky to understand the response since both events have the privacy set to OPEN.
Starting from v2.4 of the API, the API is now declarative which means you'll need to specify what fields you want the API to return.
For example, if you want first name and second name of the user, then you make a GET request to /me?fields=first_name,last_name else you will only get back the default fields which are id and name.
If you want to see what fields are available for a given endpoint, use metadata field. e.g. GET /me?metadata=true

JMeter go back to previous sampler

I am quite new to jmeter, I am using it to load test an application. My current setup is good if running few threads at a time but gets problems when more users get connected.
Here's the scenario,
sample_1: request table data
sample_2: set table row with empty user column as used by current user
|
'-->post_process_beanshell: check if have error message
sample_3: do other stuff
Currently I am able to check if the 2nd sample has an error message, the question is how do I tell beanshell to go back to 1st sample when the 2nd sample has an error message?
I would recommend put your "sample_3" under If Controller like:
Loop Controller (define maximum number of n-tries)
sample_1
sample_2
post_process_beanshell
If Controller: condition ${JMeterThread.last_sample_ok}
sample_3
JMeterThread.last_sample_ok - is a pre-defined variable which returns "true" if previous sampler was successful and "false" if not so if your "sample_2" will fail - "sample_3" won't be executed and the whole sequence will start over
Assuming you want to keep going back to sampler1 until sampler2 beanshell returns true, use a While controller.
Stick both sampler1 and sampler2 in a while controller which is conditional on the result of your error check.

Categories

Resources