How to search Grafana Loki by detected label containing space - filter

I have access to logs in Grafana Loki that I get using {namespace="my-app"} | json
A simplified example:
2023-02-03 09:03:34 {"level":"info","msg":"some message","some ID":"123"}
I want to filter when some ID is 123, something like
{namespace="my-app"} | json | some ID = "123"
^ this makes it break
It works for msg:
{namespace="my-app"} | json | msg = "some message"
It also works when I simply filter lines:
{namespace="my-app"} |= `"some ID":"123"`

Related

PowerAutomate - replace nth occurrence of character

I'm attempting to parse email body to excel file.
After some manipulations, my current output is an array, where each line is data related to a product.
[  
"Periods: 01.01.2023 - 01.02.2023 | Code: 111 | Code2: 1111 | product-name",  
"Periods: 01.01.2023 - 01.02.2023 | Code: 222 | Code2: 2222 | product-name2"
]
I need to replace the 3rd occurrence of " | " with " | Product: " , so i can get field Product before the product name.
I've tried to use Apply to each -> current item -> various ways to find 3rd occurrence and replace it, but can't succeed.
Any suggestion?
You should be able to loop through each item and perform a simple replace expression like thus ...
replace(item(), split(item(), ' | ')[3], concat('Product: ', split(item(), ' | ')[3]))
That should get you across the line. Of course, I'm basing my answer off the limited information you provided.

How can I add conditions on my jq response in bash?

I want write a script which is giving me the volumeId,instanceId and tags. But in tags just the "Name" is interest me.
I will elaborate.
today I am running with the next call
aws ec2 describe-volumes --filters Name=status,Values=available | jq -c '.Volumes[] | {State: .State, VolumeId: .VolumeId, Tags: .Tags}'
"State":"available","VolumeId":"vol-094c79bc5e641bd7e","Tags":[{"Key":"Name","Value":"Adi"},{"Key":"Team","Value":"SRE"}]}
2.{"State":"available","VolumeId":"vol-041485dd7394bbdd7","Tags":[{"Key":"Team","Value":"SRE"}]}
I want my response will include the just the tag "Name" and it's value.
If the tag "Name" does not exist , I want in my response just the "State","VolumeId".
For 1.State":"available","VolumeId":"vol-094c79bc5e641bd7e","Tags":[{"Key":"Name","Value":"Adi"}
For 2. {"State":"available","VolumeId":"vol-041485dd7394bbdd7"}
If you can live with "Tags": [] holding an empty array while still being present, a simple map(select(.Key == "Name")) will do:
jq -c '.Volumes[] | {State, VolumeId, Tags: (.Tags | map(select(.Key == "Name")))}'
{"State":"available","VolumeId":"vol-094c79bc5e641bd7e","Tags":[{"Key":"Name","Value":"Adi"}]}
{"State":"available","VolumeId":"vol-041485dd7394bbdd7","Tags":[]}
Demo
Otherwise you need to distinguish separately whether the field should be added or not. This can be achieved using an if statement:
jq -c '.Volumes[] | {State, VolumeId} + (
{Tags: (.Tags | map(select(.Key == "Name")))} | if .Tags == [] then {} else . end
)'
{"State":"available","VolumeId":"vol-094c79bc5e641bd7e","Tags":[{"Key":"Name","Value":"Adi"}]}
{"State":"available","VolumeId":"vol-041485dd7394bbdd7"}
Demo

yaml - Print key and value, if value meets consitions

Given the following yaml:
charts:
# repository with Helm charts for creation namespaces
path: ns
pathMonitoringPrometheus: prom
namespaces:
first:
description: "Description of first"
enabled: false
branch: master
bootstrapChart: bootstrap
syncAccessGroups: []
namespace:
role: k8s-role-of-first
istio: disabled
public: view
sources: []
second:
description: "Description of second"
enabled: false
branch: HEAD
bootstrapChart: bootstrap
namespace:
role: k8s-role-of-second
istio: 1-13-2
labels:
label: second
sources:
- http://url.of.second
How could we get a list of namespaces and their istio value if it is different to "disabled".
We are trying to use "yq" tool, but I guess any approach would be ok, although "yq" would be a preferred approach.
second, 1-13-2
Using kislyuk/yq you can base your filter on jq.
to_entries splits up the object into an array of key-value pairs
select selects those items matching your criteria
String interpolation in combination with the -r option puts together your desired output
yq -r '
.namespaces
| to_entries[]
| select(.value.namespace.istio != "disabled")
| "\(.key), \(.value.namespace.istio)"
'
second, 1-13-2
Using mikefarah/yq the filter is quite similar.
to_entries[] has to be split up to_entries | .[]
String interpolation is replaced using join and an array
yq '
.namespaces
| to_entries | .[]
| select(.value.namespace.istio != "disabled")
| [.key, .value.namespace.istio] | join(", ")
'
second, 1-13-2
this will do:
cat /path/tp/your.yaml |yq -r '.namespaces | to_entries[] | "\(.key) \(.value.namespace.istio)"'`
will result:
first disabled
second 1-13-2

Start Questetra process with values expressed by "Label" rather than by "Choice ID"

I can start a Questetra process like with this request:
curl https://sample.questetra.net/System/Event/IntermediateMessage/123/0/start \
-d "data[0].selects=new_york"
... where the final parameter's value is the "Choice ID" in this table (called the Master file of Choice type data item in Questetra):
+-----------+----------+
| Choice ID | Label |
+-----------+----------+
| new_york | New York |
| paris | Paris |
| ... | ... |
+-----------+----------+
Problem: The client app only has data in the format of the Label column. For instance, the client app has New York but has no way to convert that to new_york.
Question: Is there any way to start the Questetra process using values from the Label column as arguments?
Either by specifying them directly and setting some kind of flag, or by getting the values "translated" using a preliminary request, or any other way.

Cucumber - Using same datatable in multiple steps in a scenario

I am new to cucumber and trying to use the datatable in a scenario.
Scenario: 1. Sets the configuration and validates it
When the user sets the POST config
| key | value |
| enabled | false |
| timezone | "Asia/Kolkata" |
Then the user gets the config and the result is successfull
| key | value |
| enabled | false |
| timezone | "Asia/Kolkata" |
Here i am using the same datatable to construct REST post request and then validate it.
Is there a possibility to specify the same datatable for multiple steps ?
If i specify the datatable at the end of the scenario,for the first step i get the error Arity mismatch.
TIA
You could also provide different parameters to you test by using scenario outline.
Scenario Outline: Sets the configuration and validates it
When the user sets the POST config with key “<*key>” and enabled status equals to “<*enabled>” for timezone “<*timezone>”
Then the user gets the config and the correct data is recorded for key “<*key>” and enabled status equals to “<*enabled>” for timezone “<*timezone>”
Examples:
| key | enabled | timezone |
| value | false | Asia/Kolkata |
| value2 | true | timezone2 |
The first time your test will be run with key = value, enabled = false, timezone = Asia/Kolkata
The second time the test will be executed with key = value2, enabled = true, timezone = timezone2
Etc
P.S.: You need to delete the * symbols
I hope it helps.

Resources