Multiple labels in Prometheus query - devops

I am trying to get an array of label and values inside one JSON from Prometheus.
I have a metric
http_server_requests_seconds_count{method="POST", service="application", status="200", uri="/v1/rest/clients/ids"}
Using query:
count(sum(rate(http_server_requests_seconds_count[5m])) by (method,uri)) by (uri)
I get:
"result" : [
{
"metric" : {
"uri" : "/v1/rest/clients/ids"
},
"value" : [
1.662458065998E9,
"1"
]
},
However, I would like to get more labels in the metric field, such as service, status, uri.
For example:
"metric" : {
"uri" : "/v1/rest/clients/ids",
"service" : "application",
"status" : "200",
},
Either value aggregation over each unique label

I have adjusted my query as follows
round(sum(delta(http_server_requests_seconds_count[5m])) by (service, status, uri) >0 )

Related

Using aws-api-gateway models, how can I require an object contains AT LEAST 1 valid key

I am using API gateway's request validation. Here is my model so far:
{
"type" : "object",
"required" : [ "dc", "uid", "data" ],
"properties" : {
"dc" : {
"type" : "string"
},
"uid" : {
"type" : "string"
},
"data" : {
"type" : "object"
}
},
"title" : "MyApi"
}
So similar to the required function, I want to ensure that the data object has at least one key in a list I define [a, b, c, whatever]
If this is not possible, is there a way to at least prevent a null value from being sent? I tried "nullable": false but AWS said that was an invalid model schema.
Setting minProperties to '1' may work. See https://swagger.io/docs/specification/data-models/data-types/
Can (should) data be strongly typed? If so you could use composition, inheritance, and polymorphism to indicate that the data is a defined schemas. See https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

How to query specific branch build number from Jenkins JSON Remote Access API

Within the browser for my jenkins job I'm running the following query.
lastStableBuild/api/json?pretty=true&tree=actions[buildsByBranchName[*[*]]]
Results from the above query
{
"_class" : "hudson.model.FreeStyleBuild",
"actions" : [
{
"_class" : "hudson.model.CauseAction"
},
{
},
{
"_class" : "jenkins.metrics.impl.TimeInQueueAction"
},
{
},
{
"_class" : "hudson.plugins.git.util.BuildData",
"buildsByBranchName" : {
"my-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 587,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
"my-other-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 1373,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
I would like to be able to narrow it down to just the build number like you would get with
/lastSuccessBuild/buildNumber
using the api but I would settle for just everything inside of the branch name key so that I wouldn't have to loop through all branches and compare the name. I'm assuming I can narrow it down more where I have my "*" specified but can't figure out the right syntax to use.
I got that info from here instead.
tree=actions[lastBuiltRevision[*,branch[*]]]
Either way, if you want the branch info, from inside the buildsByBranchName section of the tree, you will have to query it as I did above.
If you don't mind getting your answer back in xml, xpath works very well.
For the url:
/lastStableBuild/api/xml?xpath=//buildsByBranchName&wrapper=meep
Creates an xml that looks like:
<meep>
<buildsByBranchName>
...
</buildsByBranchName>
</meep>
And will be populated with the buildsByBranchName (NOTE: there may be more than one if there are multiple git remotes, hence the need for a wrapper) for the specified last successful build of the job specified in the url. You can substitute anything for the word "meep", that will become the wrapper object for the newly created xml object.

How to check elasticsearch tokens after running a query in Rails?

My problem is the following:
I run an elasticsearch query in a rails app using specific settings to my index and my search analyzer, the problem is that it doesnt return any results in the app, in the other hand when i try to run it directly from my elasticsearch docker, i have tokens returned. If i use these tokens in my app query, i get results...
so this is my elasticsearch query:
curl -XGET 'localhost:9200/development-stoot-services/_analyze?analyzer=search_francais' -d 'cours de guitare'
{"tokens":[{"token":"cour","start_offset":0,"end_offset":5,"type":"<ALPHANUM>","position":1},{"token":"guitar","start_offset":9,"end_offset":16,"type":"<ALPHANUM>","position":3}]}
here is the query from my rails app to elasticsearch:
query = {
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-26T10:27:19+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "cours de guitare",
"default_operator" : "AND",
"fields" : [
"title",
"description",
"brand",
"category_name"
]
}
}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
},
"sort" : [
{
"created_at" : "desc"
}
]
}
the last query does not return any result, but if i try a query with the tokens returned by elasticsearch ('cour', 'guitar') i have expected results. So i guess there is a problem between rails and elasticsearch that i dont find...
Can anyone help on that ?
Try to modify your query like this, i.e. you need to specify the search_francais analyzer in your query_string in order to analyze cours de guitare the same way you did with the _analyze endpoint:
...
{
"query_string" : {
"query" : "cours de guitare",
"default_operator" : "AND",
"analyzer": "search_francais", <--- add this line
"fields" : [
"title",
"description",
"brand",
"category_name"
]
}
},
...

Escaping # at symbol in Ruby Elastic Search gem?

I have the following code in the custom ES 'where' wrapper method
filter: { term: params }
Then we have a sample ES document that contains:
"emails" => { "email" => "johndoe#email.com" }
It is returned when my search is:
query.where("emails.email" => "johndoe")
but I get no results when:
query.where("emails.email" => "johndoe#email.com")
It seems like I have to escape at symbol somehow when using ES gem?
It's probably because your field is analyzed using the default standard analyzer and is thus tokenized at the # sign.
You can see what ES has indexed by running the command below:
curl -XGET 'localhost:9200/_analyze?analyzer=standard&pretty' -d 'johndoe#email.com'
And the result is
{
"tokens" : [ {
"token" : "johndoe",
"start_offset" : 0,
"end_offset" : 7,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "email.com",
"start_offset" : 8,
"end_offset" : 17,
"type" : "<ALPHANUM>",
"position" : 2
} ]
}
As you can see, your email field has been tokenized as two different tokens and that's probably why searching for johndoe works, while searching for the full email address doesn't.
There are a few ways out from here, but one way that would work is to create your own analyzer based on a pattern_capture token filter and use it as index_analyzer for your emails.email field.
{
"settings" : {
"analysis" : {
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"patterns" : [ "([^#]+)", "(\\p{L}+)", "(\\d+)", "#(.+)" ]
}
},
"analyzer" : {
"email" : {
"tokenizer" : "uax_url_email",
"filter" : [ "email", "lowercase", "unique" ]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email" <-- use the analyzer here
}
}
}
}
}
At indexing time, that analyzer will produce all of the following tokens, which will allow you to search for any parts of your email address:
johndoe#email.com
johndoe
email.com
email
com

Neo4j cypher with parameters returns success but doesn't create anything?

If I send this:
{
"query" : "MATCH (p) WHERE p.id={id} CREATE (c {props}) CREATE UNIQUE p-[r:CHILD]->c",
"params" : {
"id" : ["{0000-0000-0000-0000}","{0000-0000-0000-0000}","{0000-0000-0000-0004}"],
"props" : [ {
"id" : "{0000-0000-0000-0004}",
"type": 48,
"title" : "TestNode"
},{
"id" : "{0000-0000-0000-0005}",
"type": 49,
"title" : "TestNode"
},{
"id" : "{0000-0000-0000-0006}",
"type": 49,
"title" : "TestNode"
}]
}
}
Via the restful cypher api, I get back "success" but nothing was created. If I send through this:
{
"query" : "MATCH (p) WHERE p.id={id} CREATE (c {props}) CREATE UNIQUE p-[r:CHILD]->c",
"params" : {
"id" : "{0000-0000-0000-0000}",
"props" : [ {
"id" : "{0000-0000-0000-0001}",
"type": 48,
"title" : "TestNode"
},{
"id" : "{0000-0000-0000-0002}",
"type": 49,
"title" : "TestNode"
} ]
}
}
It creates two children of 0000-0000-0000-0000 as expected. So something about the way I'm specifying two arrays isn't working.
I was hoping to be able to create large tree structures by essentially specifying parent ID/child to create parameters. The other option is that I use the latter style cypher and the transactional endpoint... but I'm just not sure what I'm doing wrong in the first one. Any advice much appreciated.
You probably need to do:
MATCH (p) WHERE p.id IN {id}
CREATE (c {props})
CREATE UNIQUE (p)-[r:CHILD]->(c)
The = operator is an exact comparison.

Resources