<@ULVA73B9P> is there a way to mark certain argume...
# ask-marvin
t
@Marvin is there a way to mark certain arguments to flow as a sensitive fields so that it does not logged to the Prefect server flow run (e.g. does not show up on UI(?
m
Prefect 3.x does not provide a direct way to mark flow arguments as sensitive to prevent them from being logged in the Prefect UI or server. However, you can manage logging to some extent by configuring custom logging settings or using Prefect's logger to control what gets logged. To prevent sensitive information from being logged, you could: 1. Custom Logging Configuration: Use a custom logging configuration to control what gets logged. This involves modifying the logging configuration file (e.g.,
logging.yml
) to exclude sensitive data. 2. Custom Log Messages: Use Prefect's
get_run_logger
to emit custom log messages that exclude sensitive information. This allows you to control the content of logs that are emitted during flow execution. Here's a basic example of using `get_run_logger`:
Copy code
python
from prefect import flow
from prefect.logging import get_run_logger

@flow
def my_flow(sensitive_data):
    logger = get_run_logger()
    # Log non-sensitive information
    <http://logger.info|logger.info>("Flow started without logging sensitive data.")
    # Use sensitive_data without logging it

my_flow("my_secret_password")
For more detailed configuration, you might need to dive into Prefect's logging documentation: Prefect Logging.
t
@Marvin in prefect.yaml how do I define the description block to show description like below: """ Date deployed: (Timesatmps from bash command output) Deployment Owner: (username from bash command output) Commit message: (Git commit message) """
m
To define a description block in your
prefect.yaml
file that includes dynamic content like timestamps, usernames, and commit messages from bash command outputs, you can utilize environment variables or templating features. Here's a basic approach to achieve this: 1. Define Environment Variables: Use bash commands to set environment variables before deploying. You can then reference these variables in your
prefect.yaml
. 2. Use Templating: Prefect supports templating within the
prefect.yaml
file, allowing you to insert dynamic values. Here's an example of how you might structure your `prefect.yaml`:
Copy code
yaml
description: |
  Date deployed: {{ $DATE_DEPLOYED }}
  Deployment Owner: {{ $DEPLOYMENT_OWNER }}
  Commit message: {{ $COMMIT_MESSAGE }}
Before running your deployment, set the environment variables using bash commands:
Copy code
bash
export DATE_DEPLOYED=$(date)
export DEPLOYMENT_OWNER=$(whoami)
export COMMIT_MESSAGE=$(git log -1 --pretty=%B)
Then, when you deploy using Prefect, these variables will be interpolated into the description field. Make sure your deployment process correctly sources these environment variables. For more details on templating and environment variables in
prefect.yaml
, you can refer to the Prefect YAML Documentation.
t
@Marvin can you leverage
.run_shell_script
to obtain these values
m
Yes, you can use the
run_shell_script
step in your
prefect.yaml
to execute shell commands and use their output in subsequent steps. This can be particularly useful for gathering dynamic information such as deployment timestamps, usernames, and commit messages. Here's a basic example of how you might structure your
prefect.yaml
to achieve this:
Copy code
yaml
build:
  steps:
    - id: get_deployment_info
      run_shell_script:
        script: |
          echo "Date deployed: $(date)"
          echo "Deployment Owner: $(whoami)"
          echo "Commit message: $(git log -1 --pretty=%B)"
    - id: build_docker_image
      build_docker_image:
        image_name: my-image
        tag: "{{ get_deployment_info.stdout }}"
In this example, the
run_shell_script
step executes a shell script that outputs the desired information. The
id
of the step (
get_deployment_info
) allows you to reference its output in subsequent steps. The
stdout
of the script can be used in other parts of your deployment configuration, such as in building a Docker image or setting metadata. For more detailed information on using shell scripts within Prefect deployments, you can refer to the Prefect YAML Documentation and the Prefect Shell Integration.