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

fix Function on Kubernetes for Python V2 progamming model #3676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kevin808
Copy link

Issue describing the changes in this PR

Resolves python programming V2 does not work with function on kubernetes

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

@kevin808
Copy link
Author

@microsoft-github-policy-service agree company="Microsoft"

@kshyju
Copy link
Member

kshyju commented Jul 9, 2024

@vrdmr / @gavin-aguiar Could you review this?

@liliankasem
Copy link
Member

@vrdmr / @gavin-aguiar Could you review this?

ping @vrdmr @gavin-aguiar - thank you!

@aishwaryabh aishwaryabh changed the base branch from v4.x to main November 26, 2024 20:23
@aishwaryabh aishwaryabh requested a review from a team as a code owner November 26, 2024 20:23
@@ -233,6 +241,19 @@ private async Task<TriggersPayload> GetTriggersLocalFiles()
};
}

private static bool IsWorkerIndexingEnabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed. Worker indexing is default now

@@ -220,7 +226,9 @@ private async Task<TriggersPayload> GetTriggersLocalFiles()
}
}

var functionsJsons = GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnetIsolated
var useMetadata = GlobalCoreToolsSettings.CurrentWorkerRuntime == WorkerRuntime.dotnetIsolated || IsWorkerIndexingEnabled();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we checking for dotnet isolated?

{
var functionAppPath = Path.Combine(functionsPath, "function_app.py");

var functionAppContents = await File.ReadAllTextAsync(functionAppPath);

Choose a reason for hiding this comment

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

Wrap I/O operations in try-catch blocks and log errors

{
{"type", $"httpTrigger"},
{"direction", "In"},
{"name", "req"},

Choose a reason for hiding this comment

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

Lots of repeated constants can go on top of the file for readability or a method can we created to better manage bindings for different triggerType..

private static List<Dictionary<string, object>> ParsePythonFunctionApp(string contents)
{
var functionMetadataList = new List<Dictionary<string, object>>();
var functionPattern = new Regex(@"@app\.(\w+)(?:_trigger)?\(([^)]+)\)\s+def (\w+)\(", RegexOptions.Compiled | RegexOptions.Multiline);

Choose a reason for hiding this comment

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

NIT: Add a comment explaining the what this regex does.

{"connection", properties["connection"]},
{"cardinality", "One"},
{"properties", new Dictionary<string, object> { { "supportsDeferredBinding", "True" } } }
});

Choose a reason for hiding this comment

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

Checking: should you flatten the nested dictionary with an class (or an entity)?

});
break;
// Add additional cases for other trigger types if necessary
}

Choose a reason for hiding this comment

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

If a new or unknown trigger type is encountered, it silently does nothing. This can cause hard-to-debug issues. IMHO extra logging will help here.

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.

6 participants