raviagarwalunravel commented on a change in pull request #5118: [AIRFLOW-4315]
Add monitoring API's to airflow
URL: https://github.com/apache/airflow/pull/5118#discussion_r280671548
##########
File path: airflow/www/api/experimental/endpoints.py
##########
@@ -41,6 +47,124 @@
api_experimental = Blueprint('api_experimental', __name__)
+@api_experimental.route(
+
'/dags/<string:dag_id>/dag_runs/<string:execution_date>/tasks/<string:task_id>/logs',
+ methods=['GET'])
+@requires_authentication
+def logs(dag_id, execution_date, task_id):
+ """
+ Return logs for the specified task identified by dag_id, execution_date
and task_id
+ """
+ try:
+ log = get_task_logs(dag_id, task_id, execution_date)
+ except AirflowException as err:
+ _log.info(err)
+ response = jsonify(error="{}".format(err))
+ response.status_code = err.status_code
+ return response
+ except ValueError:
+ error_message = (
+ 'Given execution date, {}, could not be identified '
+ 'as a date. Example date format: 2015-11-16T14:34:15+00:00'
+ .format(execution_date))
+ response = jsonify({'error': error_message})
+ response.status_code = 400
+ return response
+ except AttributeError as e:
+ error_message = ["Unable to read logs.\n{}\n".format(str(e))]
+ metadata = {}
+ metadata['end_of_log'] = True
+ return jsonify(message=error_message, error=True, metadata=metadata)
+
+ return log
+
+
+@api_experimental.route('/dag_runs', methods=['GET'])
+@requires_authentication
+def dag_runs_filter():
+ """
+ Return the list of all dag_runs
+ :query param state: a query string parameter
'?state=queued|running|success...'
+ :query param state_not_equal: a query string parameter
'?state_not_equal=queued|running|success...'
+ :query param execution_date_before: a query string parameter to find all
runs before provided date,
+ should be in format "YYYY-mm-DDTHH:MM:SS", for example:
"2016-11-16T11:34:15"
+ :query param execution_date_after: a query string parameter to find all
runs after provided date,
+ should be in format "YYYY-mm-DDTHH:MM:SS", for example:
"2016-11-16T11:34:15"
+ :query param dag_id: String identifier of a DAG
+ :return: List of DAG runs of a DAG with requested state,
+ """
+ state = request.args.get('state')
+ state_not_equal = request.args.get('state_not_equal')
+ execution_date_before = request.args.get('execution_date_before')
+ execution_date_after = request.args.get('execution_date_after')
+ dag_id = request.args.get('dag_id')
+
+ dagruns = get_all_dag_runs(dag_id=dag_id, state=state,
state_not_equal=state_not_equal,
+ execution_date_before=execution_date_before,
+ execution_date_after=execution_date_after)
+
+ return jsonify(dagruns)
+
+
+@api_experimental.route('/task_instances', methods=['GET'])
+@requires_authentication
+def task_instances_filter():
+ """
+ Return the list of all dag_runs
+ :query param state: a query string parameter
'?state=queued|running|success...'
+ :query param state_not_equal: a query string parameter
'?state_not_equal=queued|running|success...'
+ :query param execution_date_before: a query string parameter to find all
runs before provided date,
+ should be in format "YYYY-mm-DDTHH:MM:SS", for example:
"2016-11-16T11:34:15".'
+ :query param execution_date_after: a query string parameter to find all
runs after provided date,
+ should be in format "YYYY-mm-DDTHH:MM:SS", for example:
"2016-11-16T11:34:15".'
+ :query param dag_id: String identifier of a DAG
+ :query param task_id: String identifier of a task
+ :return: List of task instances
+ """
+ state = request.args.get('state')
+ state_not_equal = request.args.get('state_not_equal')
+ execution_date_before = request.args.get('execution_date_before')
+ execution_date_after = request.args.get('execution_date_after')
+ dag_id = request.args.get('dag_id')
+ task_id = request.args.get('task_id')
+
+ task_instances = get_all_task_instances(dag_id=dag_id, state=state,
state_not_equal=state_not_equal,
+
execution_date_before=execution_date_before,
+
execution_date_after=execution_date_after, task_id=task_id)
+
+ return jsonify(task_instances)
+
+
+@api_experimental.route('/dags', methods=['GET'])
+@requires_authentication
+def get_all_dags():
+ """
+ Returns a list of Dags
+ :query param is_paused: a query string parameter '?is_paused=true|false'
+ :return: List of all DAGs
+ """
+ is_paused = request.args.get('is_paused')
Review comment:
if the user enters erroneous value, it would be assumed to be false.
Basically, anything other than 'true' is false.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services