Skip to content

[Monitor Ingestion] Add typespec generation files #41923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/monitor/azure-monitor-ingestion/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
recursive-include tests *.py
recursive-include samples *.py
include *.md
include LICENSE
include azure/monitor/ingestion/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include azure/__init__.py
include azure/monitor/__init__.py
include azure/monitor/ingestion/py.typed
3 changes: 3 additions & 0 deletions sdk/monitor/azure-monitor-ingestion/_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"apiVersion": "2023-01-01"
}
4 changes: 4 additions & 0 deletions sdk/monitor/azure-monitor-ingestion/apiview-properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"CrossLanguagePackageId": "LogsIngestion",
"CrossLanguageDefinitionId": {}
}
2 changes: 1 addition & 1 deletion sdk/monitor/azure-monitor-ingestion/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/monitor/azure-monitor-ingestion",
"Tag": "python/monitor/azure-monitor-ingestion_12276a5674"
"Tag": "python/monitor/azure-monitor-ingestion_fd63ae0a28"
}
2 changes: 1 addition & 1 deletion sdk/monitor/azure-monitor-ingestion/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position
Expand All @@ -13,6 +13,9 @@
from ._patch import * # pylint: disable=unused-wildcard-import

from ._client import LogsIngestionClient # type: ignore
from ._version import VERSION

__version__ = VERSION

try:
from ._patch import __all__ as _patch_all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

Expand All @@ -16,28 +16,30 @@

from ._configuration import LogsIngestionClientConfiguration
from ._operations import LogsIngestionClientOperationsMixin
from ._serialization import Deserializer, Serializer
from ._utils.serialization import Deserializer, Serializer

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential


class LogsIngestionClient(LogsIngestionClientOperationsMixin):
"""Azure Monitor Data Collection Python Client.
"""Azure Monitor data collection client.

:param endpoint: The Data Collection Endpoint for the Data Collection Rule, for example
https://dce-name.eastus-2.ingest.monitor.azure.com. Required.
:param endpoint: The Data Collection Endpoint for the Data Collection Rule. For example,
`https://dce-name.eastus-2.ingest.monitor.azure.com
<https://dce-name.eastus-2.ingest.monitor.azure.com>`_. Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: Api Version. Default value is "2023-01-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: The API version to use for this operation. Default value is "2023-01-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
_endpoint = "{endpoint}"
self._config = LogsIngestionClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)

_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, TYPE_CHECKING

from azure.core.pipeline import policies

from ._version import VERSION

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential

VERSION = "unknown"


class LogsIngestionClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for LogsIngestionClient.
Note that all parameters used to create this instance are saved as instance
attributes.
:param endpoint: The Data Collection Endpoint for the Data Collection Rule, for example
https://dce-name.eastus-2.ingest.monitor.azure.com. Required.
:param endpoint: The Data Collection Endpoint for the Data Collection Rule. For example,
`https://dce-name.eastus-2.ingest.monitor.azure.com
<https://dce-name.eastus-2.ingest.monitor.azure.com>`_. Required.
:type endpoint: str
:param credential: Credential needed for the client to connect to Azure. Required.
:param credential: Credential used to authenticate requests to the service. Required.
:type credential: ~azure.core.credentials.TokenCredential
:keyword api_version: Api Version. Default value is "2023-01-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: The API version to use for this operation. Default value is "2023-01-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

Expand All @@ -43,7 +44,7 @@ def __init__(self, endpoint: str, credential: "TokenCredential", **kwargs: Any)
self.endpoint = endpoint
self.credential = credential
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://monitor.azure.com//.default"])
self.credential_scopes = kwargs.pop("credential_scopes", ["https://monitor.azure.com/.default"])
kwargs.setdefault("sdk_moniker", "monitor-ingestion/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from collections.abc import MutableMapping
from io import IOBase
import sys
import json
from typing import Any, Callable, Dict, IO, List, Optional, TypeVar, Union, overload

from azure.core import PipelineClient
from azure.core.exceptions import (
ClientAuthenticationError,
HttpResponseError,
Expand All @@ -22,14 +24,11 @@
from azure.core.tracing.decorator import distributed_trace
from azure.core.utils import case_insensitive_dict

from .._serialization import Serializer
from .._vendor import LogsIngestionClientMixinABC
from .._configuration import LogsIngestionClientConfiguration
from .._utils.model_base import SdkJSONEncoder
from .._utils.serialization import Serializer
from .._utils.utils import ClientMixinABC

if sys.version_info >= (3, 9):
from collections.abc import MutableMapping
else:
from typing import MutableMapping # type: ignore
JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object
T = TypeVar("T")
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]

Expand All @@ -38,7 +37,7 @@


def build_logs_ingestion_upload_request(
rule_id: str, stream: str, *, content_encoding: Optional[str] = None, **kwargs: Any
rule_id: str, stream_name: str, *, content_encoding: Optional[str] = None, **kwargs: Any
) -> HttpRequest:
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
Expand All @@ -51,7 +50,7 @@ def build_logs_ingestion_upload_request(
_url = "/dataCollectionRules/{ruleId}/streams/{stream}"
path_format_arguments = {
"ruleId": _SERIALIZER.url("rule_id", rule_id, "str"),
"stream": _SERIALIZER.url("stream", stream, "str"),
"stream": _SERIALIZER.url("stream_name", stream_name, "str"),
}

_url: str = _url.format(**path_format_arguments) # type: ignore
Expand All @@ -69,14 +68,16 @@ def build_logs_ingestion_upload_request(
return HttpRequest(method="POST", url=_url, params=_params, headers=_headers, **kwargs)


class LogsIngestionClientOperationsMixin(LogsIngestionClientMixinABC):
class LogsIngestionClientOperationsMixin(
ClientMixinABC[PipelineClient[HttpRequest, HttpResponse], LogsIngestionClientConfiguration]
):

@overload
def _upload(
self,
rule_id: str,
stream: str,
body: List[JSON],
stream_name: str,
body: List[Dict[str, Any]],
*,
content_encoding: Optional[str] = None,
content_type: str = "application/json",
Expand All @@ -86,7 +87,7 @@ def _upload(
def _upload(
self,
rule_id: str,
stream: str,
stream_name: str,
body: IO[bytes],
*,
content_encoding: Optional[str] = None,
Expand All @@ -98,24 +99,26 @@ def _upload(
def _upload( # pylint: disable=inconsistent-return-statements
self,
rule_id: str,
stream: str,
body: Union[List[JSON], IO[bytes]],
stream_name: str,
body: Union[List[Dict[str, Any]], IO[bytes]],
*,
content_encoding: Optional[str] = None,
**kwargs: Any
) -> None:
"""Ingestion API used to directly ingest data using Data Collection Rules.

See error response code and error response message for more detail.
Ingestion API used to directly ingest data using Data Collection Rules.

:param rule_id: The immutable Id of the Data Collection Rule resource. Required.
:param rule_id: The immutable ID of the Data Collection Rule resource. Required.
:type rule_id: str
:param stream: The streamDeclaration name as defined in the Data Collection Rule. Required.
:type stream: str
:param body: An array of objects matching the schema defined by the provided stream. Is either
a [JSON] type or a IO[bytes] type. Required.
:type body: list[JSON] or IO[bytes]
:keyword content_encoding: gzip. Default value is None.
:param stream_name: The streamDeclaration name as defined in the Data Collection Rule.
Required.
:type stream_name: str
:param body: The array of objects matching the schema defined by the provided stream. Is either
a [{str: Any}] type or a IO[bytes] type. Required.
:type body: list[dict[str, any]] or IO[bytes]
:keyword content_encoding: The content encoding of the request body which is always 'gzip'.
Default value is None.
:paramtype content_encoding: str
:return: None
:rtype: None
Expand All @@ -136,20 +139,18 @@ def _upload( # pylint: disable=inconsistent-return-statements
cls: ClsType[None] = kwargs.pop("cls", None)

content_type = content_type or "application/json"
_json = None
_content = None
if isinstance(body, (IOBase, bytes)):
_content = body
else:
_json = body
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_logs_ingestion_upload_request(
rule_id=rule_id,
stream=stream,
stream_name=stream_name,
content_encoding=content_encoding,
content_type=content_type,
api_version=self._config.api_version,
json=_json,
content=_content,
headers=_headers,
params=_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def upload(
content_encoding = "gzip"
logs.seek(0)

super()._upload(rule_id, stream=stream_name, body=logs, content_encoding=content_encoding, **kwargs)
super()._upload(
rule_id,
stream_name=stream_name,
body=cast(IO[bytes], logs),
content_encoding=content_encoding,
**kwargs
)
return

if not isinstance(logs, Sequence) or isinstance(logs, str):
Expand All @@ -76,7 +82,7 @@ def upload(
for gzip_data, log_chunk in _create_gzip_requests(cast(List[JSON], logs)):
try:
super()._upload( # type: ignore
rule_id, stream=stream_name, body=gzip_data, content_encoding="gzip", **kwargs # type: ignore
rule_id, stream_name=stream_name, body=gzip_data, content_encoding="gzip", **kwargs # type: ignore
)
except Exception as err: # pylint: disable=broad-except
if on_error:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
Loading