sp-dev-fx-webparts/samples/react-dashboards
dependabot[bot] 0a2d76bfc6
Bump webpack-dev-middleware in /samples/react-dashboards
Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4.
- [Release notes](https://github.com/webpack/webpack-dev-middleware/releases)
- [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4)

---
updated-dependencies:
- dependency-name: webpack-dev-middleware
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-23 18:24:29 +00:00
..
.devcontainer added sample.json and devcontainer 2023-06-05 10:16:08 -04:00
assets Update sample.json 2023-07-17 17:45:02 -04:00
config additional spacing added for teams client 2023-08-10 16:21:06 +02:00
sharepoint/assets readme 2023-08-10 16:36:25 +02:00
src additional spacing added for teams client 2023-08-10 16:21:06 +02:00
teams readme 2023-05-30 14:18:12 +02:00
.eslintrc.js readme 2023-05-30 14:18:12 +02:00
.gitignore readme 2023-05-30 14:18:12 +02:00
.markdownlint.json readme 2023-05-30 14:18:12 +02:00
.npmignore readme 2023-05-30 14:18:12 +02:00
.yo-rc.json readme 2023-05-30 14:18:12 +02:00
README.md Updated links to devprogram 2024-02-06 11:16:44 -05:00
gulpfile.js readme 2023-05-30 14:18:12 +02:00
package-lock.json Bump webpack-dev-middleware in /samples/react-dashboards 2024-03-23 18:24:29 +00:00
package.json additional spacing added for teams client 2023-08-10 16:21:06 +02:00
pnpm-lock.yaml Bump webpack-dev-middleware in /samples/react-dashboards 2024-03-23 18:24:29 +00:00
tsconfig.json readme 2023-05-30 14:18:12 +02:00

README.md

Application Insights and Cost Management Dashboards

Summary

Sharing Application Insights and solution's cost information with your stakeholders typically requires either using Azure Dashboards or using Power BI. This sample solution allows displaying this dashboards directly in a SharePoint site or a tab in MS Teams, moving it close to the users.

This solution consists of two web parts:

  • Application Insights executes Kusto query against the Application Insights service in your Azure tenant

    Application insights

  • Cost Insights queries the usage data for the specified scope (management group, subscription, resource group) Cost Insights

Compatibility

This sample is optimally compatible with the following environment configuration:

SPFx 1.16.1 Node.js v16 | v14 | v12 Compatible with SharePoint Online Does not work with SharePoint 2019 Does not work with SharePoint 2016 (Feature Pack 2) Local Workbench Unsupported Hosted Workbench Compatible Compatible with Remote Containers

Tested with Node 16.14.2

Applies to

Get your own free development tenant by subscribing to Microsoft 365 developer program

Authors

Version history

Version Date Comments
1.0 May 30, 2023 Initial release
1.0.1 August 10, 2023 clienttype header to avoid using tenant rate limits

Prerequisites

  • Azure tenant
  • Application Insights resource (for Application Insights web part)
  • Read access to Cost Management data (for Cost Insights web part), see Required access to view data in the Azure EA subscription scopes table
  • SharePoint Administrator or Global Administrator to install the solution
  • Global Administrator permissions to approve required API access:
    • Windows Azure Service Management API: user_impersonation
    • Application Insights API: user_impersonation

Required Permissions

resource scope
Windows Azure Service Management API user_impersonation
Application Insights API user_impersonation

Minimal Path to Awesome

  • Clone this repository
  • Ensure that you are at the solution folder
  • to debug, in the command-line run:
    • npm install / pnpm install
    • gulp serve --nobrowser
  • to deploy, in the command-line run:
    • gulp bundle --ship
    • gulp package-solution --ship

Configuration

API Connection

Configuration dashboard allows defining connection settings. Application Insights requires Application ID, which you may find by navigating to Application Insights / API Access (Configure group) Cost Management access may be scoped to a management group, subscription and resource group.

Both APIs are accessed using user impersonation.

Edit API Connection

Optionally, and for Application Insights only, you may enable access with Application ID and Key. To do so, open the web part properties panel and in the Developer Settings section, enable authentication with ApiKey and AppId:

Enable access with API Key

Kusto Query / Cost Query

Both web parts have example queries that you may use to test the solution, or to treat as a starting point for defining your own queries. EditQuery

Application Insights logs are retrieved using the Application Insights API and your custom Kusto query.

In case you want to refer to the time range defined in the web part, type {TimeRange:start} in the Kusto query: Time Range

Please test your query using either Application Insights / Query - Get or query editor in Azure portal (Application Insights / Logs) to ensure the query is correct. Some expression you may use in Workspaces will not work in Application Insights Logs API and therefore, will also fail when executed using this web part.

Cost information is retrieved using the Cost Management Usage API and your custom JSON request. Please test it using Cost Management / Query - Usage

Rendering results

Results may be displayed in a table, a chart, or both. Table may be optionally formatted as a heatmap, chart supports line chart, area chart, bar chart, column chart and pie chart styles.

Edit layout

Colors may be changed to either SharePoint theme's accent colors, or gradient colors using one of the SharePoint accents.

Edit colors and chart type

Chart is rendered using Chart Control with dependency on chart.js 2.9.4. Labels and data series are detected based on the data types, e.g. datetime, string or number; currently there is no option to define custom data mappings.

Authentication

User impersonation is executed using AadHttpClient. To call the APIs, the solution requires the following Application API permissions:

  • Windows Azure Service Management API: user_impersonation
  • Application Insights API: user_impersonation

These permissions will be requested automatically once the solution is deployed, and must be granted by a Global Admin using API access page in SharePoint Administration

Authentication with Application ID and API key is also allowed for Application Insights dashboard (see Api Connection above)

Caching

PnPClientStorage is used to cache query results in local storage to avoid throttling. This is especially important when querying cost management APIs (see more information below).

By default, caching duration is set to:

  • 15 minutes for Application Insights Dashboard, and
  • 1 day for Cost Insights Dashboard

Cache duration for Application Insights Dashboard may be extended or disabled using web part properties panel. In case you want to delete the cache manually, the key names for this solution start with spfxDashboard.

Rate Limit

This solution is using clienttype header to avoid using general tenant limits and to avoid the error 429 Too many requests. Please retry.

The default rate limits when querying cost management API with/without the clienttype parameter are:

Response header without clienttype with clienttype
x-ms-ratelimit-remaining-microsoft.costmanagement-clienttype-requests 0 1995
x-ms-ratelimit-remaining-microsoft.costmanagement-entity-requests 2 0
x-ms-ratelimit-remaining-microsoft.costmanagement-tenant-requests 18 15

The Cost Management API requests are still a subject to the rate limits. The above response headers, along with x-ms-ratelimit-microsoft.costmanagement-qpu-consumed (QPUs consumed by an API call) and x-ms-ratelimit-microsoft.costmanagement-qpu-remaining (list of remaining quotas) are printed in the browser console whenever a request to the API has been made

Accessing Application Insights Data

To query Application Insights using the Application Insights Data Access API, you must authenticate:

  • To query your workspaces, use Azure Active Directory (Azure AD) authentication.
  • To quickly explore the API without using Azure AD authentication, you can use an API key to query sample data in a non-production environment. You may try it here here, by adding x-api-key header set to ApiKey value

The Log Analytics API supports Azure AD authentication with three different Azure AD OAuth2 flows: authorization code, implicit, client credentials. Client-side applications that are incapable of storing a secret, such as SharePoint Framework solutions, use OAuth implicit flow. In SharePoint Framework solutions, authorization by using the OAuth implicit flow is done as part of the framework through MSGraphClient and AadHttpClient, both of which are introduced in SharePoint Framework v1.4.1.

Developers building a SharePoint Framework solution that requires access to specific resources secured with Azure AD list these resources along with the required permission scopes in the solution manifest. When deploying the solution package to the app catalog, SharePoint creates permission requests and prompts the administrator to manage the requested permissions. For each requested permission, a global administrator can decide whether they want to grant or deny the specific permission.

All permissions are granted to the whole tenant and not to a specific application that has requested them. When the administrator grants a specific permission, its added to the SharePoint Online Client Extensibility Azure AD application, which is provisioned by Microsoft in every Azure AD and which is used by the SharePoint Framework in the OAuth flow to provide solutions with valid access tokens.

References

Application Insights

Cost Management

If you want to get the latest cost data, query at most once per day. Reports are refreshed every four hours. If you call more frequently, you'll receive identical data. The data in Usage Details is provided on a per meter basis, per day.

If you want to get large amounts of exported data regularly, see Retrieve large cost datasets recurringly with exports.

If you have scopes with a large amount of usage data (for example a Billing Account), consider placing multiple calls to child scopes so you get more manageable files that you can download. If your dataset is more than 2 GB month-to-month, consider using exports as a more scalable solution.

Using Azure APIs

Used Application API

  • f5c26e74-f226-4ae8-85f0-b4af0080ac9e Application Insights API
  • 797f4846-ba00-4fd7-ba43-dac1f8f63013 Windows Azure Service Management API

Help

We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.

If you're having issues building the solution, please run spfx doctor from within the solution folder to diagnose incompatibility issues with your environment.

You can try looking at issues related to this sample to see if anybody else is having the same issues.

You can also try looking at discussions related to this sample and see what the community is saying.

If you encounter any issues using this sample, create a new issue.

For questions regarding this sample, create a new question.

Finally, if you have an idea for improvement, make a suggestion.

Developer resources

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.