BookmarkSubscribeRSS Feed

Operate SAS Viya from MS Teams

Started ‎11-10-2023 by
Modified ‎11-10-2023 by
Views 447

Some time ago, my colleague Raphael Poumarede shared how to Reduce the Azure bill when you are not using the SAS Viya environment.

 

To be even more cost effective in cloud resources, a common approach is to schedule the stop and the start of your Kubernetes cluster at fixed hours. At the same time and to not limit the SAS users, the decision is usually taken to delay the stop “as late as possible” in the evening and to anticipate the restart “as soon as possible” in the morning.

What if the SAS Users can play a role to optimize the cloud costs?

What if the SAS Users can decide to postpone a stop or anticipate a start by themself without anyone to be involved?

In this post I will share an example on how this can be achieved. This example will mainly be using Azure resources as they simplify the integration with MS Teams, but the concept can be adapted to any cloud provider.

 

Microsoft Tools used

 

Microsoft Teams Microsoft Teams is a collaboration platform for communication, meetings, and teamwork within organizations. It integrates with Microsoft 365 apps and offers features like chat, video conferencing, and document sharing. We are using Teams as a “simple” way to trigger an action.

 

Azure Logic Apps Azure Logic App automates tasks and integrates apps and services in the cloud. It offers a visual interface for creating workflows without extensive coding. This simplifies and accelerates business processes. 

We are using Logic App as a sequencer for all tasks.

 

Azure DevOps  Azure DevOps is Microsoft's integrated suite of development tools and services. It covers the software development lifecycle, enabling teams to collaborate, automate workflows, and deliver high-quality software efficiently.

We are using Azure DevOps to get access to external commands (kubectl) not available in Logic App.

 

Prerequisites

 

  1. SAS Viya platform is configured and available
  2. Microsoft - Create a standard or private channel in Microsoft Teams
  3. Microsoft - Create Incoming Webhooks
  4. The ability to create a Microsoft Logic App in the Azure Portal

 

Process overview in Microsoft Teams

 

The following screenshot shows an example of implementing this approach.

 

DE_01_MSTeams.jpg

 Select any image to see a larger version.

Mobile users: If you do not see this image, scroll to the bottom of the page and select the "Full" version of this post.

 

Start Process

 

Step1: The user (here David) sends a message to start the SAS Viya platform.

Step 2: The system will respond that the received has been received. This is only to confirm that the request has been received until the SAS Viya platform will be up-and-running.

Step 3: When the SAS Viya platform is completely up-and running the system sends the message in the channel with the URL of the environment.

 

Stop Process

 

Step1: The user (here David) sends a message to stop the SAS Viya platform.

Step2: The system sends the message when the SAS Viya platform is completely stopped.

 

Logic App Flow Design (for the Start Process)

 

The general idea is to use the Logic App as a sequencer for the following steps:

 

  • Trigger the sequence when a keyword is used in a specific channel in MS Teams
  • Send a “request received” to acknowledge the request
  • List the associated Azure Resources
  • For each Flexible Server (if you are using an external PostGreSQL instances)
    • List them (if more than one, i.e for CDS instances)
    • Start them using the Azure Microsoft.DBforPostgreSQL API
  • For each AKS Cluster
    • List them
    • Start them using the Azure Microsoft.ContainerService API
      • This will start the AKS Cluster
      • Therefore, will start the SAS Viya Platform
  • Trigger an Azure DevOps pipeline to
    • Run a kubectl command the check the status of the SAS Viya platform (and wait for a complete start)
    • Send a message when the platform is fully available

 

Here is the graphical overview of the Logic App I designed in Microsoft Portal.

 

02_DE_Overview.jpg

 

Now let’s describe each node of this Logic App.

 

 

03_DE_When_keywords_are_mentioned.jpg

 

When keywords are mentioned

Step Type: Microsoft Teams: When keywords are mentioned

This is where you will define your “trigger”.

I used the keyword StartSASViya in Team “SAS Viya Environment” in the channel “Personal -Latest”.

Hints: Don’t use # in the keywords

 

04_DE_HTTP_Post_message_in_a_chat_or_channel.jpg

 

HTTP Post message in a chat or channel

Step Type: HTTP

This step is a call to your predefined WebHooks.

The content of the message is in JSON format, click on the image to see the content

 

05_DE_List_resources_by_resource_group.jpg

 

List resources by resource group

Step Type: Azure Resource Manager

This step will retrieve all Azure resources in the “fradae-stable-202308-rg” resource group.

 

06_DE_Get_Flexible_Servers.jpg

 

Get Flexible Servers

Step Type: Variables Built-in

This step will filter the previous output only with object with type: “Microsoft.DBforPostgreSQL/flexibleServers”

 

07_DE_For_each_Flexible_Server.jpg

 

For each Flexible Server

Step Type: For each (Control)

This step will loop on each “Flexible Server” in the resource group. This step will first get the full ID of the Flexible Server in this format: /subscriptions/c1b1cbfa-699a-47f5-95c5-aaaaaaaaaaaa/resourceGroups/fradae-stable-

202308/rg/providers/Microsoft.DBforPostgreSQL/

flexibleServers/fradae-stable-202308-default-flexpsql

Then we will extract the variable needed to be able to start the Flexible Server through an API :

 

  • Subscription ID
  • Resource Group
  • Flexible Server Name

 

The method used is to “Split” the ID, (i.e for the Subscription ID : split(outputs('Extract_PG_ID'),'/')[2]). This will extract

c1b1cbfa-699a-47f5-95c5-aaaaaaaaaaaa.

The same method is used for the other needed variables. The last step is the actual start of the “Flexible Server” using the API described here

 

 

08_DE_Get_AKS_Clusters-.jpg

 

Get AKS Clusters (same logic as for Flexible Server)

Step Type: Variables Built-in

This step will filter the previous output only with object with type: “Microsoft.ContainerService/managedClusters”

 

09_DE_For_each_AKS_Cluster.jpg

 

For each AKS Cluster (same logic as for Flexible Server)

Step Type: For each (Control)

The last step is the actual start of the “AKS Cluster” using the API described here

 

10_DE_Send_an_HTTP_request_to_Azure_DevOps-1.jpg

 

Send an HTTP request to Azure DevOps

Step Type: Send an HTTP requests to Azure DevOps

This will trigger a DevOps pipeline (mainly to be able to use a kubectl command) to wait until the SAS Viya Platform will be fully functional.

Then the pipeline will send the completion message in the same predefined WebHooks.

The content of the request Body is in JSON format, click on the image to see the content

Hints: The JSON object resources.repositories.self.refName is mandatory and should reflect your Azure DevOps branch name of the pipeline you want to execute

 

Conclusion

 

This example shows how SAS Users can be an active part of the cloud cost optimization. Some other examples could be implemented using the same approach:

 

  • Same logic could be used to stop the SAS Viya platform
  • A more "controlled” flow could be designed to add some approval steps between a “SAS User” request for a restart and the request to the “SAS Admin” Team that will consume the logic to start the SAS Viya platform
  • If you have scheduled stops (based on tags), you can define Logic Apps to avoid the stop
  • Time-based Logic App to define when critical batch will run

 

I hope this brief example of the integration between Azure Logic App / Microsoft Teams and the SAS Viya platform will be useful to you.

Special thanks to Thomas and Pooja as this example was inspired by the combination of this post from Thomas Stringer, Schedule AKS Clusters to Start and Stop Automatically and a post from my colleague Pooja Dalal and customized it to add the MS Teams interaction.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎11-10-2023 08:10 AM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags