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 host.json for sync trigger payload #7386

Merged
merged 17 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ public async Task<SyncTriggersPayload> GetSyncTriggersPayload()
var functionDetails = await WebFunctionsManager.GetFunctionMetadataResponse(listableFunctions, hostOptions, _hostNameProvider);
result.Add("functions", new JArray(functionDetails.Select(p => JObject.FromObject(p))));

// TEMP: refactor this code to properly add extensions in all scenario(#7394)
// Add the host.json extensions to the payload
if (_environment.IsKubernetesManagedHosting())
TsuyoshiUshio marked this conversation as resolved.
Show resolved Hide resolved
cgillum marked this conversation as resolved.
Show resolved Hide resolved
{
JObject extensionsPayload = await GetHostJsonExtensionsAsync();
if (extensionsPayload != null)
{
result.Add("extensions", extensionsPayload);
}
}

// Add functions secrets to the payload
// Only secret types we own/control can we cache directly
// Encryption is handled by Antares before storage
Expand Down Expand Up @@ -346,7 +357,8 @@ public async Task<SyncTriggersPayload> GetSyncTriggersPayload()
}

string json = JsonConvert.SerializeObject(result);
if (json.Length > ScriptConstants.MaxTriggersStringLength)

if (json.Length > ScriptConstants.MaxTriggersStringLength && !_environment.IsKubernetesManagedHosting())
{
// The settriggers call to the FE enforces a max request size
// limit. If we're over limit, revert to the minimal triggers
Expand All @@ -366,6 +378,35 @@ public async Task<SyncTriggersPayload> GetSyncTriggersPayload()
};
}

internal async Task<JObject> GetHostJsonExtensionsAsync()
{
var hostOptions = _applicationHostOptions.CurrentValue.ToHostOptions();
TsuyoshiUshio marked this conversation as resolved.
Show resolved Hide resolved
string hostJsonPath = Path.Combine(hostOptions.RootScriptPath, ScriptConstants.HostMetadataFileName);
if (FileUtility.FileExists(hostJsonPath))
{
try
{
_logger.LogInformation("Reading host.json for SyncTrigger.");
TsuyoshiUshio marked this conversation as resolved.
Show resolved Hide resolved
var hostJson = JObject.Parse(await FileUtility.ReadAsync(hostJsonPath));
if (hostJson.TryGetValue("extensions", out JToken token))
{
return (JObject)token;
}
else
{
return null;
}
}
catch (JsonException ex)
{
_logger.LogWarning($"Unable to parse host configuration file '{hostJsonPath}'. : {ex}");
return null;
}
}

return null;
}

internal async Task<IEnumerable<JObject>> GetFunctionTriggers(IEnumerable<FunctionMetadata> functionsMetadata, ScriptJobHostOptions hostOptions)
{
var triggers = (await functionsMetadata
Expand Down Expand Up @@ -659,4 +700,4 @@ public bool HasValues()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private void VerifyResultWithCacheOn(string connection = DefaultTestConnection,
Assert.Equal("bbb", (string)function1Secrets["secrets"]["TestFunctionKey2"]);

var logs = _loggerProvider.GetAllLogMessages().Where(m => m.Category.Equals(SyncManagerLogCategory)).ToList();

var log = logs[0];
int startIdx = log.FormattedMessage.IndexOf("Content=") + 8;
int endIdx = log.FormattedMessage.LastIndexOf(')');
Expand Down Expand Up @@ -400,6 +401,7 @@ public async Task TrySyncTriggers_BackgroundSync_SetTriggersFailure_HashNotUpdat

// verify log statements
var logMessages = _loggerProvider.GetAllLogMessages().Where(m => m.Category.Equals(SyncManagerLogCategory)).Select(p => p.FormattedMessage).ToArray();

Assert.True(logMessages[0].Contains("Content="));
Assert.Equal(expectedErrorMessage, logMessages[1]);
}
Expand Down