Skip to content

Commit

Permalink
Add new dataset and dashboard to test variables in label queries
Browse files Browse the repository at this point in the history
  • Loading branch information
meln5674 committed Nov 25, 2022
1 parent e01bfc7 commit bc54ac6
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 2 deletions.
243 changes: 243 additions & 0 deletions integration-test/dashboards/transactions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 3,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "meln5674-mongodb-community",
"uid": "${datasource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 25,
"w": 24,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"aggregation": "[{\"$unwind\": \"$transactions\"},{ \"$project\": { \"date\": \"$transactions.date\", \"symbol\": \"$transactions.symbol\", \"code\": \"$transactions.transaction_code\", \"total\": { \"$toDouble\": \"$transactions.total\" }}}, { \"$match\": { \"code\": { \"$in\": $code }, \"symbol\": { \"$in\": $symbol } } } ]",
"autoTimeBound": false,
"autoTimeSort": true,
"collection": "transactions",
"database": "analytics",
"datasource": {
"type": "meln5674-mongodb-community",
"uid": "${datasource}"
},
"labelFields": [
"code",
"symbol"
],
"queryType": "Timeseries",
"refId": "A",
"timestampField": "date",
"timestampFormat": "",
"valueFieldTypes": [
"float64"
],
"valueFields": [
"total"
]
}
],
"title": "Transactions",
"type": "timeseries"
}
],
"refresh": false,
"schemaVersion": 37,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"current": {
"selected": false,
"text": "mongodb",
"value": "mongodb"
},
"hide": 0,
"includeAll": false,
"multi": false,
"name": "datasource",
"options": [],
"query": "meln5674-mongodb-community",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"type": "datasource"
},
{
"current": {
"selected": true,
"text": [
"amd",
"ibm",
"msft"
],
"value": [
"amd",
"ibm",
"msft"
]
},
"datasource": {
"type": "meln5674-mongodb-community",
"uid": "${datasource}"
},
"definition": "analytics (transactions)",
"hide": 0,
"includeAll": true,
"multi": true,
"name": "symbol",
"options": [],
"query": {
"aggregation": "[{\"$unwind\": \"$transactions\"},{ \"$project\": { \"date\": \"$transactions.date\", \"symbol\": \"$transactions.symbol\", \"code\": \"$transactions.transaction_code\"} }, { \"$match\": { \"date\": { \"$gte\": { \"$date\": \"${__from:date}\" }, \"$lte\" : { \"$date\": \"${__to:date}\" } } } } ]",
"collection": "transactions",
"database": "analytics",
"fieldName": "symbol",
"fieldType": "string"
},
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
},
{
"current": {
"selected": true,
"text": [
"buy"
],
"value": [
"buy"
]
},
"datasource": {
"type": "meln5674-mongodb-community",
"uid": "${datasource}"
},
"definition": "analytics (transactions)",
"hide": 0,
"includeAll": true,
"multi": true,
"name": "code",
"options": [],
"query": {
"aggregation": "[{\"$unwind\": \"$transactions\"},{ \"$project\": { \"date\": \"$transactions.date\", \"symbol\": \"$transactions.symbol\", \"code\": \"$transactions.transaction_code\"} }, { \"$match\": { \"date\": { \"$gte\": { \"$date\": \"${__from:date}\" }, \"$lte\" : { \"$date\": \"${__to:date}\" } } } } ]",
"collection": "transactions",
"database": "analytics",
"fieldName": "code",
"fieldType": "string"
},
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "1993-10-24T12:52:03.788Z",
"to": "2000-12-15T14:47:01.267Z"
},
"timepicker": {},
"timezone": "",
"title": "Transactions",
"uid": "SKyKSuOVz",
"version": 1,
"weekStart": ""
}
11 changes: 11 additions & 0 deletions integration-test/datasets/transactions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set -x
ARGS=( -d analytics -c transactions --file /mnt/host/grafana-mongodb-community-plugin/integration-test/datasets/download/transactions.json )
if [ "${ALLOW_EMPTY_PASSWORD}" != "yes" ]; then
ARGS+=(
--username "${MONGODB_ROOT_USER}"
--password "${MONGODB_ROOT_PASSWORD}"
--authenticationDatabase admin
)
fi
mongoimport \
"${ARGS[@]}"
19 changes: 17 additions & 2 deletions integration-test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
if ! [ -f integration-test/datasets/download/tweets.zip ]; then
curl -vfL https://github.com/ozlerhakan/mongodb-json-files/blob/master/datasets/tweets.zip?raw=true > integration-test/datasets/download/tweets.zip
fi
if ! [ -f integration-test/datasets/download/transactions.json ]; then
curl -vfL https://github.com/fieldsets/mongodb-sample-datasets/blob/main/sample_analytics/transactions.json?raw=true > integration-test/datasets/download/transactions.json
fi
rm -rf integration-test/datasets/download/tweets
unzip integration-test/datasets/download/tweets.zip -d integration-test/datasets/download/tweets/

Expand All @@ -40,6 +43,8 @@ data:
$(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-test/datasets/weather.js; set +x)
tweets.sh: |
$(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-test/datasets/tweets.sh; set +x)
transations.sh: |
$(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-test/datasets/transactions.sh; set +x)
---
apiVersion: v1
kind: ConfigMap
Expand All @@ -60,10 +65,18 @@ $(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-te
apiVersion: v1
kind: ConfigMap
metadata:
name: dashboards
name: dashboard-retweets
data:
retweets.json: |
$(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-test/dashboards/retweets.json; set -x)
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dashboard-transactions
data:
transactions.json: |
$(set +x; while IFS= read -r line; do echo " ${line}" ; done < integration-test/dashboards/transactions.json; set -x)
EOF

helm repo add bitnami https://charts.bitnami.com/bitnami
Expand Down Expand Up @@ -103,8 +116,10 @@ GRAFANA_ARGS=(
--set config.grafanaIniConfigMap=grafana-ini
--set config.useGrafanaIniFile=true
--set dashboardsProvider.enabled=true
--set dashboardsConfigMaps[0].configMapName=dashboards
--set dashboardsConfigMaps[0].configMapName=dashboard-retweets
--set dashboardsConfigMaps[0].fileName=retweets.json
--set dashboardsConfigMaps[1].configMapName=dashboard-transactions
--set dashboardsConfigMaps[1].fileName=transactions.json
# --set image.tag=7.1.5-debian-10-r9
)

Expand Down

0 comments on commit bc54ac6

Please sign in to comment.