I have an Composer environment in Google Cloud. I want to add an item to the UI Menu with some links but it doesn’t work.
Composer version: 2.8.4
Airflow version: 2.7.3
I created an Airflow Plugin analog to this one:
https://github.com/GoogleCloudPlatform/composer-airflow/blob/2.9.1/airflow/composer/plugins/composer_menu_plugin.py
This is the code of my plugin:
from __future__ import annotations
import os
from urllib.parse import urlencode
from airflow.plugins_manager import AirflowPlugin
from airflow.security import permissions
RESOURCE_LINK_MENU = "Link Menu"
RESOURCE_LINK1_NAME = "Link name 1"
RESOURCE_LINK2_NAME = "Link name 2"
RESOURCE_LINK3_NAME = "Link name 3"
LINKS_PLUGIN_PERMISSIONS = [
(permissions.ACTION_CAN_ACCESS_MENU, RESOURCE_LINK_MENU),
(permissions.ACTION_CAN_ACCESS_MENU, RESOURCE_LINK1_NAME),
(permissions.ACTION_CAN_ACCESS_MENU, RESOURCE_LINK2_NAME),
(permissions.ACTION_CAN_ACCESS_MENU, RESOURCE_LINK3_NAME)
]
MENU_CATEGORY_NAME = "Links"
LINK1="https://www.google.com/"
LINK2="https://console.cloud.google.com/"
LINK3="https://www.wikipedia.org/"
LINK1_APPBUILDER_MITEM = {
"name": RESOURCE_LINK1_NAME,
"label": "Label link 1",
"href": LINK1,
"category": RESOURCE_LINK_MENU,
"category_label": MENU_CATEGORY_NAME,
}
LINK2_APPBUILDER_MITEM = {
"name": RESOURCE_LINK2_NAME,
"label": "Label link 2",
"href": LINK2,
"category": RESOURCE_LINK_MENU,
"category_label": MENU_CATEGORY_NAME,
}
LINK3_APPBUILDER_MITEM = {
"name": RESOURCE_LINK3_NAME,
"label": "Label link 3",
"href": LINK3,
"category": RESOURCE_LINK_MENU,
"category_label": MENU_CATEGORY_NAME,
}
class LinksPlugin(AirflowPlugin):
"""Plugin for adding links as menu items in Airflow UI."""
name = "LinksPlugin"
appbuilder_menu_items = [
LINK1_APPBUILDER_MITEM,
LINK2_APPBUILDER_MITEM,
LINK3_APPBUILDER_MITEM
]
Composer doesn’t show anything in the menu.
I restarted the environment but it doesn’t make a difference.
If I go to Admin -> Plugins I can see that Airflow recognizes the plugin:
In Composer logs I get the following errors:
Add View Menu Error: %s
Creation of Permission View Error: %s
Creation of Permission View Error: %s
Creation of Permission View Error: %s
Creation of Permission View Error: %s