Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read-only Config endpoint #9497

Merged
merged 14 commits into from
Jun 26, 2020
37 changes: 33 additions & 4 deletions airflow/api_connexion/endpoints/config_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,41 @@
# specific language governing permissions and limitations
# under the License.

# TODO(mik-laj): We have to implement it.
# Do you want to help? Please look at: https://github.com/apache/airflow/issues/8136
from flask import Response, request

from airflow.api_connexion.schemas.config_schema import config_schema
from airflow.configuration import conf

def get_config():

def get_config() -> Response:
"""
Get current configuration.
"""
raise NotImplementedError("Not implemented yet.")
response_types = ['text/plain', 'application/json']
content_type = request.accept_mimetypes.best_match(response_types)
conf_dict = conf.as_dict(display_source=True, display_sensitive=True)
if content_type == 'text/plain':
config = ''
for section, parameters in conf_dict.items():
config += f'[{section}]\n'
for key, (value, source) in parameters.items():
config += f'{key} = {value} # source: {source}\n'
else:
config = {
'sections': [
{
'name': section,
'options': [
{
'key': key,
'value': value,
'source': source,
}
for key, (value, source) in parameters.items()
],
}
for section, parameters in conf_dict.items()
]
}
config = config_schema.dump(config)
return config
3 changes: 3 additions & 0 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ components:
value:
type: string
readOnly: true
source:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they can't do anything about this information. They will not change their behavior because the information comes from environment variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inspired by the table in the web configuration page, which has four columns - section, key, value and source. Isn't source information useful for admin users to change and debug the configuration? Especially when it comes from multiple sources like airflow.cfg, env var, cmd.

Copy link
Member

@mik-laj mik-laj Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we will be able to maintain the backward compatibility of the API for this field. in my opinion, the value of this field in the API is low because it refers to values that the API client cannot influence in any way. This may allow debugging problems, but the main goal of the API is to facilitate the management, but not to facilitate troubleshooting.

A similar situation is with the Job table, which is not present in API, and access to it allows us to solve troubleshooting issues, but this table is not relevant for third-party systems and has not been included in the API specification. Each field/endpoint in the API is opt-in, not opt-out, to facilitate backward compatibility.

If you want to make field decisions, think about whether this field will be relevant when you have 100 Airflow instances., In this case, you need a different view of the data stored in the system. You may worry about what the value of the configuration option looks like, e.g. to compare instances, but the source of the content is technical detail.

We can add additional endpoints that allow access to more detailed data in the future, but these endpoints will have to be specially marked to ensure level of stability.

Copy link
Contributor Author

@22quinn 22quinn Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you are coming from. I think I am not clear on the main use case of this endpoint. Do you mind giving a specific example on what this endpoint might be used for? Like what do people do after they query GET /config from 100 Airflow instances?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Airflow has options that have a big impact on instance performance and resource usage.

parallelism = 32
dag_concurrency = 16
max_active_runs_per_dag = 16
dag_file_processor_timeout = 50
scheduler_heartbeat_sec = 5
job_heartbeat_sec = 5
processor_poll_interval = 1
min_file_process_interval = 0
dag_dir_list_interval = 300
etc.

Users may want to read these values and then combine them with data from other applications (e.g. Stackdriver, Zabbix, Prometheus) e..g. average CPU usage, average memory usage, etc. This will allow us to make recommendations on the changes that should be made to improve the health of the instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I removed it

type: string
readOnly: true

ConfigSection:
type: object
Expand Down
39 changes: 39 additions & 0 deletions airflow/api_connexion/schemas/config_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from marshmallow import Schema, fields


class ConfigOptionSchema(Schema):
""" Config Option Schema """
key = fields.String(required=True)
value = fields.String(required=True)
source = fields.String(required=True)


class ConfigSectionSchema(Schema):
""" Config Section Schema"""
name = fields.String(required=True)
options = fields.List(fields.Nested(ConfigOptionSchema))


class ConfigSchema(Schema):
""" Config Schema"""
sections = fields.List(fields.Nested(ConfigSectionSchema))


config_schema = ConfigSchema(strict=True)