-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Containerapp] az containerapp env telemetry: add command for updating telemetry settings #7199
Merged
yanzhudd
merged 45 commits into
Azure:main
from
michaelkira:private/michdai/addotelcommands
Mar 5, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
d4a94cc
update
michaelkira b918ed4
update
michaelkira 5500bc5
remove include-system-telemetry
michaelkira df2e21f
update
michaelkira e28d896
update
michaelkira 6268d7c
update test
michaelkira 2c695cc
update
michaelkira d04b740
update
michaelkira ad09e27
update
michaelkira 8b5cdcb
update
michaelkira 172e62b
update
michaelkira 8bf599a
update
michaelkira f7b8cf3
update
michaelkira 2d35de5
Merge branch 'main' into private/michdai/addotelcommands
michaelkira 4c7370e
update
michaelkira e280456
update
michaelkira 47ec83c
Merge branch 'main' into private/michdai/addotelcommands
michaelkira ba799d8
update
michaelkira b849984
update
michaelkira 104d7dc
resolve comments
michaelkira 21e5994
update
michaelkira 935e5fa
update
michaelkira 7cad222
update
michaelkira f141d48
update
michaelkira f8f80e8
update
michaelkira 54fabaf
update
michaelkira 5d3b900
update
michaelkira e6c2a9e
update
michaelkira fa54681
update
michaelkira f5e1903
update
michaelkira 904a950
update
michaelkira 9898d29
update
michaelkira b48a3db
update
michaelkira 0d29fc4
update
michaelkira 69dfe2e
update
michaelkira 2dad758
udpate
michaelkira 5164b3e
update
michaelkira 6f4013c
update
michaelkira 7ffd05f
update
michaelkira ec13c3a
update
michaelkira ec7ac11
update
michaelkira ce60dc4
Merge branch 'main' into private/michdai/addotelcommands
michaelkira bbe89ad
update
michaelkira 8b4c8e8
update
michaelkira a22a764
update
michaelkira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1322,3 +1322,58 @@ | |
--environment MyEnvironment \\ | ||
--configuration PropertyName1=Value1 PropertyName2=Value2 | ||
""" | ||
|
||
# Container Apps Telemetry Commands | ||
|
||
helps['containerapp env telemetry'] = """ | ||
type: group | ||
short-summary: Commands to manage telemetry settings for the container apps environment. | ||
""" | ||
|
||
helps['containerapp env telemetry data-dog'] = """ | ||
type: group | ||
short-summary: Commands to manage data dog settings for the container apps environment. | ||
""" | ||
|
||
helps['containerapp env telemetry app-insights'] = """ | ||
type: group | ||
short-summary: Commands to manage app insights settings for the container apps environment. | ||
""" | ||
|
||
helps['containerapp env telemetry data-dog set'] = """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add help information for 'containerapp env telemetry' |
||
type: command | ||
short-summary: Create or update container apps environment telemetry data dog settings. | ||
examples: | ||
- name: Create or update container apps environment telemetry data dog settings. | ||
text: | | ||
az containerapp env telemetry data-dog set -n MyContainerappEnvironment -g MyResourceGroup \\ | ||
--site dataDogSite --key dataDogKey --enable-open-telemetry-traces true --enable-open-telemetry-metrics true | ||
""" | ||
|
||
helps['containerapp env telemetry app-insights set'] = """ | ||
type: command | ||
short-summary: Create or update container apps environment telemetry app insights settings. | ||
examples: | ||
- name: Create or update container apps environment telemetry app insights settings. | ||
text: | | ||
az containerapp env telemetry app-insights set -n MyContainerappEnvironment -g MyResourceGroup \\ | ||
--connection-string connectionString --enable-open-telemetry-traces true --enable-open-telemetry-logs true | ||
""" | ||
|
||
helps['containerapp env telemetry data-dog delete'] = """ | ||
type: command | ||
short-summary: Delete container apps environment telemetry data dog settings. | ||
examples: | ||
- name: Delete container apps environment telemetry data dog settings. | ||
text: | | ||
az containerapp env telemetry data-dog delete -n MyContainerappEnvironment -g MyResourceGroup | ||
""" | ||
|
||
helps['containerapp env telemetry app-insights delete'] = """ | ||
type: command | ||
short-summary: Delete container apps environment telemetry app insights settings. | ||
examples: | ||
- name: Delete container apps environment telemetry app insights settings. | ||
text: | | ||
az containerapp env telemetry app-insights delete -n MyContainerappEnvironment -g MyResourceGroup | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/containerapp/azext_containerapp/containerapp_env_telemetry_decorator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
from azure.cli.command_modules.containerapp._utils import safe_set, safe_get | ||
from knack.log import get_logger | ||
from knack.util import CLIError | ||
from ._client_factory import handle_raw_exception | ||
from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
from azure.cli.core.commands import AzCliCommand | ||
from typing import Any, Dict | ||
|
||
DATA_DOG_DEST = 'dataDog' | ||
APP_INSIGHTS_DEST = 'appInsights' | ||
logger = get_logger(__name__) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need one more blank line |
||
|
||
class ContainerappEnvTelemetryDataDogPreviewSetDecorator(BaseResource): | ||
|
||
def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
super().__init__(cmd, client, raw_parameters, models) | ||
self.managed_env_def = {} | ||
self.existing_managed_env_def = {} | ||
|
||
def get_argument_open_telemetry_data_dog_site(self): | ||
return self.get_param("site") | ||
|
||
def get_argument_open_telemetry_data_dog_key(self): | ||
return self.get_param("key") | ||
|
||
def get_argument_enable_open_telemetry_traces(self): | ||
return self.get_param("enable_open_telemetry_traces") | ||
|
||
def get_argument_enable_open_telemetry_metrics(self): | ||
return self.get_param("enable_open_telemetry_metrics") | ||
|
||
def construct_payload(self): | ||
# Get current containerapp env telemetry properties | ||
try: | ||
self.existing_managed_env_def = self.client.show(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name()) | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
self.set_up_open_telemetry_data_dog_site() | ||
self.set_up_open_telemetry_data_dog_key() | ||
self.set_up_open_telemetry_traces_destinations() | ||
self.set_up_open_telemetry_metrics_destinations() | ||
|
||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def set_up_open_telemetry_data_dog_site(self): | ||
if self.get_argument_open_telemetry_data_dog_site() and self.get_argument_open_telemetry_data_dog_site() is not None: | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "dataDogConfiguration", "site", value=self.get_argument_open_telemetry_data_dog_site()) | ||
|
||
def set_up_open_telemetry_data_dog_key(self): | ||
if self.get_argument_open_telemetry_data_dog_key() and self.get_argument_open_telemetry_data_dog_key() is not None: | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "dataDogConfiguration", "key", value=self.get_argument_open_telemetry_data_dog_key()) | ||
|
||
def set_up_open_telemetry_traces_destinations(self): | ||
if self.get_argument_enable_open_telemetry_traces() is not None: | ||
existing_traces = safe_get(self.existing_managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations") | ||
if existing_traces is None: | ||
if self.get_argument_enable_open_telemetry_traces(): | ||
existing_traces = [DATA_DOG_DEST] | ||
else: | ||
if self.get_argument_enable_open_telemetry_traces() and DATA_DOG_DEST not in existing_traces: | ||
existing_traces.append(DATA_DOG_DEST) | ||
elif not self.get_argument_enable_open_telemetry_traces() and DATA_DOG_DEST in existing_traces: | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
existing_traces.remove(DATA_DOG_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
|
||
def set_up_open_telemetry_metrics_destinations(self): | ||
if self.get_argument_enable_open_telemetry_metrics() is not None: | ||
existing_metrics = safe_get(self.existing_managed_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations") | ||
if existing_metrics is None: | ||
if self.get_argument_enable_open_telemetry_metrics(): | ||
existing_metrics = [DATA_DOG_DEST] | ||
else: | ||
if self.get_argument_enable_open_telemetry_metrics() and DATA_DOG_DEST not in existing_metrics: | ||
existing_metrics.append(DATA_DOG_DEST) | ||
elif not self.get_argument_enable_open_telemetry_metrics() and DATA_DOG_DEST in existing_metrics: | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
existing_metrics.remove(DATA_DOG_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations", value=existing_metrics) | ||
|
||
def update(self): | ||
try: | ||
return self.client.update(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), | ||
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def, no_wait=self.get_argument_no_wait()) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
|
||
class ContainerappEnvTelemetryAppInsightsPreviewSetDecorator(BaseResource): | ||
|
||
def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
super().__init__(cmd, client, raw_parameters, models) | ||
self.managed_env_def = {} | ||
self.existing_managed_env_def = {} | ||
|
||
def get_argument_open_telemetry_app_insights_connection_string(self): | ||
return self.get_param("connection_string") | ||
|
||
def get_argument_enable_open_telemetry_traces(self): | ||
return self.get_param("enable_open_telemetry_traces") | ||
|
||
def get_argument_enable_open_telemetry_logs(self): | ||
return self.get_param("enable_open_telemetry_logs") | ||
|
||
def construct_payload(self): | ||
# Get current containerapp env telemetry properties | ||
try: | ||
self.existing_managed_env_def = self.client.show(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name()) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
self.set_up_open_telemetry_open_telemetry_app_insights_connection_string() | ||
self.set_up_open_telemetry_traces_destinations() | ||
self.set_up_open_telemetry_logs_destinations() | ||
|
||
def set_up_open_telemetry_open_telemetry_app_insights_connection_string(self): | ||
if self.get_argument_open_telemetry_app_insights_connection_string() and self.get_argument_open_telemetry_app_insights_connection_string() is not None: | ||
safe_set(self.managed_env_def, "properties", "appInsightsConfiguration", "connectionString", value=self.get_argument_open_telemetry_app_insights_connection_string()) | ||
|
||
def set_up_open_telemetry_traces_destinations(self): | ||
if self.get_argument_enable_open_telemetry_traces() is not None: | ||
existing_traces = safe_get(self.existing_managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations") | ||
if existing_traces is None: | ||
if self.get_argument_enable_open_telemetry_traces(): | ||
existing_traces = [APP_INSIGHTS_DEST] | ||
else: | ||
if self.get_argument_enable_open_telemetry_traces() and APP_INSIGHTS_DEST not in existing_traces: | ||
existing_traces.append(APP_INSIGHTS_DEST) | ||
elif not self.get_argument_enable_open_telemetry_traces() and APP_INSIGHTS_DEST in existing_traces: | ||
existing_traces.remove(APP_INSIGHTS_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
|
||
def set_up_open_telemetry_logs_destinations(self): | ||
if self.get_argument_enable_open_telemetry_logs() is not None: | ||
existing_logs = safe_get(self.existing_managed_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations") | ||
if existing_logs is None: | ||
if self.get_argument_enable_open_telemetry_logs(): | ||
existing_logs = [APP_INSIGHTS_DEST] | ||
else: | ||
if self.get_argument_enable_open_telemetry_logs() and APP_INSIGHTS_DEST not in existing_logs: | ||
existing_logs.append(APP_INSIGHTS_DEST) | ||
elif not self.get_argument_enable_open_telemetry_logs() and APP_INSIGHTS_DEST in existing_logs: | ||
existing_logs.remove(APP_INSIGHTS_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations", value=existing_logs) | ||
|
||
def update(self): | ||
try: | ||
return self.client.update(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), | ||
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def, no_wait=self.get_argument_no_wait()) | ||
except Exception as e: | ||
handle_raw_exception(e) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move to the
history.rst