-
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
Changes from 36 commits
d4a94cc
b918ed4
5500bc5
df2e21f
e28d896
6268d7c
2c695cc
d04b740
ad09e27
8b5cdcb
172e62b
8bf599a
f7b8cf3
2d35de5
4c7370e
e280456
47ec83c
ba799d8
b849984
104d7dc
21e5994
935e5fa
7cad222
f141d48
f8f80e8
54fabaf
5d3b900
e6c2a9e
fa54681
f5e1903
904a950
9898d29
b48a3db
0d29fc4
69dfe2e
2dad758
5164b3e
6f4013c
7ffd05f
ec13c3a
ec7ac11
ce60dc4
bbe89ad
8b4c8e8
a22a764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1274,3 +1274,43 @@ | |
--image imageName \\ | ||
--workload-profile-name my-wlp | ||
""" | ||
|
||
# Container Apps Telemetry Commands | ||
|
||
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-metrics 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 data dog settings. | ||
examples: | ||
- name: Delete container apps environment telemetry app insights settings. | ||
text: | | ||
az containerapp env telemetry app-insights delete -n MyContainerappEnvironment -g MyResourceGroup | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,16 @@ def load_command_table(self, _): | |
g.custom_show_command('show', 'show_dapr_component_resiliency') | ||
g.custom_show_command('list', 'list_dapr_component_resiliencies') | ||
|
||
self.command_group('containerapp env telemetry', is_preview=True) | ||
|
||
with self.command_group('containerapp env telemetry data-dog', is_preview=True) as g: | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g.custom_command('set', 'set_environment_telemetry_data_dog', supports_no_wait=True, exception_handler=ex_handler_factory()) | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g.custom_command('delete', 'delete_environment_telemetry_data_dog', supports_no_wait=True, exception_handler=ex_handler_factory()) | ||
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. confirmation |
||
|
||
with self.command_group('containerapp env telemetry app-insights', is_preview=True) as g: | ||
g.custom_command('set', 'set_environment_telemetry_app_insights', supports_no_wait=True, exception_handler=ex_handler_factory()) | ||
g.custom_command('delete', 'delete_environment_telemetry_app_insights', supports_no_wait=True, exception_handler=ex_handler_factory()) | ||
|
||
with self.command_group('containerapp github-action') as g: | ||
g.custom_command('add', 'create_or_update_github_action', exception_handler=ex_handler_factory()) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 containerapp env properties of CA we are updating | ||
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. what does CA mean? |
||
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): | ||
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] | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
else: | ||
if self.get_argument_enable_open_telemetry_traces() and DATA_DOG_DEST not in existing_traces: | ||
existing_traces.append(DATA_DOG_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
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) | ||
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. duplicated code with L63 and L67. could we set it outside if |
||
|
||
def set_up_open_telemetry_metrics_destinations(self): | ||
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] | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations", value=existing_metrics) | ||
else: | ||
if self.get_argument_enable_open_telemetry_traces() and DATA_DOG_DEST not in existing_metrics: | ||
michaelkira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
existing_metrics.append(DATA_DOG_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations", value=existing_metrics) | ||
elif not self.get_argument_enable_open_telemetry_traces() 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 containerapp env properties of CA we are updating | ||
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): | ||
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] | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
else: | ||
if self.get_argument_enable_open_telemetry_traces() and APP_INSIGHTS_DEST not in existing_traces: | ||
existing_traces.append(APP_INSIGHTS_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations", value=existing_traces) | ||
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): | ||
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] | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations", value=existing_logs) | ||
else: | ||
if self.get_argument_enable_open_telemetry_logs() and APP_INSIGHTS_DEST not in existing_logs: | ||
existing_logs.append(APP_INSIGHTS_DEST) | ||
safe_set(self.managed_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations", value=existing_logs) | ||
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) |
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