How can I get the "real" Azure App Service slot instance name? - azure

I'd like to know how I can get a unique identifier for the "slot instance" that an Azure App Service slot has loaded into it.
Note that I am not referring to the name of the slot.
For example:
My Azure App Service has two slots named "App" (Production) and "App-Staging" (Staging).
I then deploy version 1 of my project to the "App" slot.
I then deploy version 2 of my project to the "App-Staging" slot.
I then perform a Slot Swap operation from the Azure Portal:
Both instances of my app are running simultaneously (imagine they run in a container of some kind).
Both "containers" are immediately "detached" from their associated slot while still running.
Both "containers" are then immediately re-attached to the opposing slot.
i.e. version 1 stops receiving HTTP requests for app.azurewebsites.net and suddenly starts receiving requests for app-staging.azurewebsites.net.
and version 2 stops receiving HTTP requests for app-staging.azurewebsites.net and suddenly starts receiving requests for app.azurewebsites.net.
In order to investigate some issues I was having, I created a text file at D:\home\SlotName.txt. In the "App" slot I entered "SlotA" and in the "App-Staging" slot I entered "SlotB".
This SlotName.txt moves with the application instance, and allows my application to detect which filesystem or "container" instance it's living in - and this doesn't change when a slot-swap is performed.
I find this information essential when trying to uniquely identify deployments or when investigating logging continuity issues (as the staging slot won't be logging production data, for example).
However, my SlotName.txt file seems like a hack - but I can't see any information in the Environment Variables for my app's instance that reveals the same information.
Environment variables do reveal the slot name, e.g. "App" and "App-Staging" which is mutable - of course, but it doesn't uniquely identify the "container" or filesystem instance that the app is deployed into.
Here's the two Kudu Environment pages from the Production and Staging slots - notice that the values are either identical (like Machine name), slot-specific, or refer to the deployed application code and none of them refer to the filesystem / container instance they live in:
Is there any way to get this information without using my SlotName.txt trick?

The answer hiding right under my nose - and different terminology.
What I was calling a "slot instance name" is actually referred to as a "Deployment Id" (I know this is an overloaded term as it's also used in the context of Azure's (now legacy) "Cloud Services" PaaS too).
This information is visible in the Kudu environment page and is also an exposed as an environment-variable: WEBSITE_DEPLOYMENT_ID.
The WEBSITE_DEPLOYMENT_ID value is of the form {SiteName}[__{Random}], with the __{Random} prefix omitted for the first deployment space.
If you look closely at the screenshot I posted, you'll notice the left-hand screenshot has the site-slot-name Site1__e928 whereas the right-hand screenshot is of the "first" slot-space and so its name is just Site1.
It is unfortunate that this information is not documented by Microsoft publicly - at least so far as Google can see (searching for the term right now yields zero useful relevant results):
Mystery solved!

You have something called deployment slot setting values as shown in below image:
Attach a key-value pair in each slot with different value.
Here, this setting sticks to the specific app, even if you swap.
This can be trick you're looking for.
Source

Related

in application insights, how to find the number of servers/instances for a web service at a point in time?

If you look at live metrics in AI for a web service, it shows the number of servers currently active (this is dynamic, it goes up and down dependent on load).
We have some periodic major site issues, which we think could be when Azure sales up and adds a new instance, but cant find any way of recording/tracking/graphic/querying this.
The number of servers is shown in "live Metrics". Right now I can see we have 5.
They are also show in Performance->roles, but this only shows the number of servers (aka roles) right now, I cant see any history unfortunately.
any ideas how to see if/when a new instance was created and/or destroyed?
Actually, it's difficult to find out when a new instance was created / destroyed in history, since app service plan does not support diagnostics settings.
The most similar way is to query the requests logs then you may have the change to figure out. The query like below(to write the query, in azure portal -> your application insights -> Logs):
requests
| project timestamp, cloud_RoleName, cloud_RoleInstance
| order by timestamp desc

How to really move Resources from one subscription to another one on Azure when 1 depends on another

I am trying to move a single Resourcegroup from one subscription to another one. Here how the things looked like
ResourceGroupA (I want to move between subscriptions)
-WebApp A
-SqlDB
-Plan
ResourceGroupB
-WebApp B
So WebApp B is accessing also SQlDB. When I try to move ResourceGroupA to the other Subscription, Azure returns warning that I must Move WebApp B together. It makes sense because it depends on SQLDB. Ok I moved WebApp B to the ResourceGroupA. Starting Move operation again, bump, another error. It complains
WebApp B This resource is located in resource group 'ResourceGroupA ',
but hosted in the resource group 'ResourceGroupB'. This may be a
result of prior move operations. Move it back to respective hosting
resource group
So what will be the solution now? Is there a better way to move maybe 2 ResourceGroups at the same time?
Did you try stopping the WebApp2 and then move the resources?
After 2 days i could solve the problem and i hope that it will help anyone else struggling with this problem.
Although i have described above a simple scenario, i tried to move like 20 resource together within a resource group and Azure complains every time a different resource. Like above described, it complained first a web app which is in another resource group and it suggested me that i should move it together with ResourceGroupA and move it from ResourceGroupB to ResourceGroupA. Here very important you stop the website first and move it because otherwise hosting will remain in ResourceGroupB and it will complain again as error message above. Even though you do that correctly, it complains that you should move the Plan as well if it is in other resource group. When you move it, it complains again that Plan hosting remained in the other resource group. It asks you to move back to the original ResourceGroup which makes no sense and it goes like a ping-pong game. If you make a few move operations suddenly it gets locked and gives your warning that "ResourceGroup has incomplete operation please wait". this might take entire day til you can do another attempt.
Final clear solution, if you are able to do, just publish your web app to the other subscription with a new plan and delete the old one. I have had like 3 web apps complained like that deleted all 3 and republished to the target subscription and i was able to move the rest of the resource group without any error or warning. Beside this solution it is pointless to try back and forth.

Azure App-Service Swap "Bounces" Between Source and Destination

I'm seeing some interesting behavior on Azure App Service that I'm hoping somebody will be kind enough to comment on.
Reproduction steps (all Azure steps can be done in the portal):
Create a new Web App in App Service (Standard pricing level, single instance is fine), e.g. mysite
Create a new staging slot for that App, e.g. mysite-staging
Deploy a bare-bones ASP.NET app to mysite with a file /scripts/test.js that has the content //ONE
Deploy a bare-bones ASP.NET app to mysite-staging with a file /scripts/test.js that has the content //TWO
Swap the deployment slots
Immediately after the swap starts, navigate to mysite.azurewebsites.net/scripts/test.js and monitor the returned content during the swap operation (by continually doing a force-refresh in the browser)
What I would expect to see:
At some point during the swap, the content changes seamlessly/consistently/irreversibly from //ONE to //TWO
What I actually see:
During the swap operation, the content "flickers"/"bounces" between //ONE and //TWO. After the swap operation is complete, the behavior is stable and //TWO is consistently returned
The observed behavior suggests that there is no single point in time at which all traffic can be said to be going to the new version.
The reason this concerns me is the following scenario:
A user requests a page mysite.azurewebsites.net which, during this "bouncing" stage, responds with the "v2" version of the page with a link to a CDN-hosted script mycdn.com/scripts/test.js?v2 (the ?v2 is a new query string)
The browser requests the script from the CDN, which in turn requests the script from mysite.azurewebsites.net. This time, the "bouncing" causes the response to be the v1 version of the script.
Now we have a v1 version of the script cached in the CDN, which all users in that region will load with the v2 version of the page
My question: Is this "bouncing" behavior during a swap operation "by design"? If so, what is the recommended approach for solving the pathological case above?
The behavior you've described is currently by design. When we perform the swap we update the mappings between hostnames and the sites in our database but our frontend instances cache those mappings and refresh them every 30 seconds. So the "bouncing" period may last up to 30 seconds.
I do not have at the moment a good recommendation on how to solve the case, but will look into possible ways to address this.

Windows Azure Websites - Get Instance Identifier

What's a possible way to determine on an Azure website with multiple instances what instance is responding (some ID or other piece of unique info)?
The following environment setting will have the instance id the current request is running on: WEBSITE_INSTANCE_ID.
You'll also receive this id as a cookie in the response named: ARRAffinity.
You can also use this information to get back to that specific instance, see: http://blog.amitapple.com/post/2014/03/access-specific-instance/ for more information about it.
Microsoft Azure provides many environment variables for Azure Web Apps (formerly known as Website), including the following:
WEBSITE_SITE_NAME - the name of the site.
WEBSITE_INSTANCE_ID- the id representing the VM that the site is running on.
etc
See Azure Runtime Environment by David Ebbo for more details.
You can use Server.MachineName to get the name of the server.
2022-06-06
Configuration of Web App
How to find Instance
1.This is an instance ID.
2.Go to see the environment
3.Find which variable is pl1sdlwk0001WS, and COMPUTERNAME is that you want.
Set up InstanceInputEndpoint in configuration. This will allocate ports from the given port range for each instance, then you can visit a instance through the port.
For more information about InstanceInputEndpoint: http://msdn.microsoft.com/en-us/library/windowsazure/gg557553.aspx
You can use RoleEnvironment.CurrentRoleInstance.Id
Request.ServerName I believe. Just like vanilla IIS

How do you specify the deployIisAppPath to a site root that is not DefaultWebSite?

I have a ASP.NET MVC web application project that I want to deploy to my IIS webserver. The site tree is set up thusly:
SERVERNAME(myDomain\Username)
Application Pools
Sites
Default Web Site
MyProjectSite
bin
Content
...
Views
I am trying to deploy to the MyProject site. See below settings that I am using versus the errors I am returning. I am apparently not specifying my site path correctly, but for the life of me, I can't figure out what it should be.
The following settings stay the same between iterations:
/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=False /p:MSDeployPublishMethod=WMSvc /p:AuthType=Basic /p:Username="myUserName" /p:Password="MyPassword" /p:AllowUntrustedCertificate=True
Specify SiteName/ as IISAppPath:
Parameters:
/p:MsDeployServiceUrl="https://serverName:8172/MsDeploy.axd?Site=MyProjectSite" /p:DeployIisAppPath="MyProjectSite/"
Error:
Could not complete an operation with the specified provider ("createApp") when connecting using the Web Management Service - I don't want to create a new site. I want to sync the content that is already there.
Specify IISAppPath as Root (supposing that the sitename in the URL is used)
Parameters:
/p:MsDeployServiceUrl="https://serverName:8172/MsDeploy.axd?Site=MyProjectSite" /p:DeployIisAppPath="/"
Error:
Could not complete an operation with the specified provider ("iisApp") when connecting using the Web Management Service - Looks like it is trying to access the Default WebSite or something (to which I have purposefully NOT given myself rights).
Specify IISAppPath as empty string(supposing that the sitename in the URL is used)
Parameters:
/p:MsDeployServiceUrl="https://serverName:8172/MsDeploy.axd?Site=MyProjectSite" /p:DeployIisAppPath=""
Error:
The "ConcatFullServiceUrlWithSiteName" task was not given a value for the required parameter "SiteAppName" - So it interprets "" as actually a null value thus breaking an attempt to concatenate it.
Specify no site attribute in the URL but SiteName/ as IISAppPath
Parameters:
/p:MsDeployServiceUrl="https://serverName:8172/MsDeploy.axd" /p:DeployIisAppPath="MyProjectSite/"
Error:
Could not complete an operation with the specified provider ("createApp") when connecting using the Web Management Service
Specify no site attribute in URL but SiteName as IISAppPath
Parameters:
/p:MsDeployServiceUrl="https://serverName:8172/MsDeploy.axd" /p:DeployIisAppPath="MyProjectSite"
Error:
Could not complete an operation with the specified provider ("createApp") when connecting using the Web Management Service
Now given that it is running a concatenate on the SiteAppName, it must be combining it with the Site name, yes? What are you supposed to put there to get the site to sync to the root of a site?
Update
In an attempt to figure out the proper path scheme, I have tried to publish using the Visual Studio 2012 Publish dialog. In this case, I am returned an error saying that The request timed out (testing the connection works almost instantly and previewing the changes works but takes a few seconds). I checked the event log, and the tracelog for wmsvc to no avail. Even with trace set to verbose, nothing shows up in the tracelog. I have tried disabling the firewalls on both computers, and nothing seems to work on that front either.
Figured this one out.
The problem stemmed from two settings in the Web Deploy page of the project properties. I had previously set this project up (in the Debug configuration) to copy only the files necessary to run the application, and NOT build a zip package. I neglected however to do anything to those settings for the release configuration.
The reason (confidence level 75%) it was trying to use createApp was because it was deploying from the Zip package it had created. So my IISAppPath settings in those cases were fine, I was just deploying the wrong thing.
I set the Create deployment package as a zip file setting to false, and the Items to deploy dropdown to Only files needed to run this application and everything went off without a hitch.
Incidentally I found out (as referred above) that you can use the Publish Profiles outputted by the Web Publish dialog in Visual Studio (2012 only unfortunately; 2010 you have to do some massaging that I am unsure of). I named mine with no spaces, and supplied the password as an argument as well as the Untrusted Certificate setting. Now MSBuild Arguments in the build definition for TFS look like this:
/p:DeployOnBuild=True;PublishProfile=NameOfPublishProfile /p:AllowUntrustedCertificate=True /p:Password=PleaseVerifyMe

Resources