feat(alert/report): chart as csv format attachment for email and slack (#13828)

* add ui for setting report format

* refactor default notification format

* init csv data alert report

* add report format to report_schedule model

* add ALERTS_ATTACH_REPORTS feature flag

* fix lint

* update check image tag

* fix migrations

Co-authored-by: samtfm <sam@preset.io>
This commit is contained in:
Lily Kuang
2021-04-15 14:07:49 -07:00
committed by GitHub
parent 21c6efea67
commit df7e2b6a8e
15 changed files with 670 additions and 246 deletions

View File

@@ -15,7 +15,9 @@
# specific language governing permissions and limitations
# under the License.
import re
from typing import Any
import urllib.request
from typing import Any, Dict, Optional
from urllib.error import URLError
import pandas as pd
@@ -65,3 +67,20 @@ def df_to_escaped_csv(df: pd.DataFrame, **kwargs: Any) -> Any:
df = df.applymap(escape_values)
return df.to_csv(**kwargs)
def get_chart_csv_data(
chart_url: str, auth_cookies: Optional[Dict[str, str]] = None
) -> Optional[bytes]:
content = None
if auth_cookies:
opener = urllib.request.build_opener()
cookie_str = ";".join([f"{key}={val}" for key, val in auth_cookies.items()])
opener.addheaders.append(("Cookie", cookie_str))
response = opener.open(chart_url)
content = response.read()
if response.getcode() != 200:
raise URLError(response.getcode())
if content:
return content
return None