Azure Functionsメモ ~ host.jsonの役割

Version2.xの情報だけど、公式ドキュメントは下記。
docs.microsoft.com

これによると、host.jsonの役割は下記。

The host.json metadata file contains global configuration options that affect all functions for a function app.
メタデータファイルhost.jsonは、function appの全てのfunctionに影響を及ぼすグローバル設定オプションを含むファイル。

更に、

Other function app configuration options are managed in your app settings (for deployed apps) or your local.settings.json file (for local development).
他のfunction appの設定オプションについては、下記2通りで設定する。
deployed appsについては、app settingsで、local開発に関しては、local.setting.jsonファイルで設定する。

それでサンプルが下記のようであると。

{
    "version": "2.0",
    "aggregator": {
        "batchSize": 1000,
        "flushTimeout": "00:00:30"
    },
    "extensions": {
        "cosmosDb": {},
        "durableTask": {},
        "eventHubs": {},
        "http": {},
        "queues": {},
        "sendGrid": {},
        "serviceBus": {}
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    },
    "functions": [ "QueueProcessor", "GitHubWebHook" ],
    "functionTimeout": "00:05:00",
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    },
    "logging": {
        "fileLoggingMode": "debugOnly",
        "logLevel": {
          "Function.MyFunction": "Information",
          "default": "None"
        },
        "applicationInsights": {
            "samplingSettings": {
              "isEnabled": true,
              "maxTelemetryItemsPerSecond" : 20,
              "evaluationInterval": "01:00:00",
              "initialSamplingPercentage": 100.0, 
              "samplingPercentageIncreaseTimeout" : "00:00:01",
              "samplingPercentageDecreaseTimeout" : "00:00:01",
              "minSamplingPercentage": 0.1,
              "maxSamplingPercentage": 100.0,
              "movingAverageRatio": 1.0,
              "excludedTypes" : "Dependency;Event",
              "includedTypes" : "PageView;Trace"
            },
            "enableLiveMetrics": true,
            "enableDependencyTracking": true,
            "enablePerformanceCountersCollection": true,            
            "httpAutoCollectionOptions": {
                "enableHttpTriggerExtendedInfoCollection": true,
                "enableW3CDistributedTracing": true,
                "enableResponseHeaderInjection": true
            },
            "snapshotConfiguration": {
                "agentEndpoint": null,
                "captureSnapshotMemoryWeight": 0.5,
                "failedRequestLimit": 3,
                "handleUntrackedExceptions": true,
                "isEnabled": true,
                "isEnabledInDeveloperMode": false,
                "isEnabledWhenProfiling": true,
                "isExceptionSnappointsEnabled": false,
                "isLowPrioritySnapshotUploader": true,
                "maximumCollectionPlanSize": 50,
                "maximumSnapshotsRequired": 3,
                "problemCounterResetInterval": "24:00:00",
                "provideAnonymousTelemetry": true,
                "reconnectInterval": "00:15:00",
                "shadowCopyFolder": null,
                "shareUploaderProcess": true,
                "snapshotInLowPriorityThread": true,
                "snapshotsPerDayLimit": 30,
                "snapshotsPerTenMinutesLimit": 1,
                "tempFolder": null,
                "thresholdForSnapshotting": 1,
                "uploaderProxy": null
            }
        }
    },
    "managedDependency": {
        "enabled": true
    },
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    },
    "watchDirectories": [ "Shared", "Test" ]
}

これ全ての説明は公式ドキュメントを参照するとして、1つだけ説明。

functions

A list of functions that the job host runs. An empty array means run all functions. Intended for use only when running locally. In function apps in Azure, you should instead follow the steps in How to disable functions in Azure Functions to disable specific functions rather than using this setting.

job hostが実行する関数リスト。
空配列の場合は全ての関数を実行するという意味である。
ローカルで実行する場合にのみ有効。
Azure上でのfunction appsでは、この設定ではなく、Azure Functionsでの関数の無効化方法に関する説明に従う必要がある。

試しにhost.jsonに次のように2つ記載してみた。

{
    "version": "2.0",
    "functions": ["HttpTriggerExample", "HttpTriggerReference"]
}

この状態でF5キーを押してローカル実行すると、コンソールに次のようにログが出力された。
f:id:graySpace:20200227165354p:plain

host.jsonから1つ関数名を削除して次のようにすると。

{
    "version": "2.0",
    "functions": ["HttpTriggerExample"]
}

たしかに1つだけ実行。
f:id:graySpace:20200227165726p:plain