Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jvasquezrojas committed Jul 17, 2024
1 parent 2e3a898 commit 6b7ff13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/snowflake/cli/api/commands/execution_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from dataclasses import dataclass
import uuid
from dataclasses import dataclass, field
from enum import Enum


Expand All @@ -23,10 +24,10 @@ class ExecutionStatus(Enum):

@dataclass
class ExecutionMetadata:
execution_id: str
start_time: float = 0
end_time: float = 0
start_time: float = 0.0
end_time: float = 0.0
status: ExecutionStatus = ExecutionStatus.SUCCESS
execution_id: str = field(default_factory=lambda: uuid.uuid4().hex)

def __post_init__(self):
self.start_time = time.monotonic()
Expand All @@ -35,5 +36,5 @@ def complete(self, status: ExecutionStatus):
self.end_time = time.monotonic()
self.status = status

def duration(self):
def get_duration(self):
return self.end_time - self.start_time
3 changes: 1 addition & 2 deletions src/snowflake/cli/api/commands/snow_typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import dataclasses
import logging
import uuid
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, Tuple

Expand Down Expand Up @@ -96,7 +95,7 @@ def custom_command(command_callable):
@wraps(command_callable)
def command_callable_decorator(*args, **kw):
"""Wrapper around command callable. This is what happens at "runtime"."""
execution = ExecutionMetadata(uuid.uuid4().hex)
execution = ExecutionMetadata()
self.pre_execute(execution)
try:
result = command_callable(*args, **kw)
Expand Down
4 changes: 2 additions & 2 deletions src/snowflake/cli/app/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def log_command_result(execution: ExecutionMetadata):
TelemetryField.KEY_TYPE: TelemetryEvent.CMD_EXECUTION_RESULT.value,
CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id,
CLITelemetryField.COMMAND_RESULT_STATUS: execution.status.value,
CLITelemetryField.COMMAND_EXECUTION_TIME: execution.duration(),
CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(),
}
)

Expand All @@ -179,7 +179,7 @@ def log_command_execution_error(exception: Exception, execution: ExecutionMetada
CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id,
CLITelemetryField.ERROR_TYPE: exception_type,
CLITelemetryField.IS_CLI_EXCEPTION: is_cli_exception,
CLITelemetryField.COMMAND_EXECUTION_TIME: execution.duration(),
CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(),
}
)

Expand Down

0 comments on commit 6b7ff13

Please sign in to comment.