Celery - Task signature converted to dictionary and cannot call in chord - Using chain of tasks in header group of chord - task

Following the answer on celery chord with group of chains with exception in chain
I'm getting an error where Celery seems to change the chain of task signatures into a dictionary causing the error below.
Celery - 4.4
Redis - 3.3.11
Code - from #bigzbig
#celery_app.task
def task_one():
return 'OKIDOKI'
#celery_app.task
def task_two(str):
return f'{str} YOUPI'
#celery_app.task
def task_three(str):
return f'{str} MAKAPAKA'
#celery_app.task
def task_exception(str):
raise KeyError(f'{str} Ups')
#celery_app.task(ignore_result=True)
def task_wrapper(*args, **kwargs):
if 'job' in kwargs:
kwargs['job'].apply()
#celery_app.task(ignore_result=True)
def callback_task(*args, **kwargs):
return (args, kwargs, 'Yeah')
def test():
chains = []
tasks = [
task_one.s(),
task_two.s(),
task_exception.s(),
task_three.s(),
]
chains.append(task_wrapper.s(job=chain(*tasks)))
tasks = [
task_one.s(),
task_two.s(),
task_three.s(),
]
chains.append(task_wrapper.s(job=chain(*tasks)))
chord(chains, callback_task.s()).apply_async()
Print of kwargs['job']
celeryworker2_1 | [2020-03-23 22:31:01,646: WARNING/ForkPoolWorker-1] {'task': 'celery.chain', 'args': [], 'kwargs': {'tasks': [{'task': 'portfolio.tasks.task_one', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'chord_size': None, 'immutable': False}, {'task': 'portfolio.tasks.task_two', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'chord_size': None, 'immutable': False}, {'task': 'portfolio.tasks.task_exception', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'chord_size': None, 'immutable': False}, {'task': 'portfolio.tasks.task_three', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False, 'chord_size': None}]}, 'options': {}, 'subtask_type': 'chain', 'immutable': False, 'chord_size': None}
celeryworker_1 | [2020-03-23 22:31:01,650: WARNING/ForkPoolWorker-1] {'task': 'celery.chain', 'args': [], 'kwargs': {'tasks': [{'task': 'portfolio.tasks.task_one', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'chord_size': None, 'immutable': False}, {'task': 'portfolio.tasks.task_two', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'chord_size': None, 'immutable': False}, {'task': 'portfolio.tasks.task_three', 'args': [], 'kwargs': {}, 'options': {}, 'subtask_type': None, 'immutable': False, 'chord_size': None}]}, 'options': {}, 'subtask_type': 'chain', 'immutable': False, 'chord_size': None}
Error
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 650, in __protected_call__
return self.run(*args, **kwargs)
File "/app/portfolio/tasks.py", line 241, in task_wrapper
kwargs['job'].apply()
AttributeError: 'dict' object has no attribute 'apply'

You are trying to pass signature to another task. So Celery converts it to dict. You can build Signature from dict.
"task_always_eager=True" is set to run under the same process instead as a different celery task, As executing chain itself is a different task. This way you will be preserving link or link_error is any given.
from celery.canvas import Signature
callback = Signature(kwargs['job'])
callback.delay(task_always_eager=True)

Related

Outlook REST API returns events without start and end dates

When requesting GET https://outlook.office.com/api/v2.0/me/calendars/{calendar_id}/events the response (for some events) does not have a Start and End date.
The full structure for such events is as follows:
{
'OriginalStartTimeZone': None,
'End': {
'TimeZone': 'tzone://Microsoft/Utc',
'DateTime': '0001-01-01T00:00:00.0000000Z'
},
'HasAttachments': False,
'ResponseRequested': True,
'ShowAs': 'Free',
'Recurrence': None,
'Start': {
'TimeZone': 'tzone://Microsoft/Utc',
'DateTime': '0001-01-01T00:00:00.0000000Z'
},
'BodyPreview': '',
'AllowNewTimeProposals': True,
'Location': {...},
'Attendees': [...],
'TransactionId': None,
'Type': 'SingleInstance',
'ResponseStatus': {
'Response': 'NotResponded',
'Time': '0001-01-01T00:00:00Z'
},
'Body': {...},
'OnlineMeeting': None,
'IsRoomRequested': False,
'OnlineMeetingProvider': 'Unknown',
'IsCancelled': False,
'IsAllDay': False,
'ReminderMinutesBeforeStart': 0,
'Subject': '...',
'Categories': [],
'LastModifiedDateTime': '2020-03-11T18:31:15.548Z',
'AutoRoomBookingOptions': None,
'OriginalEndTimeZone': None,
'CreatedDateTime': '2020-03-11T18:34:34.259429Z',
'IsOnlineMeeting': False,
'#odata.id': '...',
'IsDraft': False,
'WebLink': '...',
'ChangeKey': '...',
'SeriesMasterId': None,
'IsOrganizer': True,
'iCalUId': None,
'AutoRoomBookingStatus': 'None',
'Locations': [],
'Id': '...',
'IsReminderOn': False,
'Calendar#odata.associationLink': '...',
'Calendar#odata.navigationLink': '...',
'Importance': 'Normal',
'Organizer': {...},
'#odata.etag': '...',
'Sensitivity': 'Normal',
'OnlineMeetingUrl': None
}
Is this normal behavior? If so, how can this be displayed?
How can I create such an event to reproduce it?

How to check if two containers are linked properly?

I have 3 containers, say their names are A, B, C.
Their definition, now that I tried to link them together (using the key links), is attached at the end of the question.
How can I test that this linking worked properly?
{
'A': {
'run_args': {
'name': 'A',
'detach': 'True',
'volumes': {
'/var/run/datadog': {'bind': '/var/run/datadog', 'mode': 'rw'}
},
'ports': {'30000/tcp': '30000', '30010/tcp': '30010'},
'restart_policy': {'name': 'always'},
'log_config': {'type': 'syslog'},
'command': A_cmd,
'links': {'B': 'B', 'C': 'C'}
}
},
'B': {
'run_args': {
'name': 'B',
'detach': True,
'volumes': {
'/etc/salt': {'bind': '/etc/salt', 'mode': 'rw'},
'/var/run/datadog': {'bind': '/var/run/datadog', 'mode': 'rw'}
},
'ports': {'8080/tcp': '80'},
'restart_policy': {'name': 'always'},
'command': B_cmd,
'tty': True,
'links': {'A': 'A', 'C': 'C'}
}
},
'C': {
'run_args': {
'name': 'C',
'detach': True,
'volumes': {
'/etc/salt': {'bind': '/etc/salt', 'mode': 'rw'},
'/var/run/datadog': {'bind': '/var/run/datadog', 'mode': 'rw'}
},
'ports': {'33000/tcp': '33000'},
'restart_policy': {'name': 'always'},
'command': C_cmd,
'tty': True,
'links': {'A': 'A', 'B': 'B'}
}
}
}
ping container names from another container. If they are linked then it will respond.

How to add dashboard configuration json file in Grafana image?

I have a grafana docker image which have hawkular-datasource pre-configured using configuration files.
After after running grafana instance, I have a json given by teammate, which can be imported inside grafana and that json file creates dashboard when imported.
How do I make that dashboards appear by default in Grafana instance?
I tried copying the json file to /etc/grafana/provisioning/dashboards/ folder and created a new docker image. But when I run the image, the instance doesn't contain the dashboard at the homepage or anywhere in it.
How do I add this json file in docker image. Am I following the correct way?
I tried this http://docs.grafana.org/administration/provisioning/ But it didn't help out much. Any suggestion?
Here is the json file.
{
"id": null,
"title": "Openshift Metrics",
"tags": [],
"style": "dark",
"timezone": "browser",
"editable": true,
"hideControls": false,
"sharedCrosshair": false,
"rows": [
{
"collapse": false,
"editable": true,
"height": "322px",
"panels": [
{
"content": "<center><p style='font-size: 40pt'>$app</p></center>",
"editable": true,
"error": false,
"id": 23,
"isNew": true,
"links": [],
"mode": "html",
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"style": {
"font-size": "36pt"
},
"title": "",
"type": "text"
},
{
"aliasColors": {},
"bars": false,
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 9,
"isNew": true,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeatIteration": 1476706310439,
"scopedVars": {},
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "none",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "avg",
"type": "gauge"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Memory usage",
"tooltip": {
"msResolution": true,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": 0,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 12,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "sum",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "live",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Live, all pods",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 15,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "avg",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "live",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Live per pod",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 10,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "sum",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "avg",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Average, all pods",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 13,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "avg",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "avg",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Average per pod",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 11,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "sum",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "max",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Max, all pods",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(237, 129, 40, 0.89)",
"rgba(245, 54, 54, 0.9)"
],
"datasource": "Hawk-DS",
"editable": true,
"error": false,
"format": "bytes",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"height": "100px",
"id": 14,
"interval": null,
"isNew": true,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeatIteration": 1476706310439,
"scopedVars": {},
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"targets": [
{
"queryBy": "tags",
"rate": false,
"refId": "A",
"seriesAggFn": "avg",
"tags": [
{
"name": "container_name",
"value": "$app"
},
{
"name": "descriptor_name",
"value": "memory/usage"
}
],
"target": "select metric",
"tagsQL": "container_name IN [$app] AND descriptor_name='memory/usage'",
"timeAggFn": "max",
"type": "gauge"
}
],
"thresholds": "140000000,180000000",
"title": "Max per pod",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
}
],
"repeat": "app",
"scopedVars": {
"app": {
"text": "aloha",
"value": "aloha",
"selected": true
}
},
"title": "New row"
}
],
"time": {
"from": "now-30m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"templating": {
"list": [
{
"current": {},
"datasource": "Hawk-DS",
"hide": 0,
"includeAll": true,
"label": "Application",
"multi": true,
"name": "app",
"options": [],
"query": "tags/container_name:*",
"refresh": 1,
"regex": "",
"type": "query"
}
]
},
"annotations": {
"list": []
},
"schemaVersion": 12,
"version": 32,
"links": [],
"gnetId": null
}
You should put a YAML file pointing to the JSON files in that folder. For example write /etc/grafana/provisioning/dashboards/local.yml:
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10 #how often Grafana will scan for changed dashboards
options:
path: /var/lib/grafana/dashboards
And then write your JSON file to /var/lib/grafana/dashboards/openshift.json.
Before Grafana 5, my previous solution was to wrap the whole Docker process in a script that uses the API to create the dashboard once the Docker container is up. You can use the GF_SECURITY_ADMIN_PASSWORD environment variable to set the password. You can also use GF_AUTH_ANONYMOUS_ENABLED, but you'll need to make sure it's not accessible to the outside world.
docker run -p 3000:3000 -e GF_AUTH_ANONYMOUS_ENABLED=true grafana/grafana ...
sleep 10 # wait for grafana to load (use a better method of waiting in production)
curl -skfS -XPOST --header "Content-Type: application/json" "http://localhost:3000/grafana/api/dashboards/db" --data-binary #dashboard.json
I've faced with the same problem and I hope the next solution could help somebody.
For example, you have the next working directory:
├── docker-compose.yml
├── grafana
│ ├── Dockerfile
│ ├── dashboards
│ │ └── exported_dashboard.json #dashboard you saved before
│ └── provisioning
│ │
│ ├── dashboards
│ │ └── all.yml
│ └── datasources
│ └── all.yml
In the Dockerfile you have to add provisioning and dashboards folders into grafana container:
FROM grafana/grafana:latest
ADD ./provisioning /etc/grafana/provisioning
ADD ./dashboards /var/lib/grafana/dashboards
In provisioning/dashboards/all.yml you have to set path to imported dashboards folder
where exported_dashboard.json is actually placed:
- name: 'default'
org_id: 1
folder: ''
type: 'file'
options:
folder: '/var/lib/grafana/dashboards'
[Optional] Then you also can configure default datasourse in provisioning/datasources/all.yml, prometheus, for example:
datasources:
- access: 'proxy'
editable: true
is_default: true
name: 'prom1'
org_id: 1
type: 'prometheus'
url: 'http://prometheus:9090'
version: 1
Finally, docker-compose.yml:
version: '3.8'
services:
grafana:
image: awesome-grafana:latest
build:
context: grafana
ports:
- "3000:3000"
environment:
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: "/var/lib/grafana/dashboards/exported_dashboard.json"
As for HOME dashborad, you can use the GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH evironment variable, as shown above.
More about GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH evironment variable you can read in that github issue.
The full comprehensive code example you can find in the next github repository
Original article with explanation there.

Docker 1.12 certificate missing using daemon.json file

I am running docker 1.12 on Ubuntu 16.04, I need to change the bip option, so I create a custom /etc/docker/daemon.json configuration file that looks like this:
root#simo:/etc/docker# cat daemon.json
{
"authorization-plugins": [],
"dns": ["8.8.8.8", "8.8.4.4"],
"dns-opts": [],
"dns-search": [],
"exec-opts": [],
"exec-root": "",
"storage-driver": "",
"storage-opts": [],
"labels": [],
"live-restore": true,
"log-driver": "",
"log-opts": {},
"mtu": 0,
"pidfile": "",
"graph": "",
"cluster-store": "",
"cluster-store-opts": {},
"cluster-advertise": "",
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,
"debug": true,
"hosts": [],
"log-level": "",
"tls": false,
"tlsverify": false,
"tlscacert": "",
"tlscert": "",
"tlskey": "",
"swarm-default-advertise-addr": "",
"api-cors-header": "",
"selinux-enabled": false,
"userns-remap": "",
"group": "",
"cgroup-parent": "",
"default-ulimits": {},
"ipv6": false,
"iptables": false,
"ip-forward": false,
"ip-masq": false,
"userland-proxy": false,
"ip": "0.0.0.0",
"bridge": "",
"bip": "172.17.42.1/16",
"fixed-cidr": "",
"fixed-cidr-v6": "",
"default-gateway": "",
"default-gateway-v6": "",
"icc": false,
"raw-logs": false,
"registry-mirrors": [],
"insecure-registries": [],
"disable-legacy-registry": false,
"default-runtime": "runc",
"oom-score-adjust": -500
}
Now, if I start the daemon it simply not work saying:
FATA[0000] Could not load X509 key pair (cert: "", key: ""): open : no such file or directory
Which is definitely correct, but doesn't let me use docker at all.
If I remove the daemon.json file, however dockerd start correctly, so I am guessing that, either is possible to start dockerd without providing the certificates or there are certificates somewhere that I should use to run dockerd.
How may I simply run dockerd using a daemon.json config file?
If you only need to change the value of bip then following daemon.json file is sufficient.
{
"bip": "172.17.42.1/16"
}

Convert Json structures(Json File) to Ruby hash

I have a JSON File which looks like:
{"business_id": "vcNAWiLM4dR7D2nwwJ7nCA", "full_address": "4840 E Indian School Rd\nSte 101\nPhoenix, AZ 85018", "hours": {"Tuesday": {"close": "17:00", "open": "08:00"}, "Friday": {"close": "17:00", "open": "08:00"}, "Monday": {"close": "17:00", "open": "08:00"}, "Wednesday": {"close": "17:00", "open": "08:00"}, "Thursday": {"close": "17:00", "open": "08:00"}}, "open": true, "categories": ["Doctors", "Health & Medical"], "city": "Phoenix", "review_count": 7, "name": "Eric Goldberg, MD", "neighborhoods": [], "longitude": -111.98375799999999, "state": "AZ", "stars": 3.5, "latitude": 33.499313000000001, "attributes": {"By Appointment Only": true}, "type": "business"}
{"business_id": "JwUE5GmEO-sH1FuwJgKBlQ", "full_address": "6162 US Highway 51\nDe Forest, WI 53532", "hours": {}, "open": true, "categories": ["Restaurants"], "city": "De Forest", "review_count": 26, "name": "Pine Cone Restaurant", "neighborhoods": [], "longitude": -89.335843999999994, "state": "WI", "stars": 4.0, "latitude": 43.238892999999997, "attributes": {"Take-out": true, "Good For": {"dessert": false, "latenight": false, "lunch": true, "dinner": false, "breakfast": false, "brunch": false}, "Caters": false, "Noise Level": "average", "Takes Reservations": false, "Delivery": false, "Ambience": {"romantic": false, "intimate": false, "touristy": false, "hipster": false, "divey": false, "classy": false, "trendy": false, "upscale": false, "casual": false}, "Parking": {"garage": false, "street": false, "validated": false, "lot": true, "valet": false}, "Has TV": true, "Outdoor Seating": false, "Attire": "casual", "Alcohol": "none", "Waiter Service": true, "Accepts Credit Cards": true, "Good for Kids": true, "Good For Groups": true, "Price Range": 1}, "type": "business"}
I want to to traverse this file and convert individual structures into a Ruby hash so that I can access the different hashes to perform actions on them.
This is a hash of the first structure of the JSON file:
{"business_id"=>"uUsfpN81JCMKyH6c0D0bTg", "full_address"=>"1910 Village Center Cir\nSte 6\nSummerlin\nLas Vegas, NV 89134", "hours"=>{}, "open"=>true, "categories"=>["Food", "Desserts", "Italian", "Pizza", "Restaurants"], "city"=>"Las Vegas", "review_count"=>6, "name"=>"Rocco's NY Pizza & Pasta", "neighborhoods"=>["Summerlin"], "longitude"=>-115.3041999, }
Similarly I want to have hashes of all other JSON structures. How can I do this in Ruby on Rails?
The file you got it's not a JSON file, but simply a text file with a bunch of JSON-encoded objects. Simply loop over the lines.
require 'json'
File.read("file.txt").split("\n").each do |line|
JSON.parse(line)
end
or use .map instead of .each if you want return an Array of Hash.
File.foreach("file.txt").map do |line|
JSON.parse(line)
end
File.read("file.txt").split("\n").map do |line|
JSON.parse(line)
end
Also note this has nothing to do with Rails, it's pure Ruby code.
Something like this will return an array of hashes retrieved from the file:
require 'json'
array_of_hashes = File.foreach('file.txt').map{ |l| JSON[l] }
Be warned though, this isn't scalable because you'll be pulling the entire file into memory, and if that resulting array is larger than the available space you'll see your program go to a crawl.
A more scalable approach would be to read each line, convert it to a Ruby object using JSON's parser, then immediately stuff the resulting object into a database record, and finally iterate over the database to do your massaging. SQLite3, PostgreSQL, MySQL would all be reasonable choices for this.
Have you tried JSON.parse
require 'json'
JSON.parse(your_json) #=> your expected result

Resources