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

Linux Consumption metrics publisher for Legion #10750

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

vivekjilla
Copy link

@vivekjilla vivekjilla commented Jan 16, 2025

Issue describing the changes in this PR

This PR pulls in the new metrics component for Linux Consumption in Legion environments
This is exactly same as: #9741, except for few changes which I highlighted as Qs in comments below.

resolves #issue_for_this_pr

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

/// <returns><see cref="true"/> if the app is V1 Linux Consumption running on Legion; otherwise, <see cref="false"/>.</returns>
public static bool IsV1LinuxConsumptionOnLegion(this IEnvironment environment)
{
return IsLinuxConsumptionOnLegion(environment); //&& environment.WebsiteSkuIsDynamic();
Copy link
Author

@vivekjilla vivekjilla Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out how to distinguish between cv2 vs cv1 in legion based on environment variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a unique environmental value/flag that we're specifying for Cv1 that isn't present for Flex apps. Perhaps the SKU value? @balag0 what would you recommend we use to distinguish here? We need this check to return True for Cv1 on Legion and False for Flex apps.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CV2
LEGION_SERVICE_HOST = 1
WEBSITE_SKU = FlexConsumption

CV1 on Legion
LEGION_SERVICE_HOST = 1
WEBSITE_SKU_NAME or WEBSITE_SKU = Dynamic

@vivekjilla vivekjilla changed the title User/vijilla/legion cv1 metrics Linux Consumption metrics publisher for Legion Jan 29, 2025
@vivekjilla vivekjilla marked this pull request as ready for review January 29, 2025 04:44
@vivekjilla vivekjilla requested a review from a team as a code owner January 29, 2025 04:44
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_metricsTracker = metricsTracker ?? throw new ArgumentNullException(nameof(metricsTracker));
//_metricsLogger = metricsLogger ?? throw new ArgumentNullException(nameof(metricsLogger));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the metricsLogger dependency here (as metricsLogger depends on metricsPublisher and is causing cyclic dependency). The original code: https://github.com/Azure/azure-functions-host/pull/9741/files#diff-b40529fc8edfa035050463add05ab73052020dd74d615cdd5e939b860e739d5b.

Seems like it was being used to log the OnMetricsDiagnosticEvent. So we need to figure out a way to add it back and refactor it out to remove the cyclic dependency. @mathewc any suggestions here.

Copy link
Member

@mathewc mathewc Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. One way to break this cycle is to employ the Service Locator antipattern as we've done in other places in the code to resolve these, e.g. here.

So you could add an IScriptHostManager ctor param then use it to resolve the metrics logger. You'd define a helper property MetricsLogger that would do the service resolution.

@fabiocav in case he has another idea :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as per suggestion.

@@ -58,6 +58,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.1" />
<PackageReference Include="Microsoft.Azure.AppService.Middleware.Functions" Version="1.5.5" />
<PackageReference Include="Microsoft.Azure.AppService.Proxy.Client" Version="2.3.20240307.67" />
<PackageReference Include="Microsoft.Azure.Functions.Platform.Metrics.LinuxConsumption" Version="1.0.4" />
Copy link
Author

@vivekjilla vivekjilla Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to setup official build pipeline to publish this package. Currently this one was manually uploaded as per: #9741 (comment)

var logger = s.GetService<ILogger<LinuxContainerLegionMetricsPublisher>>();
var metricsTracker = s.GetService<ILinuxConsumptionMetricsTracker>();
var standbyOptions = s.GetService<IOptionsMonitor<StandbyOptions>>();
//var metricsLogger = s.GetService<IMetricsLogger>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Once we fix the cyclic ref update this code

@@ -280,7 +286,15 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
services.AddSingleton<IMetricsPublisher>(s =>
{
var environment = s.GetService<IEnvironment>();
if (environment.IsFlexConsumptionSku())
if (environment.IsV1LinuxConsumptionOnLegion())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename this env helper to IsLinuxConsumptionOnLegion, which matches IsLinuxConsumptionOnAtlas

/// </summary>
/// <param name="environment">The environment to check.</param>
/// <returns><see cref="true"/> if the sku is Dynamic; otherwise, <see cref="false"/>.</returns>
public static bool WebsiteSkuIsDynamic(this IEnvironment environment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD if we need this - when I did the first PR this was a work in progress and we were thinking we could check the sku in this way to determine

[InlineData(true, null, ScriptConstants.DynamicSku, true)]
[InlineData(true, ScriptConstants.DynamicSku, null, true)]
[Trait(TestTraits.Group, TestTraits.LinuxConsumptionMetricsTests)]
public void IsV1LinuxConsumptionOnLegion_ReturnsExpectedResult(bool isLinuxConsumptionOnLegion, string websiteSku, string websiteSkuName, bool expectedValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After rename, fix this to IsLinuxConsumptionOnLegion_ReturnsExpectedResult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants