Azure-Player / azure.datafactory.tools

Tools for deploying Data Factory (v2) in Microsoft Azure
https://azureplayer.net/adftools
MIT License
207 stars 69 forks source link

Trigger Activation Failure Post-Selective Deployment #386

Open Gexdobro opened 4 months ago

Gexdobro commented 4 months ago

Describe the bug Hi Kamil!

We are using the PowerShell module for our selective ADF objects deployments, and it works great (ADF as a resource pre-exists). Basically, we defined our PowerShell script to explicitly include the desired objects to be deployed from our repository. During deployment, the only caveat is that after the first deployment (creation) of each trigger, it stays disabled, even though in the trigger JSON definition it is declared as Started (desired state). I am attaching the parameters set for a deployment below.

The described case is "S01" from your matrix-of-behavior-logic-1.

Parameters the script has been run with:

Includes                       : {[pipeline.example_1, AdfObject], [trigger.example_1, ], [linkedService.example_1, ],[pipeline.example_2, AdfObject]…}
Excludes                       : {}
DeleteNotInSource              : True
StopStartTriggers              : True
CreateNewInstance              : False
DeployGlobalParams             : True
FailsWhenConfigItemNotFound    : True
FailsWhenPathNotFound          : True
IgnoreLackOfReferencedObject   : False
DoNotStopStartExcludedTriggers : False
DoNotDeleteExcludedObjects     : True
IncrementalDeployment          : False
TriggerStopMethod              : DeployableOnly
TriggerStartMethod             : BasedOnSourceCode

To Reproduce Generate a PowerShell script with parameters mirroring the ones provided above. Execute the script to initiate a selective deployment.

Expected behavior Trigger is active after first selective deployment.

Version of PowerShell module of: azure.datafactory.tools 1.8.0

Logs

The deployment log erroneously indicates that the trigger has already started, despite it not being active in reality.

===================================================================================
STEP: Starting triggers...
TriggerStartMethod = BasedOnSourceCode
- Trigger already started: example_1

Trigger definition

{
    "name": "example_1",
    "properties": {
        "annotations": [],
        "runtimeState": "Started",
        "pipelines": [
            {
                "pipelineReference": {
                    "referenceName": "example_1",
                    "type": "PipelineReference"
                }
            }
        ],
        "type": "ScheduleTrigger",
        "typeProperties": {
            "recurrence": {
                "frequency": "Month",
                "interval": 12,
                "startTime": "2024-01-15T10:54:00Z",
                "timeZone": "UTC",
                "schedule": {
                    "minutes": [
                        0
                    ],
                    "hours": [
                        0
                    ],
                    "monthDays": [
                        1
                    ]
                }
            }
        }
    }
}
NowinskiK commented 4 months ago

Are you sure that the trigger is NOT Started after the deployment? Can you double check that with the following code?

Get-AzDataFactoryV2Trigger -ResourceGroupName "ADF" -DataFactoryName "WikiADF"
Gexdobro commented 4 months ago

Thank you for your quick answer!

Yes, I am certain these triggers stays "Stopped" deployment regardless of the runtimeState value in the JSON definition trigger file, at least with the presented above parameters. I have double checked the post-deployment status in the portal and also using the PowerShell command you suggested.

NowinskiK commented 4 months ago

It must be some specific scenario in your case because this is a very common pattern to deploy and start a trigger. This normally works for hundreds if not thousands of users (including Unit Test), otherwise I would get this issue here immediately. Can you proof this doesn't work within some video or script so I could easily run & reproduce the issue?

Gexdobro commented 4 months ago

At the moment I can only share the script below unfortunately:

param
(
    [parameter(Mandatory = $true)] [String] $rootFolder,
    [parameter(Mandatory = $true)] [String] $dataFactoryName,
    [parameter(Mandatory = $true)] [String] $resourceGroupName,
    [parameter(Mandatory = $true)] [String] $location
)

$adf = Import-AdfFromFolder -RootFolder "$rootFolder" -FactoryName $dataFactoryName
$opt = New-AdfPublishOption

# Trigger:
$opt.Includes.Add("trigger.trigger1", "")

# Other objects
$opt.Includes.Add("integrationruntime.*", "")
$opt.Includes.Add("factory.*", "")
$opt.Includes.Add("managedVirtualNetwork.*", "")

$opt.CreateNewInstance = $false
$opt.DeleteNotInSource = $true
$opt.TriggerStopMethod = "DeployableOnly"

Publish-AdfV2FromJson -RootFolder "$rootFolder" -ResourceGroupName "$resourceGroupName" -DataFactoryName "$dataFactoryName" -Location "$location" -Option $opt

A trigger json definition can be as the one described in the previous comment.

I believe a critical factor that might be contributing to this problem is the parameter $opt.TriggerStopMethod being set to "DeployableOnly" - but for a selective deployment this value is desired. Here is a very similar lead but in this case trigger is defined as already deployed (second run):

https://github.com/Azure-Player/azure.datafactory.tools/discussions/369

Gexdobro commented 4 months ago

Hi @NowinskiK - will you be able to help with this issue?

NowinskiK commented 4 months ago

I have limited capacity atm, but I will take a look at this as soon as I can.

Gexdobro commented 4 months ago

Thank you very much! Your assistance would be greatly appreciated!

NowinskiK commented 4 months ago

This only happens when TriggerStopMethod = 'DeployableOnly'