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

Can't use Azure App Configuration as a source for ConnectionStringSetting #1149

Open
djseng opened this issue Nov 21, 2024 · 2 comments
Open

Comments

@djseng
Copy link

djseng commented Nov 21, 2024

  • Azure Functions SQL Extension or Extension Bundle Version:
    c# net8 isolated function
    Microsoft.Azure.Functions.Worker.Extensions.Sql;3.1.284

  • Is this a deployed or local function: either

  • What type of Database are you using? (Run SELECT @@VERSION as Version, SERVERPROPERTY('EngineEdition') as EngineEdition on your database)
    deployed: Microsoft SQL Azure (RTM) - 12.0.2000.8
    Oct 2 2024 11:51:41
    Copyright (C) 2022 Microsoft Corporation, 5
    local: Version EngineEdition
    Microsoft SQL Server 2019 (RTM-CU27-GDR) (KB5040948) - 15.0.4382.1 (X64)
    Jul 1 2024 20:03:23
    Copyright (C) 2019 Microsoft Corporation
    Express Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 22621: ) (Hypervisor), 4

  • List any custom settings for your function app. This could be a custom time-out defined specifically for your database server or optional configuration that can be customized for the app defined here.
    no custom settings

Steps to Reproduce:

  1. add App Configuration instance to IConfigation

Program.cs

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureAppConfiguration(
        builder =>
        {
            var config = builder.Build();
            builder.AddAzureAppConfiguration(options =>
            {
                options.Connect(config["AppConfigConnectionString"]);
            });
        })
    .Build();

host.Run();
  1. specify key that is defined in Azure App Configuration

CollectEvents.cs

using Azure.Messaging.EventGrid;

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Sql;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Test;

public class CollectEvents
{
    private readonly ILogger _logger;
    private readonly IConfiguration _config;

    public CollectEvents(ILogger<CollectEvents> logger, IConfiguration config)
    {
        _logger = logger;
        _config = config;
    }

    [Function("CollectEvents")]
    [SqlOutput("Operations.ActivityLog",
        "SqlConnectionString" // complains about missing connection string
    )]
    public ActivityLog Run([EventGridTrigger] EventGridEvent eventGridEvent)
    {
        _logger.LogInformation("SqlConnectionString: {SqlConnectionString}",
            _config["SqlConnectionString"]); // outputs expected connection string

        var log = new ActivityLog
        {
            Id = eventGridEvent.Id,
            EventTime = eventGridEvent.EventTime,
            EventType = eventGridEvent.EventType,
            Subject = eventGridEvent.Subject,
            DataVersion = eventGridEvent.DataVersion,
            Topic = eventGridEvent.Topic,
        };
        return log;
    }
}

public class ActivityLog
{
    public string Id { get; set; } = null!;
    public DateTimeOffset EventTime { get; set; }
    public string EventType { get; set; } = null!;
    public string Subject { get; set; } = null!;
    public string DataVersion { get; set; } = null!;
    public string? Topic { get; set; }
}
@Charles-Gagnon
Copy link
Contributor

I'm not really familiar with this Azure App Configuration stuff so I don't have an immediate answer, but digging around some other issues found this response to a similar question : Azure/azure-functions-host#9598 (comment)

This is just a lead: I remember reading that Event-based scaling doesn't allow dynamic elements in the function signature, all queues, databases, etc need to be hardcoded, constant, or app setting reference.
However, it is possible when Runtime-based scaling is enabled (Configuration --> Function Runtime Settings --> Runtime Scale Monitoring). This setting has conditions and affects a wider range of behaviour so check if that matches your use case.

In case that helps at all.

Is this functionality that you've successfully used in other extensions for signature provided parameters?

In any case, a workaround is always to just use the Azure Function app settings and define your connection string there. Not ideal I realize, but hopefully that could at least unblock you until we can figure out if this is even possible to support currently.

@waynebrantley
Copy link

@djseng I wish we could do that. This is a shortcoming of all azure functions that use attributes where a connection string is provided.

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

No branches or pull requests

3 participants