Skip to content
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
merged 45 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d4a94cc
update
michaelkira Jan 19, 2024
b918ed4
update
michaelkira Jan 19, 2024
5500bc5
remove include-system-telemetry
michaelkira Jan 22, 2024
df2e21f
update
michaelkira Jan 22, 2024
e28d896
update
michaelkira Jan 22, 2024
6268d7c
update test
michaelkira Jan 22, 2024
2c695cc
update
michaelkira Jan 22, 2024
d04b740
update
michaelkira Jan 24, 2024
ad09e27
update
michaelkira Jan 24, 2024
8b5cdcb
update
michaelkira Jan 24, 2024
172e62b
update
michaelkira Jan 24, 2024
8bf599a
update
michaelkira Jan 24, 2024
f7b8cf3
update
michaelkira Jan 25, 2024
2d35de5
Merge branch 'main' into private/michdai/addotelcommands
michaelkira Jan 25, 2024
4c7370e
update
michaelkira Jan 25, 2024
e280456
update
michaelkira Jan 26, 2024
47ec83c
Merge branch 'main' into private/michdai/addotelcommands
michaelkira Feb 21, 2024
ba799d8
update
michaelkira Feb 21, 2024
b849984
update
michaelkira Feb 21, 2024
104d7dc
resolve comments
michaelkira Feb 22, 2024
21e5994
update
michaelkira Feb 22, 2024
935e5fa
update
michaelkira Feb 22, 2024
7cad222
update
michaelkira Feb 22, 2024
f141d48
update
michaelkira Feb 22, 2024
f8f80e8
update
michaelkira Feb 22, 2024
54fabaf
update
michaelkira Feb 22, 2024
5d3b900
update
michaelkira Feb 23, 2024
e6c2a9e
update
michaelkira Feb 23, 2024
fa54681
update
michaelkira Feb 28, 2024
f5e1903
update
michaelkira Feb 28, 2024
904a950
update
michaelkira Feb 28, 2024
9898d29
update
michaelkira Feb 29, 2024
b48a3db
update
michaelkira Feb 29, 2024
0d29fc4
update
michaelkira Feb 29, 2024
69dfe2e
update
michaelkira Feb 29, 2024
2dad758
udpate
michaelkira Feb 29, 2024
5164b3e
update
michaelkira Feb 29, 2024
6f4013c
update
michaelkira Mar 1, 2024
7ffd05f
update
michaelkira Mar 1, 2024
ec13c3a
update
michaelkira Mar 1, 2024
ec7ac11
update
michaelkira Mar 1, 2024
ce60dc4
Merge branch 'main' into private/michdai/addotelcommands
michaelkira Mar 5, 2024
bbe89ad
update
michaelkira Mar 5, 2024
8b4c8e8
update
michaelkira Mar 5, 2024
a22a764
update
michaelkira Mar 5, 2024
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
4 changes: 4 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ upcoming
* 'az containerapp env dapr-component resiliency': Add support for Dapr Component Resiliency Circuit Breakers
* 'az containerapp create/update/up': Don't compress jar/war/zip file before upload source code
* 'az containerapp create/update/up': Update source to cloud builder to 20240124.1
* 'az containerapp env telemetry data-dog set': support update environment data dog configuration with --site, --key, --enable-open-telemetry-traces and --enable-open-telemetry-metrics
* 'az containerapp env telemetry data-dog delete': support delete environment data dog configuration
* 'az containerapp env telemetry app-insights set': support update environment app insights configuration with --connection-string, --enable-open-telemetry-traces and --enable-open-telemetry-logs
* 'az containerapp env telemetry app-insights delete': support delete environment app insights configuration
Comment on lines +7 to +10
Copy link
Contributor

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


0.3.47
++++++
Expand Down
40 changes: 40 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,3 +1274,43 @@
--image imageName \\
--workload-profile-name my-wlp
"""

# Container Apps Telemetry Commands

helps['containerapp env telemetry data-dog set'] = """
Copy link
Contributor

Choose a reason for hiding this comment

The 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
"""
35 changes: 34 additions & 1 deletion src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"appLogsConfiguration": None,
"customDomainConfiguration": None, # CustomDomainConfiguration,
"workloadProfiles": None,
"InfrastructureResourceGroup": None
"infrastructureResourceGroup": None,
"openTelemetryConfiguration": None
}
}

Expand Down Expand Up @@ -536,6 +537,38 @@
"type": None
}

AppInsightsConfiguration = {
"connectionString": None
}

OpenTelemetryConfiguration = {
"destinationsConfiguration": None,
"tracesConfiguration": None,
"logsConfiguration": None,
"metricsConfiguration": None
}

DestinationsConfiguration = {
"dataDogConfiguration": None
}

DataDogConfiguration = {
"site": None,
"key": None
}

TracesConfiguration = {
"destinations": []
}

LogsConfiguration = {
"destinations": []
}

MetricsConfiguration = {
"destinations": []
}

ManagedServiceIdentity = {
"type": None, # 'None', 'SystemAssigned', 'UserAssigned', 'SystemAssigned,UserAssigned'
"userAssignedIdentities": None # {string: UserAssignedIdentity}
Expand Down
16 changes: 13 additions & 3 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def load_arguments(self, _):
c.argument('logs_dynamic_json_columns', options_list=['--logs-dynamic-json-columns', '-j'], arg_type=get_three_state_flag(),
help='Boolean indicating whether to parse json string log into dynamic json columns. Only work for destination log-analytics.', is_preview=True)

# Telemetry
with self.argument_context('containerapp env telemetry data-dog set') as c:
c.argument('site', options_list=['--site'], help='Specify the data dog site')
c.argument('key', options_list=['--key'], help='Specify the data dog api key')
c.argument('enable_open_telemetry_traces', options_list=['--enable-open-telemetry-traces', '-t'], arg_type=get_three_state_flag(), help='Boolean indicating whether to enable data dog open telemetry traces')
c.argument('enable_open_telemetry_metrics', options_list=['--enable-open-telemetry-metrics', '-m'], arg_type=get_three_state_flag(), help='Boolean indicating whether to enable data dog open telemetry metrics')

with self.argument_context('containerapp env telemetry app-insights set') as c:
c.argument('connection_string', options_list=['--connection-string'], help='Application Insights connection string used by container apps environment')
c.argument('enable_open_telemetry_traces', options_list=['--enable-open-telemetry-traces', '-t'], arg_type=get_three_state_flag(), help='Boolean indicating whether to enable application insights open telemetry traces')
c.argument('enable_open_telemetry_logs', options_list=['--enable-open-telemetry-logs', '-l'], arg_type=get_three_state_flag(), help='Boolean indicating whether to enable application insights open telemetry logs')

# Storage
with self.argument_context('containerapp env storage') as c:
c.argument('storage_type', arg_type = get_enum_type(['AzureFile', 'NfsAzureFile']), help="Type of the storage. Assumed to be AzureFile if not specified.", is_preview=True)
c.argument('access_mode', id_part=None, arg_type=get_enum_type(["ReadWrite", "ReadOnly"]),
Expand Down Expand Up @@ -176,9 +189,6 @@ def load_arguments(self, _):
c.argument('user_assigned', nargs='+', help="Space-separated user identities.")
c.argument('system_assigned', help="Boolean indicating whether to assign system-assigned identity.", action='store_true')

with self.argument_context('containerapp env identity remove', is_preview=True) as c:
c.argument('user_assigned', nargs='*', help="Space-separated user identities. If no user identities are specified, all user identities will be removed.")

with self.argument_context('containerapp up') as c:
c.argument('environment', validator=validate_env_name_or_id_for_up, options_list=['--environment'], help="Name or resource ID of the container app's managed environment or connected environment.")
c.argument('artifact', help="Local path to the application artifact for building the container image. See the supported artifacts here: https://aka.ms/SourceToCloudSupportedArtifacts.", is_preview=True)
Expand Down
10 changes: 10 additions & 0 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The 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())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def set_up_dynamic_json_columns(self):

def set_up_infrastructure_resource_group(self):
if self.get_argument_enable_workload_profiles() and self.get_argument_infrastructure_subnet_resource_id() is not None:
self.managed_env_def["properties"]["InfrastructureResourceGroup"] = self.get_argument_infrastructure_resource_group()
self.managed_env_def["properties"]["infrastructureResourceGroup"] = self.get_argument_infrastructure_resource_group()

def set_up_managed_identity(self):
identity_def = ManagedServiceIdentity
Expand Down
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__)

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

@Juliehzl Juliehzl Mar 1, 2024

Choose a reason for hiding this comment

The 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)
Loading