How to separate metrics per endpoint using compojure - clojure

I have enabled metrics on Compojure using metrics-clojure-ring
(def app
(->
(wrap-defaults myapp api-defaults)
(expose-metrics-as-json)
(instrument)
))
but the metrics come out for all api's combined. is there a way to instrument per endpoint?

What exactly do you mean with instrumenting per endpoint? The metrics are combined on the /metrics endpoint for every endpoint. The underlying library (Coda Hale metrics) does that for you.
If you only want one metric on an endpoint you can select one key from the all-metrics hash map. E.g., create a route for /metrics/<metric-name> and only select the metric-name key from all-metrics and return that. If you really want to only track one metric instead of all at once, I think you have to fork the Coda Hale code and change the implementation.
Let me know if this helps. I might not have understood your question.

Related

Google Stackdriver - How can I show the logs of multiple containers in one view?

I am currently using Google Stackdriver (the new layout!) to investigate my logging. In my case there are three services communicating between each other. I'd love to see their communication between each other in the form of my INFO logging in the most convenient way possible.
FooService > BarService > SnickerService
Status Quo
Currently I am only able to see the log of one of either services. So I started to open three browser tabs and having all three mentioned service logs opened. Now I figure out a timestamp/range where the FooService started calling BarService.
This timerange I apply to the other remaining two services.
That way I have a overview how the process is being distributed among those services.
This way to do it however is super awkward to setup every time
This leads me to the question if I can bring the logging of three containers into one Stackdriver view?
In the log query I see this field (example FooService)
resource.labels.pod_name="fooservice-bd4c9bf4d-nv4k2"
Questions
Is there a way to have a AND operation here?
Is there also a way to "search" for pods? At the moment I always have to dive into my Workloads and dig for the pod id (example above: bd4c9bf4d-nv4k2) so I can use it in the query. By doing so I would be way faster just clicking View Logs in the Google Cloud Console. So this can't be much of a fast way imho.
You can use 2 operators
: is the contain operator
() is a group operator
With : you can search on partial name. Use this resource.labels.pod_name: "fooservice" matches all the fooservice pod name.
With () you can group values or comparison, like this ("foo" OR "bar")
If you put all together
resource.labels.pod_name: ("fooservice" OR "barservice")
-> This filter allows you to filter on the pod_name which contains the values "fooservice" OR "barservice"

Get all items in DynamoDB with API Gateway's Mapping Template

Is there a simple way to retrieve all items from a DynamoDB table using a mapping template in an API Gateway endpoint? I usually use a lambda to process the data before returning it but this is such a simple task that a Lambda seems like an overkill.
I have a table that contains data with the following format:
roleAttributeName roleHierarchyLevel roleIsActive roleName
"admin" 99 true "Admin"
"director" 90 true "Director"
"areaManager" 80 false "Area Manager"
I'm happy with getting the data, doesn't matter the representation as I can later transform it further down in my code.
I've been looking around but all tutorials explain how to get specific bits of data through queries and params like roles/{roleAttributeName} but I just want to hit roles/ and get all items.
All you need to do is
create a resource (without curly braces since we dont need a particular item)
create a get method
use Scan instead of Query in Action while configuring the integration request.
Configurations as follows :
enter image description here
now try test...you should get the response.
to try it out on postman deploy the api first and then use the provided link into postman followed by your resource name.
API Gateway allows you to Proxy DynamoDB as a service. Here you have an interesting tutorial on how to do it (you can ignore the part related to index to make it work).
To retrieve all the items from a table, you can use Scan as the action in API Gateway. Keep in mind that DynamoDB limits the query sizes to 1MB either for Scan and Query actions.
You can also limit your own query before it is automatically done by using the Limit parameter.
AWS DynamoDB Scan Reference

boto3 list_services() with order

I made aws auto deployment code with boto3 library.
In my code, get all service list and use it.
I have to get lastest service. But I think there is no order option.
(https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.list_services)
Sometimes, first element is latest service.
But sometimes, old service is placed in first element.
Is there any option or way to get latest service?
Thanks.
The list_services method does not return details of individual services. It simply lists the services, and returns you a list of identifiers (ARNs) for those services.
To get more details of a given service, you can use describe_services. This allows you to get details of up to 10 services at a time.
So, take the list of service identifiers that you get back from list_services, and pass it to describe_services (with at most 10 service identifiers). Something like this (untested):
list_response = client.list_services(
cluster='xyz',
launchType='EC2'
)
desc_response = client.describe_services(
cluster='xyz',
services=list_response['serviceArns']
)
Note that you will have to do pagination using maxResults / nextToken if there are a lot of results.

AWS Ruby SDK filtering

I'm refactoring a Ruby framework that is calling describe_instances and then filtering the response for just the VPC names.
It seems a waste of bandwidth to pull down the data for every instance in the region and then filter out the VPC ids in this way.
When I look at the documentation for filtering server side I see posts doing things like applying filters for all instances of type xx and so on.
What I want to do is pull down all VPC ids as a unique list.
Can anyone point me at an example of how to do that?
Thanks in advance
Never mind, I discovered the describe_vpcs endpoint:
def get_vpc_ids
ec2_object.describe_vpcs[:vpcs].each do |vpc|
#vpc_list.push(vpc[:vpc_id])
end
#vpc_list.uniq!
end

Query AWS SNS Endpoints by User Data

Simple question, but I suspect it doesn't have a simple or easy answer. Still, worth asking.
We're creating an implementation for push notifications using AWS with our Web Server running on EC2, sending messages to a queue on SQS, which is dealt with using Lambda, which is sent finally to SNS to be delivered to the iOS/Android apps.
The question I have is this: is there a way to query SNS endpoints based on the custom user data that you can provide on creation? The only way I see to do this so far is to list all the endpoints in a given platform application, and then search through that list for the user data I'm looking for... however, a more direct approach would be far better.
Why I want to do this is simple: if I could attach a User Identifier to these Device Endpoints, and query based on that, I could avoid completely having to save the ARN to our DynamoDB database. It would save a lot of implementation time and complexity.
Let me know what you guys think, even if what you think is that this idea is impractical and stupid, or if searching through all of them is the best way to go about this!
Cheers!
There isn't the ability to have a "where" clause in ListTopics. I see two possibilities:
Create a new SNS topic per user that has some identifiable id in it. So, for example, the ARN would be something like "arn:aws:sns:us-east-1:123456789:know-prefix-user-id". The obvious downside is that you have the potential for a boat load of SNS topics.
Use a service designed for this type of usage like PubNub. Disclaimer - I don't work for PubNub or own stock but have successfully used it in multiple projects. You'll be able to target one or many users this way.
According the the [AWS documentation][1] if you try and create a new Platform Endpoint with the same User Data you should get a response with an exception including the ARN associated with the existing PlatformEndpoint.
It's definitely not ideal, but it would be a round about way of querying the User Data Endpoint attributes via exception.
//Query CustomUserData by exception
CreatePlatformEndpointRequest cpeReq = new CreatePlatformEndpointRequest().withPlatformApplicationArn(applicationArn).withToken("dummyToken").withCustomUserData("username");
CreatePlatformEndpointResult cpeRes = client.createPlatformEndpoint(cpeReq);
You should get an exception with the ARN if an endpoint with the same withCustomUserData exists.
Then you just use that ARN and away you go.