12
3

はじめに

この記事は Microsoft Azure Tech Advent Calendar 2023 8 日目の記事です。

Azure Functions を構成するコンポーネントの多くは OSS として GitHub に公開されています。

リポジトリ上のソースコードや Wiki 、Issue や Release Note を参照することで Azure Functions 利用時におけるトラブルシューティングや仕様の理解において役に立つことでしょう。

この記事では、主要なリポジトリについて紹介していきたいと思います。

Azure Functions の大まかな仕組み

Azure Functions ではユーザーが開発/デプロイした関数コードは、ワーカーインスタンスと呼ばれる VM 上で実行されることになります。PaaS サービスとして App Service / Azure Functions の構成要素ついては、日本マイクロソフトサポート部門によるブログ記事でも解説されています。

image.png

ワーカーインスタンス上で、実際にどのようにアプリケーションコードが実行されるかについては、少し古い記事ですが、Azure Functions の紹介資料に以下の画像が記載されています。

image.png

図のように、アプリケーションコードを実行するスタックには、プラットフォーム側が用意したレイヤーが含まれており、Functions HostWebJobs などが OSS として公開されているものとなります。

なお、一番下の App Service Dynamic Runtime については、抽象的ではありますが PaaS プラットフォームとして Azure が提供しているレイヤとなり OSS として公開されていないことが多いように見受けられます。

関連リポジトリ

以下では代表的なものを紹介していきます。

Functions Host 関連

図中に登場する以下の 3 つの要素となります。

image.png

名前 リポジトリ 説明
Azure Functions Host https://github.com/Azure/azure-functions-host Azure Functions のメインのプロセス。
Azure WebJobs SDK https://github.com/Azure/azure-webjobs-sdk WebJobs フレームワーク
Azure WebJobs SDK Extensions https://github.com/Azure/azure-webjobs-sdk-extensions WebJobs フレームワーク拡張機能

Azure Functions Host の README にあるように、Functions Host プロセスは、WebJobs SDK というフレームワークを用いて構成されています。

The Azure Functions runtime builds upon the Azure WebJobs SDK to provide a hosting platform for functions written in many different languages and supporting a wide variety of triggers and bindings.

Azure Functions のランタイムバージョンとは、Functions Host のバージョンを指します。

なお、WebJobsApp Service の機能 としても提供されています。

Language Workers

Language Worker は各言語ランタイム上で動作する、各言語の Worker 実装となります。
Functions Host と Language worker は GRPC でやり取りし、ユーザーの関数コードをロードして実行します。

.NET については、ワーカープロセスモデルが2つあり、In-Process モデルの場合は、FunctionsHost のプロセス上で実行され、Out-Process(分離ワーカーモデル)の場合、他の言語と同様に Language Worker が動作することになります。

名前 リポジトリ 説明
azure-functions-dotnet-worker https://github.com/Azure/azure-functions-dotnet-worker Language Worker の.Net 実装と SDK
azure-functions-python-worker https://github.com/Azure/azure-functions-python-worker Language Worker の Python 実装
azure-functions-nodejs-worker https://github.com/Azure/azure-functions-nodejs-worker Language Worker の JavaScript 実装
azure-functions-java-worker https://github.com/Azure/azure-functions-java-worker Language Worker の Java 実装
azure-functions-powershell-worker https://github.com/Azure/azure-functions-powershell-worker Language Worker の PowerShell 実装
azure-functions-language-worker-protobuf https://github.com/Azure/azure-functions-language-worker-protobuf Functions Host と Language Worker 間の protobuf 定義

また、アプリコード内で参照すべきライブラリも別途公開されています。

名前 リポジトリ 説明
azure-functions-python-library https://github.com/Azure/azure-functions-python-library Python V2 プログラミングモデルで必要
azure-functions-nodejs-library https://github.com/Azure/azure-functions-nodejs-library JavaScript V4 プログラミングモデルで必要
azure-functions-java-library https://github.com/Azure/azure-functions-java-library Java 関数作成に必要

Function Extentions

Azure Functions において、WebJobs SDK (Extentions) に含まれていないトリガーやバインディングは、個別に拡張機能として提供されています。公式なものや非公式なものなどがあります。
利用する場合はそれらを登録する必要があります。

名前 リポジトリ 説明
azure-functions-extension-bundles https://github.com/Azure/azure-functions-extension-bundles 拡張機能のバンドル
azure-functions-sql-extension https://github.com/Azure/azure-functions-sql-extension AzureASQL拡張
azure-functions-openai-extension https://github.com/cgillum/azure-functions-openai-extension OpenAI 拡張(非公式)
ACSEmailOutputBinding https://github.com/georgeOsdDev/ACSEmailOutputBinding Azure Communication Service Email バインディング拡張(非公式)

Durable Functions

Durable Functions も Functions 拡張の 1 つではありますが、関連のリポジトリが多くあります。

名前 リポジトリ 説明
durabletask https://github.com/Azure/durabletask DurableTask のフレームワーク
azure-functions-durable-extension https://github.com/Azure/azure-functions-durable-extension DurableTaskをAzure Functions で使えるようにした Functions 拡張
azure-functions-durable-python https://github.com/Azure/azure-functions-durable-python Python 用 Durable Functions ライブラリ
azure-functions-durable-js https://github.com/Azure/azure-functions-durable-js JavaScript 用 Durable Functions ライブラリ
durabletask-java https://github.com/microsoft/durabletask-java Java 用 Durable Functions ライブラリ
azure-functions-durable-powershell https://github.com/Azure/azure-functions-durable-powershell PowerShell 用 Durable Functions ライブラリ
durabletask-mssql https://github.com/microsoft/durabletask-mssql SQL Server ストレージプロバイダー
durabletask-netherite https://github.com/microsoft/durabletask-netherite [netherite ストレージプロバイダー](https://learn.microsoft.com/ja-jp/azure/azure-functions/durable/quickstart-netherite
DurableFunctionsMonitor https://github.com/microsoft/DurableFunctionsMonitor ストレージモニター

Container Image

Linux 環境では、Functions Host や各言語ランタイムを含むコンテナイメージ上でアプリケーションが実行されます。各言語ごとのイメージは mcr.microsoft.com/azure-functions/<言語> にてホスティングされています。

名前 リポジトリ 説明
azure-functions-docker https://github.com/Azure/azure-functions-docker イメージ管理

Kudu 関連

Azure Functions(App Service) では、Kudu と呼ばれる、SCM サイトがデプロイ管理などを提供するサイドカーとして提供されています。
以下のブログ記事、検証記事も参考にしてください。

名前 リポジトリ 説明
kudu https://github.com/projectkudu/kudu Windows 環境で動作する Kudu
kudulite https://github.com/Azure-App-Service/KuduLite Linux 環境で動作する Kudu
Oryx https://github.com/microsoft/Oryx KuduLite 上で動作するビルドツール
DaaS https://github.com/Azure/DaaS 問題の診断と解決などを提供するツール

開発ツール

ローカルで Azure Functions を実行したり、Azure に発行するためのツールもそれぞれ公開されています。

名前 リポジトリ 説明
azure-functions-core-tools https://github.com/Azure/azure-functions-core-tools Azure Functions Core Tools
vscode-azurefunctions https://github.com/microsoft/vscode-azurefunctions VS Code 機能拡張
azure-functions-maven-plugin https://github.com/microsoft/azure-maven-plugins/tree/develop/azure-functions-maven-plugin Maven プラグイン
azure-functions-templates https://github.com/Azure/azure-functions-templates ポータルや VS Code で表示される scaffold テンプレート
functions-action https://github.com/Azure/functions-action GitHub Action
functions-container-action https://github.com/Azure/functions-container-action カスタムコンテナ用 GitHub Action
azure-cli https://github.com/Azure/azure-cli AZ CLI(Azure Functionsのみに限らず)
azure-powershell https://github.com/Azure/azure-powershell AZ Powershell (Azure Functionsのみに限らず)

SDK

拡張機能の内部で利用されていたり、アプリケーションコードから利用する各種サービスの SDK は言語ごとに公開されています。
※これらは特に Azure Functions 特有のものではありません。

名前 リポジトリ 説明
azure-sdk-for-net https://github.com/Azure/azure-sdk-for-net
azure-sdk-for-python https://github.com/azure/azure-sdk-for-python
azure-sdk-for-js https://github.com/Azure/azure-sdk-for-js
azure-sdk-for-java https://github.com/Azure/azure-sdk-for-java

Sample コード

下記サイトにて多くのサンプル実装が公開されています。

上記も含め、Azure や MS 関連の GitHub org にて、リポジトリを検索するといろいろ出てきます。
また、ここまでに挙げた各リポジトリ内に sample といったディレクトリや teste2etest などといったディレクトリが含まれることもあります。それらも参考になると思います。

名前 リポジトリ 説明
Azure-Samples https://github.com/Azure-Samples サンプルコードリポジトリ用のorg
azure-functions-nodejs-samples https://github.com/Azure/azure-functions-nodejs-samples Node.js Functionsのサンプル集

その他

名前 リポジトリ 説明
Azure Functions リポジトリ https://github.com/Azure/Azure-Functions この記事で紹介した内容にあるような各リポジトリへのリンクなどが紹介されています。Issue の報告などは、個別のライブラリの問題か切り分けられないようであればこのリポジトリに対して報告するのもありと思います。
公式ドキュメント https://github.com/MicrosoftDocs/azure-docs/tree/main/articles/azure-functions 公式ドキュメント の英語の原本になります。
app-service-announcements https://github.com/Azure/app-service-announcements Functions Host のリリースなどが Issue として報告されます。

おわりに

上記はあくまでも一覧ではなく主観を含む主要なリポジトリの紹介となります。ここで紹介しきれない以外にも多くの関連プロジェクトが OSS として公開されています。
コードを眺めてデバッグしたり、バグを見つけたら Issue 報告したり、PR を送ってみるのもよいでしょう。

12
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
3