Skip to content

Commit bd45d3c

Browse files
Rakshith Bhyravabhotlascottaddie
andauthored
Migration Guide from Azure-loganalytics (Azure#21674)
* Migration Guide from Azure-loganalytics * Apply suggestions from code review Co-authored-by: Scott Addie <[email protected]> * Update sdk/monitor/azure-monitor-query/migration_guide.md Co-authored-by: Scott Addie <[email protected]> * Apply suggestions from code review Co-authored-by: Scott Addie <[email protected]> * Update sdk/monitor/azure-monitor-query/migration_guide.md Co-authored-by: Scott Addie <[email protected]> Co-authored-by: Scott Addie <[email protected]>
1 parent 13f2d0f commit bd45d3c

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Guide for migrating from azure-loganalytics v0.1.0 to azure-monitor-query v1.0.x
2+
3+
This guide assists you in the migration from [azure-loganalytics](https://pypi.org/project/azure-loganalytics/) v0.1.0 to [azure-monitor-query](https://pypi.org/project/azure-monitor-query/) v1.0.x. Side-by-side comparisons are provided for similar operations between the two packages.
4+
5+
Familiarity with the `azure-loganalytics` v0.1.0 package is assumed. If you're new to the Azure Monitor Query client library for Python, see the [README for `azure-monitor-query`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/README.md) instead of this guide.
6+
7+
## Table of contents
8+
9+
- [Migration benefits](#migration-benefits)
10+
- [Cross-service SDK improvements](#cross-service-sdk-improvements)
11+
- [New features](#new-features)
12+
- [Important changes](#important-changes)
13+
- [The client](#the-client)
14+
- [Client constructors and authentication](#client-constructors-and-authentication)
15+
- [Send a single query request](#sending-a-single-query-request)
16+
- [Additional samples](#additional-samples)
17+
18+
## Migration benefits
19+
20+
A natural question to ask when considering whether to adopt a new version or library is what the benefits of doing so would be. As Azure has matured and been embraced by a more diverse group of developers, we've focused on learning the patterns and practices to best support developer productivity and to understand the gaps that the Python client libraries have.
21+
22+
Several areas of consistent feedback were expressed across the Azure client library ecosystem. One of the most important is that the client libraries for different Azure services haven't had a consistent approach to organization, naming, and API structure. Additionally, many developers have felt that the learning curve was too steep. The APIs didn't offer an approachable and consistent onboarding story for those learning Azure or exploring a specific Azure service.
23+
24+
To improve the development experience across Azure services, a set of uniform [design guidelines](https://azure.github.io/azure-sdk/general_introduction.html) was created for all languages to drive a consistent experience with established API patterns for all services. A set of [Python-specific guidelines](https://azure.github.io/azure-sdk/python/guidelines/index.html) was also introduced to ensure that Python clients have a natural and idiomatic feel with respect to the Python ecosystem. Further details are available in the guidelines.
25+
26+
### Cross-service SDK improvements
27+
28+
The Azure Monitor Query client library also takes advantage of the cross-service improvements made to the Azure development experience. Examples include:
29+
30+
- Using the new [`azure-identity`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md) library to share a single authentication approach between clients.
31+
- A unified logging and diagnostics pipeline offering a common view of the activities across each of the client libraries.
32+
33+
### New features
34+
35+
There are a variety of new features in version 1.0 of the Monitor Query library. Some include:
36+
37+
- The ability to execute a batch of queries with the `LogsQueryClient.query_batch()` API.
38+
- The ability to configure the retry policy used by the operations on the client.
39+
- Authentication with Azure Active Directory (Azure AD) credentials using [`azure-identity`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md).
40+
41+
For more new features, changes, and bug fixes, see the [change log](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/CHANGELOG.md).
42+
43+
## Important changes
44+
45+
### The client
46+
47+
To provide a more intuitive experience, the top-level client to query logs was renamed to `LogsQueryClient` from `LogAnalyticsDataClient`. `LogsQueryClient` can be authenticated using Azure AD. This client is the single entry point to execute a single query or a batch of queries.
48+
49+
#### Consistency
50+
51+
There are now methods with similar names, signatures, and locations to create senders and receivers. The result is consistency and predictability on the various features of the library.
52+
53+
### Client constructors and authentication
54+
55+
In `azure-loganalytics` v0.1.0:
56+
57+
```python
58+
from azure.loganalytics import LogAnalyticsDataClient
59+
from msrestazure.azure_active_directory import ServicePrincipalCredentials
60+
61+
credential = ServicePrincipalCredentials(...)
62+
client = LogAnalyticsDataClient(credentials=credential)
63+
```
64+
65+
In `azure-monitor-query` v1.0.x:
66+
67+
```python
68+
from azure.monitor.query import LogsQueryClient
69+
from azure.identity import DefaultAzureCredential
70+
71+
credential = DefaultAzureCredential()
72+
client = LogsQueryClient(credential=credential)
73+
```
74+
75+
### Send a single query request
76+
77+
In version 1.0 of the Monitor Query library:
78+
79+
- The `QueryBody` is flattened. Users are expected to pass the Kusto query directly to the API.
80+
- The `timespan` attribute is now required, which helped to avoid querying over the entire data set.
81+
82+
In `azure-loganalytics` v0.1.0:
83+
84+
```python
85+
from azure.loganalytics.models import QueryBody
86+
87+
query = 'AppRequests | take 5'
88+
response = client.query(workspace_id, QueryBody(**{'query': query}))
89+
```
90+
91+
In `azure-monitor-query` v1.0.x:
92+
93+
```python
94+
query = 'AppRequests | take 5'
95+
client.query(workspace_id, query, timespan=timedelta(days=1))
96+
```
97+
98+
## Additional samples
99+
100+
For more examples, see [Samples for azure-monitor-query](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-query/samples).

0 commit comments

Comments
 (0)