I'm trying to query all artifacts that are older than 6 months old. I'm able to delete them if I hard code a date into my query.
{
"files": [
{
"aql": {
"items.find": {
"repo": "foobar",
"$or": [
{
"$and": [
{
"modified": { "$lt": "2016-10-18T21:26:52.000Z"}
}
]
}
]
}
}
}
]
}
jfrog rt del --spec /tmp/foo.spec --dry-run
How can I do a query with a relative date? (e.g today - 6 months)
I'm going to put this into a cron job, and I'd rather not munge a spec file every time the cron job runs.
AQL queries support relative time operators.
In this case, modify the query:
"modified": { "$lt": "2016-10-18T21:26:52.000Z"}
To:
"modified": { "$before": "6mo"}
See full documantation at: AQL Relative Time Operators.
Related
I'm working with JFROG Cli and need to cleanup artifacts from folder under repository and keep only 5 latest artifacts (latest by created date).
I have already created some code which removes artifacts which were created 7 and more days. But I need to keep 5 latest artifacts. Anyone has any ideas?
{
"files": [
{
"aql": {
"items.find": {
"repo": "maven-repo",
"path": {"$match":"com/mqjbnd64/7.1"},
"name": {"$match":"*"},
"$or": [
{
"$and": [
{
"created": { "$before":"7d" }
}
]
}
]
}
}
}
]
}
You can create an initial query sorting by create date and limiting the number of records returned to 5.
Than you can execute another query, to get all artifacts in this path, and deleted the ones not returned by the previous query.
I want to add a variable to the given MongoDB query in Metabase. I know that it is supported after https://github.com/metabase/metabase/issues/3653 I have given my query below which is not working with the variable.
My query is:
[
{
"$project": {
"lastCommGenTS": "$lastCommGenTS",
"lastUpdated": "$lastUpdated",
"regNo": "$regNo",
"derivedStatus": "$derivedStatus"
}
},
{
"$match": {
"$expr": {
"$and": [
{
"$eq": [
"$regNo",{{regNo}}
]
}
]
}
}
},
{
"$project": {
"_id": "$_id",
"regNo": "$regNo",
"derivedStatus": "$derivedStatus",
"lastcommtimeIST": {
"$dateToString": {
"format": "%Y-%m-%d %H:%M:%S",
"date": {
"$toDate": "$lastCommGenTS"
},
"timezone": "+05:30"
}
},
"lastupdatedIST": {
"$dateToString": {
"format": "%Y-%m-%d %H:%M:%S",
"date": {
"$toDate": "$lastUpdated"
},
"timezone": "+05:30"
}
},
"lag_in_minutes": {
"$divide": [
{
"$subtract": [
"$lastUpdated",
"$lastCommGenTS"
]
},
60000
]
}
}
}
]
I am getting this error here:
Unexpected character ('{' (code 123)): was expecting double-quote to start field name at [Source: java.io.StringReader#6bab96b; line: 17, column: 26]
Please help me.
Many thanks in advance :)
In my case, I could not get variables to work for native Mongo Queries because I was using an older version of metabase which did not support the same. The support for variables and field filters in native Mongo queries was added after this version of release - https://github.com/metabase/metabase/releases/tag/v0.34.0
In docs for Google Analytics API Response body contains queryCost and resourceQuotasRemaining. But, when I do
curl -i -H 'Content-Type: application/json' -X POST 'https://analyticsreporting.googleapis.com/v4/reports:batchGet?access_token=mytoken' -d '{"reportRequests":[{"viewId":"ga:myviewId","dateRanges":[{"startDate":"2019-12-04","endDate":"2019-12-04"}],"dimensions":[{"name":"ga:campaign"},{"name":"ga:adContent"},{"name":"ga:keyword"},{"name":"ga:currencyCode"}],"dimensionFilterClauses":[{"filters":[{"dimensionName":"ga:sourceMedium","operator":"EXACT","expressions":["Yandex.Market / cpc"]}]},{"filters":[{"dimensionName":"ga:campaign","operator":"PARTIAL","expressions":["msk"]}]}],"metrics":[{"expression":"ga:goal12Completions"}],"metricFilterClauses":[{"filters":[{"metricName":"ga:goal12Completions","operator":"GREATER_THAN","comparisonValue":"0"}]}],"hideTotals":true,"hideValueRanges":true}]}'
response body do not contain queryCost and resourceQuotasRemaining
{"reports":[{"columnHeader":{"dimensions":[...],"metricHeader":{"metricHeaderEntries":[...]}},"data":{"rows":[{"dimensions":[...],"metrics":[...]}],"rowCount":1,"isDataGolden":true}}]}
If I add to JSON in POST "useResourceQuotas":true, I get error: "The request is not eligible for resource quotas. Check if account is premium and whitelisted." (code 400).
How I can get information about query cost, quotas remaining and other limit stats using API? Or it is possible only for premium accounts?
Pete,
Resource based quota feature is only available to Analytics 360 users.
Thanks,
Ilya
your request doesn't include useResourceQuotas = true. its default false
{
"reportRequests": [
{
"viewId": "ga:xxxx",
"dateRanges": [
{
"startDate": "2019-12-04",
"endDate": "2019-12-04"
}
],
"metrics": [
{
"expression": "ga:users"
}
],
"hideTotals": true,
"hideValueRanges": true
}
],
"useResourceQuotas": true
}
Result
{
"reports": [
{
"columnHeader": {
"metricHeader": {
"metricHeaderEntries": [
{
"name": "ga:users",
"type": "INTEGER"
}
]
}
},
"data": {
"rows": [
{
"metrics": [
{
"values": [
"1298"
]
}
]
}
],
"rowCount": 1,
"isDataGolden": true
}
}
],
"resourceQuotasRemaining": {
"dailyQuotaTokensRemaining": 100000,
"hourlyQuotaTokensRemaining": 25000
}
}
useResourceQuotas
Doesn't work with every request. I would suggest that you go though yours adding different things to see what the exact problem is. Start by removing all those filters. Once you figure out exactly which one is giving you the error with the userREsourceQuotas let me know and i will ping the team about having the documentation updated. It doesnt say currently that there should be an issue with using it with anything. I cant test your request I dont have any accounts with goals setup like that that i could test with.
We are using the ELK v6.6 version.
We have requirement in Kibana that we have list of records which are displaying in the Kibana data table. We need to display last updated record on top of the table. For which we are using below DSL query but which is not working.Can you please help us to resolve this issue.
{
"query": {
"match_all": { }
},
"aggs": {
"actual_trans_type.keyword": {
"terms": {
"field": "#timestamp"
},
"aggs": {
"top_hit": {
"sort": [
{
"fieldName": {
"order": "desc"
}
}
],
"size": 2
}
}
}
}
}
https://i.stack.imgur.com/eCpde.png
https://i.stack.imgur.com/9XBHC.png
Edit the visualization, click on the timestamp column head to sort it in the descending order and then save the visualization. Now you will have the table in the descending order of timestamp field by default.
Is there a way to download an artifact using AQL?
I have a query sent with:
curl -u user:pass \
-X POST https://artifactoryURL/artifactory/api/search/aql \
-H 'content-type: text/plain' \
-T query.aql
And my query.aql:
items.find(
{
"repo":{"$eq":"repo"},
"$and": [
{
"path": { "$match": "path/*"},
"name": { "$match": "*.rpm"}
}
]
}
)
.sort({ "$desc": ["modified"] })
.limit(1)
Now that I know it returns what I want, Is there a way to change the request from api/search/aql to something like api/download/aql and get those items?
EDIT:
I had also tried doing this with the jfrog cli but they don't fully support AQL there (sort and limit didn't work).
This is the command I tried:
jfrog rt s --spec=query-aql.json
And the spec that failed to sort and limit results:
{
"files": [
{
"aql": {
"items.find": {
"repo": "repo",
"$and": [
{
"path": { "$match": "path/*"},
"name": { "$match": "*.rpm"}
}
]
}
},
"sort": {
"$asc": ["modified"]
},
"limit": 1
}
]
}
EDIT 2:
Added a jfrog-cli-go issue: https://github.com/JFrogDev/jfrog-cli-go/issues/56
An easy way to use your aql script to download files from artifactory is to use the JFrog cli as mention here : https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-Download,CopyandMoveCommandsSpecSchema
The cli can be downloaded as an executable for linux, mac or windows and should fit your needs
With the curl command the only thing you can do is then to parse the result from your aql query and perform download request for each file.
I was just looking for a very similar thing -- use a download spec file to download the latest artifact from a given repo and path. I don't care if I use AQL or not, I just want it in the download-spec.json file. If you go to the link above look at Example 5.
Modified for your example:
{
"files": [
{
"pattern": "path/*.rpm",
"target": "my/download/path/",
"sortBy": "created",
"sortOrder": "desc",
"limit": 1,
}
]
}
jfrog cli supports --limit, --sort-order, and --sort-by arguments.
The following works for me:
jfrog rt search --spec=/tmp/jfrogfilespec.json --sort-by created --sort-order=desc --limit 1
The contents of the json spec file are:
{ "files": [ { "aql": { "items.find": { "repo":{"$eq":"my-release-repo"}, "name":{"$match":"my-artifact-prefix*"} } } } ] }
This generates the following query (according to debug mode):
items.find( { "repo":{"$eq":"my-release-repo"}, "name":{"$match":"my-artifact-prefix*"} } ).include("name","repo","path","actual_md5","actual_sha1","size","type","created").sort({"$desc":["created"]}).limit(1)
What is frustrating is that I cannot seem to find a way to use "jfrog rt search" with a filespec that allows me to influence the "include" modifier portion of the search.