> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage Workflow Guide | OpenMetadata Ingestion Workflows

> Monitor usage patterns from queries and dashboards with workflow-based usage extraction.

export const connector_0 = "bigquery"

# Usage Workflow

Learn how to configure the Usage workflow from the UI to ingest Query history data from your data sources.

This workflow is available ONLY for the following connectors:

* [BigQuery](/v1.12.x/connectors/database/bigquery)
* [Snowflake](/v1.12.x/connectors/database/snowflake)
* [MSSQL](/v1.12.x/connectors/database/mssql)
* [Redshift](/v1.12.x/connectors/database/redshift)
* [Clickhouse](/v1.12.x/connectors/database/clickhouse)
* [PostgreSQL](/v1.12.x/connectors/database/postgres)
* [Databricks](/v1.12.x/connectors/database/databricks)

If your database service is not yet supported, you can use this same workflow by providing a Query Log file!

Learn how to do so 👇

<CardGroup cols={1}>
  <Card title="Usage Workflow through Query Logs" href="/v1.12.x/connectors/ingestion/workflows/usage/usage-workflow-query-logs">
    Configure the usage workflow by providing a Query Log file.
  </Card>
</CardGroup>

## UI Configuration

Once the metadata ingestion runs correctly and we are able to explore the service Entities, we can add Query Usage information.

This will populate the Queries tab from the Table Entity Page.

<img src="https://mintcdn.com/openmetadata/B2l1cx1p9XLB6-uu/public/images/features/ingestion/workflows/usage/table-entity-page.png?fit=max&auto=format&n=B2l1cx1p9XLB6-uu&q=85&s=f4318e381b197bbfcb10494d14b1f893" alt="table-entity-page" width="4044" height="1944" data-path="public/images/features/ingestion/workflows/usage/table-entity-page.png" />

We can create a workflow that will obtain the query log and table creation information from the underlying database and feed it to OpenMetadata. The Usage Ingestion will be in charge of obtaining this data.

### 1. Add a Usage Ingestion

From the Service Page, go to the Ingestions tab to add a new ingestion and click on Add Usage Ingestion.

<img src="https://mintcdn.com/openmetadata/B2l1cx1p9XLB6-uu/public/images/features/ingestion/workflows/usage/add-ingestion.png?fit=max&auto=format&n=B2l1cx1p9XLB6-uu&q=85&s=1ea240dc7a300b036d5c44430f15456b" alt="add-ingestion" width="4044" height="1944" data-path="public/images/features/ingestion/workflows/usage/add-ingestion.png" />

### 2. Configure the Usage Ingestion

Here you can enter the Usage Ingestion details:

<img src="https://mintcdn.com/openmetadata/B2l1cx1p9XLB6-uu/public/images/features/ingestion/workflows/usage/configure-usage-ingestion.png?fit=max&auto=format&n=B2l1cx1p9XLB6-uu&q=85&s=0a43a30b9698da9bd7a4487d88deac5b" alt="configure-usage-ingestion" width="2600" height="2496" data-path="public/images/features/ingestion/workflows/usage/configure-usage-ingestion.png" />

### Usage Options

**Query Log Duration**

Specify the duration in days for which the usage should capture usage data from the query logs. For example, if you specify 2 as the value for the duration, the data usage will capture usage information for 48 hours prior to when the ingestion workflow is run.

**Stage File Location**

Mention the absolute file path of the temporary file name to store the query logs before processing.

**Result Limit**

Set the limit for the query log results to be run at a time.

### 3. Schedule and Deploy

After clicking Next, you will be redirected to the Scheduling form. This will be the same as the Metadata Ingestion. Select your desired schedule and click on Deploy to find the usage pipeline being added to the Service Ingestions.

<img src="https://mintcdn.com/openmetadata/B2l1cx1p9XLB6-uu/public/images/features/ingestion/workflows/usage/scheule-and-deploy.png?fit=max&auto=format&n=B2l1cx1p9XLB6-uu&q=85&s=fc659d1a3163d44ef6b627341205bd47" alt="schedule-and-deploy" width="4044" height="1944" data-path="public/images/features/ingestion/workflows/usage/scheule-and-deploy.png" />

## YAML Configuration

In the [connectors](/v1.12.x/connectors) section we showcase how to run the metadata ingestion from a JSON/YAML file using the Airflow SDK or the CLI via metadata ingest. Running a usage workflow is also possible using a JSON/YAML configuration file.

This is a good option if you wish to execute your workflow via the Airflow SDK or using the CLI; if you use the CLI a usage workflow can be triggered with the command `metadata usage -c FILENAME.yaml`. The `serviceConnection` config will be specific to your connector (you can find more information in the [connectors](/v1.12.x/connectors) section), though the sourceConfig for the usage will be similar across all connectors.

## Query Usage

The Query Usage workflow will be using the `query-parser` processor.

After running a Metadata Ingestion workflow, we can run Query Usage workflow.
While the `serviceName` will be the same to that was used in Metadata Ingestion, so the ingestion bot can get the `serviceConnection` details from the server.

### 1. Define the YAML Config

This is a sample config for {connector_0} Usage:

<CodePreview>
  <ContentPanel>
    <ContentSection id={1} title="Source Configuration" lines="4">
      Configure the source type and service name for your usage workflow.
    </ContentSection>

    <ContentSection id={2} title="Usage Config Type" lines="6">
      **type**: Set to `DatabaseUsage` for database usage ingestion.
    </ContentSection>

    <ContentSection id={3} title="Query Log Duration" lines="8">
      **queryLogDuration**: Configuration to tune how far we want to look back in query logs to process usage data (in days).
    </ContentSection>

    <ContentSection id={4} title="Stage File Location" lines="10">
      **stageFileLocation**: Temporary file name to store the query logs before processing. Absolute file path required.

      Note that the location is a directory that will be cleaned at the end of the ingestion.
    </ContentSection>

    <ContentSection id={5} title="Result Limit" lines="11">
      **resultLimit**: Configuration to set the limit for query logs.
    </ContentSection>

    <ContentSection id={6} title="Query Log File Path" lines="13">
      **queryLogFilePath**: Configuration to set the file path for query logs. If instead of getting the query logs from the database we want to pass a file with the queries.
    </ContentSection>

    <ContentSection id={7} title="Processor Configuration" lines="14-16">
      Choose the `query-parser` processor to parse and process the query logs.
    </ContentSection>

    <ContentSection id={8} title="Stage Configuration" lines="17-20">
      Configure the staging location for table usage data before it's sent to OpenMetadata.
    </ContentSection>

    <ContentSection id={9} title="Bulk Sink Configuration" lines="21-24">
      Configure the bulk sink for metadata usage ingestion.
    </ContentSection>
  </ContentPanel>

  <CodePanel fileName="{connector}_usage.yaml">
    ```yaml theme={null}
    source:
      type: {connector}-usage
      serviceName: {connector}
      sourceConfig:
        config:
          type: DatabaseUsage
          # Number of days to look back
          queryLogDuration: 7
          # This is a directory that will be DELETED after the usage runs
          stageFileLocation: <path to store the stage file>
          # resultLimit: 1000
          # If instead of getting the query logs from the database we want to pass a file with the queries
          # queryLogFilePath: path-to-file
    processor:
      type: query-parser
      config: {}
    stage:
      type: table-usage
      config:
        filename: /tmp/{connector}_usage
    bulkSink:
      type: metadata-usage
      config:
        filename: /tmp/{connector}_usage
    ```
  </CodePanel>
</CodePreview>

### 2. Run with the CLI

After saving the YAML config, we will run the command the same way we did for the metadata ingestion:

```bash theme={null}
metadata usage -c <path-to-yaml>
```
