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 CRUD otlp settings #7356

Merged
merged 38 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
237ecf4
add otlp support
michaelkira Mar 6, 2024
84a5627
update
michaelkira Mar 7, 2024
58a0e7a
update
michaelkira Mar 7, 2024
3f04c2f
update
michaelkira Mar 7, 2024
f5c93d8
update
michaelkira Mar 7, 2024
7a2e6da
update
michaelkira Mar 7, 2024
9ce3232
update
michaelkira Mar 7, 2024
0749f4a
update
michaelkira Mar 7, 2024
35cf0a8
update
michaelkira Mar 7, 2024
3c37add
update
michaelkira Mar 7, 2024
9eda229
update
michaelkira Mar 8, 2024
23ab02f
update
michaelkira Mar 11, 2024
48ba157
update
michaelkira Mar 11, 2024
f2d368c
update
michaelkira Mar 11, 2024
8e944e9
Merge remote-tracking branch 'upstream/main' into private/michdai/add…
michaelkira Mar 11, 2024
6d27dda
update
michaelkira Mar 11, 2024
8d499d1
update
michaelkira Mar 11, 2024
ec2f227
update
michaelkira Mar 12, 2024
82497bf
update
michaelkira Mar 12, 2024
3504dd8
update
michaelkira Mar 12, 2024
65bdf62
update
michaelkira Mar 13, 2024
6408a58
update
michaelkira Mar 13, 2024
f1d730a
update
michaelkira Mar 14, 2024
6f7f27a
update
michaelkira Mar 14, 2024
9d34c07
re generate test files
michaelkira Mar 14, 2024
372b58d
update
michaelkira Mar 14, 2024
f1a19bc
update
michaelkira Mar 15, 2024
8cecd93
update
michaelkira Mar 15, 2024
cbbab57
update
michaelkira Mar 15, 2024
4047e6e
udpate
michaelkira Mar 18, 2024
90a0f9b
update
michaelkira Mar 18, 2024
a00909d
update
michaelkira Mar 19, 2024
655cd9b
update
michaelkira Mar 19, 2024
fd2954a
update
michaelkira Mar 20, 2024
e7cb40b
format
michaelkira Mar 20, 2024
0c23015
update
michaelkira Mar 20, 2024
da8ba0d
update
michaelkira Mar 20, 2024
ddb0c0d
update
michaelkira Mar 20, 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
7 changes: 7 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Release History
===============
upcoming
++++++
* 'az containerapp env telemetry data-dog show': Support show environment data dog configuration
* 'az containerapp env telemetry app-insights show': Support show environment app insights configuration
* 'az containerapp env telemetry otlp add': Support add environment otlp configuration with --otlp-name, --endpoint, --insecure, --headers, --enable-open-telemetry-traces, --enable-open-telemetry-logs and --enable-open-telemetry-metrics
* 'az containerapp env telemetry otlp update': Support update environment otlp configuration with --otlp-name, --endpoint, --insecure, --headers, --enable-open-telemetry-traces, --enable-open-telemetry-logs and --enable-open-telemetry-metrics
* 'az containerapp env telemetry otlp remove': Support remove environment otlp configuration with --otlp-name
* 'az containerapp env telemetry otlp show': Support show environment otlp configuration with --otlp-name
* 'az containerapp env telemetry otlp list': Support show environment otlp configurations

0.3.49
++++++
Expand Down
75 changes: 75 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,15 @@
--site dataDogSite --key dataDogKey --enable-open-telemetry-traces true --enable-open-telemetry-metrics true
"""

helps['containerapp env telemetry data-dog show'] = """
type: command
short-summary: Show container apps environment telemetry data dog settings.
examples:
- name: Show container apps environment telemetry data dog settings.
text: |
az containerapp env telemetry data-dog show -n MyContainerappEnvironment -g MyResourceGroup
"""

helps['containerapp env telemetry app-insights set'] = """
type: command
short-summary: Create or update container apps environment telemetry app insights settings.
Expand All @@ -1375,6 +1384,15 @@
--connection-string connectionString --enable-open-telemetry-traces true --enable-open-telemetry-logs true
"""

helps['containerapp env telemetry app-insights show'] = """
type: command
short-summary: Show container apps environment telemetry app insights settings.
examples:
- name: Show container apps environment telemetry app insights settings.
text: |
az containerapp env telemetry app-insights show -n MyContainerappEnvironment -g MyResourceGroup
"""

helps['containerapp env telemetry data-dog delete'] = """
type: command
short-summary: Delete container apps environment telemetry data dog settings.
Expand All @@ -1392,3 +1410,60 @@
text: |
az containerapp env telemetry app-insights delete -n MyContainerappEnvironment -g MyResourceGroup
"""

helps['containerapp env telemetry otlp'] = """
type: group
short-summary: Commands to manage otlp settings for the container apps environment.
"""

helps['containerapp env telemetry otlp add'] = """
michaelkira marked this conversation as resolved.
Show resolved Hide resolved
type: command
short-summary: Add container apps environment telemetry otlp settings.
examples:
- name: Add container apps environment telemetry otlp settings.
text: |
az containerapp env telemetry otlp add -n MyContainerappEnvironment -g MyResourceGroup \\
--otlp-name otlpName --endpoint otlpEndpoint --insecure false --headers api-key=apiKey \\
--enable-open-telemetry-traces true --enable-open-telemetry-logs true --enable-open-telemetry-metrics true
"""

helps['containerapp env telemetry otlp update'] = """
type: command
short-summary: Update container apps environment telemetry otlp settings.
examples:
- name: Update container apps environment telemetry otlp settings.
text: |
az containerapp env telemetry otlp update -n MyContainerappEnvironment -g MyResourceGroup \\
--otlp-name otlpName --endpoint otlpEndpoint --insecure false --headers api-key=apiKey \\
--enable-open-telemetry-traces true --enable-open-telemetry-logs true --enable-open-telemetry-metrics true
"""

helps['containerapp env telemetry otlp remove'] = """
type: command
short-summary: Remove container apps environment telemetry otlp settings.
examples:
- name: Remove container apps environment telemetry otlp settings.
text: |
az containerapp env telemetry otlp remove -n MyContainerappEnvironment -g MyResourceGroup \\
--otlp-name otlpName
"""

helps['containerapp env telemetry otlp show'] = """
type: command
short-summary: Show container apps environment telemetry otlp settings.
examples:
- name: Show container apps environment telemetry otlp settings.
text: |
az containerapp env telemetry otlp show -n MyContainerappEnvironment -g MyResourceGroup \\
--otlp-name otlpName
"""

helps['containerapp env telemetry otlp list'] = """
type: command
short-summary: List container apps environment telemetry otlp settings.
examples:
- name: List container apps environment telemetry otlp settings.
text: |
az containerapp env telemetry otlp list -n MyContainerappEnvironment -g MyResourceGroup
"""

22 changes: 18 additions & 4 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from .action import AddCustomizedKeys
from ._validators import (validate_env_name_or_id, validate_build_env_vars,
validate_custom_location_name_or_id, validate_env_name_or_id_for_up)
validate_custom_location_name_or_id, validate_env_name_or_id_for_up,
validate_otlp_headers)
from ._constants import MAXIMUM_CONTAINER_APP_NAME_LENGTH, MAXIMUM_APP_RESILIENCY_NAME_LENGTH, MAXIMUM_COMPONENT_RESILIENCY_NAME_LENGTH


Expand Down Expand Up @@ -65,17 +66,30 @@ def load_arguments(self, _):
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') as c:
c.argument('name', id_part=None)
michaelkira marked this conversation as resolved.
Show resolved Hide resolved

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('site', help='Specify the data dog site')
c.argument('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('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')

with self.argument_context('containerapp env telemetry otlp') as c:
c.argument('otlp_name', help='The name of the otlp entry')
c.argument('endpoint', options_list=['--endpoint', '-e'], help='The endpoint of the otlp entry')
c.argument('insecure', arg_type=get_three_state_flag(), help='Boolean indicating whether the otlp is insecure or not')
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 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 open telemetry logs')
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 open telemetry metrics')
c.argument('headers', nargs='+', help="A list of headers for the otlp. Space-separated values in 'key=value' format.",
validator=validate_otlp_headers)

# 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)
Expand Down
108 changes: 107 additions & 1 deletion src/containerapp/azext_containerapp/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from ._utils import safe_get
from azure.cli.command_modules.containerapp._utils import safe_set, safe_get
from .containerapp_env_telemetry_decorator import DATA_DOG_DEST, APP_INSIGHTS_DEST
from knack.log import get_logger

logger = get_logger(__name__)


def transform_sensitive_values(response_json):
Expand Down Expand Up @@ -39,3 +43,105 @@ def transform_usages_output(result):
table_result.append(value)

return table_result


def transform_telemetry_data_dog_values(response_json):
containerapp_env_def = response_json

r = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "dataDogConfiguration")

if r is not None:
if "key" in safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "dataDogConfiguration"):
safe_set(r, "key", value=None)

safe_set(r, "site", value=safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "dataDogConfiguration", "site"))

enable_open_telemetry_traces = False
existing_traces = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations")
if existing_traces and DATA_DOG_DEST in existing_traces:
enable_open_telemetry_traces = True

safe_set(r, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_metrics = False
existing_metrics = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations")
if existing_metrics and DATA_DOG_DEST in existing_metrics:
enable_open_telemetry_metrics = True

safe_set(r, "enableOpenTelemetryMetrics", value=enable_open_telemetry_metrics)

return r


def transform_telemetry_app_insights_values(response_json):
containerapp_env_def = response_json

r = safe_get(containerapp_env_def, "properties", "appInsightsConfiguration")

if r is not None:
if "connectionString" in safe_get(containerapp_env_def, "properties", "appInsightsConfiguration"):
safe_set(r, "connectionString", value=None)

enable_open_telemetry_traces = False
existing_traces = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations")
if existing_traces and APP_INSIGHTS_DEST in existing_traces:
enable_open_telemetry_traces = True

safe_set(r, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_logs = False
existing_logs = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations")
if existing_logs and APP_INSIGHTS_DEST in existing_logs:
enable_open_telemetry_logs = True

safe_set(r, "enableOpenTelemetryLogs", value=enable_open_telemetry_logs)

return r


def transform_telemetry_otlp_values(response_json):
containerapp_env_def = response_json

existing_otlps = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "destinationsConfiguration", "otlpConfigurations")
existing_traces = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "tracesConfiguration", "destinations")
existing_logs = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "logsConfiguration", "destinations")
existing_metrics = safe_get(containerapp_env_def, "properties", "openTelemetryConfiguration", "metricsConfiguration", "destinations")

if existing_otlps is not None:
for otlp in existing_otlps:
if "headers" in otlp:
dict = otlp["headers"]
if dict:
for header in dict:
if "value" in header:
header["value"] = None
enable_open_telemetry_traces = False

otlp_name = safe_get(otlp, "name")

enable_open_telemetry_traces = False
if existing_traces and otlp_name in existing_traces:
enable_open_telemetry_traces = True

safe_set(otlp, "enableOpenTelemetryTraces", value=enable_open_telemetry_traces)

enable_open_telemetry_logs = False
if existing_logs and otlp_name in existing_logs:
enable_open_telemetry_logs = True

safe_set(otlp, "enableOpenTelemetryLogs", value=enable_open_telemetry_logs)

enable_open_telemetry_metrics = False
if existing_metrics and otlp_name in existing_metrics:
enable_open_telemetry_metrics = True

safe_set(otlp, "enableOpenTelemetryMetrics", value=enable_open_telemetry_metrics)

return existing_otlps


def transform_telemetry_otlp_values_by_name(response_json):
existing_otlps = transform_telemetry_otlp_values(response_json)

return existing_otlps[0]
michaelkira marked this conversation as resolved.
Show resolved Hide resolved

19 changes: 19 additions & 0 deletions src/containerapp/azext_containerapp/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,22 @@ def validate_build_env_vars(cmd, namespace):
"Duplicate build environment variable {env} found, environment variable names must be unique.".format(
env=key_val[0]))
env_pairs[key_val[0]] = key_val[1]

michaelkira marked this conversation as resolved.
Show resolved Hide resolved
def validate_otlp_headers(cmd, namespace):
michaelkira marked this conversation as resolved.
Show resolved Hide resolved
headers = namespace.headers

if not headers:
return

header_pairs = {}

for pair in headers:
key_val = pair.split('=', 1)
if len(key_val) != 2:
raise ValidationError("Otlp headers must be in the format \"<key>=<value>\".")
if key_val[0] in header_pairs:
raise ValidationError(
"Duplicate headers {header} found, header names must be unique.".format(
header=key_val[0]))
header_pairs[key_val[0]] = key_val[1]

23 changes: 18 additions & 5 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from azure.cli.command_modules.containerapp._transformers import (transform_containerapp_output, transform_containerapp_list_output)
from azext_containerapp._client_factory import ex_handler_factory
from ._transformers import (transform_usages_output,
transform_sensitive_values)
transform_sensitive_values,
transform_telemetry_data_dog_values,
transform_telemetry_app_insights_values,
transform_telemetry_otlp_values,
transform_telemetry_otlp_values_by_name)


def load_command_table(self, _):
Expand Down Expand Up @@ -110,12 +114,21 @@ def load_command_table(self, _):
self.command_group('containerapp env telemetry', is_preview=True)

with self.command_group('containerapp env telemetry data-dog', is_preview=True) as g:
g.custom_command('set', 'set_environment_telemetry_data_dog', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_environment_telemetry_data_dog', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('set', 'set_environment_telemetry_data_dog', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_data_dog_values)
g.custom_command('delete', 'delete_environment_telemetry_data_dog', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_data_dog_values)
g.custom_show_command('show', 'show_environment_telemetry_data_dog', transform=transform_telemetry_data_dog_values)

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, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('set', 'set_environment_telemetry_app_insights', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_app_insights_values)
g.custom_command('delete', 'delete_environment_telemetry_app_insights', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_app_insights_values)
g.custom_show_command('show', 'show_environment_telemetry_app_insights', transform=transform_telemetry_app_insights_values)

with self.command_group('containerapp env telemetry otlp', is_preview=True) as g:
g.custom_command('add', 'add_environment_telemetry_otlp', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_otlp_values)
g.custom_command('update', 'update_environment_telemetry_otlp', supports_no_wait=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_otlp_values)
g.custom_command('remove', 'remove_environment_telemetry_otlp', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory(), transform=transform_telemetry_otlp_values)
g.custom_show_command('show', 'show_environment_telemetry_otlp', transform=transform_telemetry_otlp_values_by_name)
g.custom_show_command('list', 'list_environment_telemetry_otlp', transform=transform_telemetry_otlp_values)

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