github.com/observiq/carbon@v0.9.11-0.20200820160507-1b872e368a5e/docs/operators/metadata.md (about)

     1  ## `metadata` operator
     2  
     3  The `metadata` operator adds labels to incoming entries.
     4  
     5  ### Configuration Fields
     6  
     7  | Field      | Default          | Description                                                                                     |
     8  | ---        | ---              | ---                                                                                             |
     9  | `id`       | `metadata`       | A unique identifier for the operator                                                            |
    10  | `output`   | Next in pipeline | The connected operator(s) that will receive all outbound entries                                |
    11  | `labels`   | {}               | A map of `key: value` labels to add to the entry's labels                                       |
    12  | `resource` | {}               | A map of `key: value` labels to add to the entry's resource                                     |
    13  | `on_error` | `send`           | The behavior of the operator if it encounters an error. See [on_error](/docs/types/on_error.md) |
    14  
    15  Inside the label values, an [expression](/docs/types/expression.md) surrounded by `EXPR()`
    16  will be replaced with the evaluated form of the expression. The entry's record can be accessed
    17  with the `$` variable in the expression so labels can be added dynamically from fields.
    18  
    19  ### Example Configurations
    20  
    21  
    22  #### Add static labels and resource
    23  
    24  Configuration:
    25  ```yaml
    26  - type: metadata
    27    labels:
    28      environment: "production"
    29    resource:
    30      cluster: "blue"
    31  ```
    32  
    33  <table>
    34  <tr><td> Input entry </td> <td> Output entry </td></tr>
    35  <tr>
    36  <td>
    37  
    38  ```json
    39  {
    40    "timestamp": "2020-06-15T11:15:50.475364-04:00",
    41    "labels": {},
    42    "record": {
    43      "message": "test"
    44    }
    45  }
    46  ```
    47  
    48  </td>
    49  <td>
    50  
    51  ```json
    52  {
    53    "timestamp": "2020-06-15T11:15:50.475364-04:00",
    54    "labels": {
    55      "environment": "production"
    56    },
    57    "resource": {
    58      "cluster": "blue"
    59    },
    60    "record": {
    61      "message": "test"
    62    }
    63  }
    64  ```
    65  
    66  </td>
    67  </tr>
    68  </table>
    69  
    70  #### Add dynamic tags and labels
    71  
    72  Configuration:
    73  ```yaml
    74  - type: metadata
    75    output: metadata_receiver
    76    labels:
    77      environment: 'EXPR( $.environment == "production" ? "prod" : "dev" )'
    78  ```
    79  
    80  <table>
    81  <tr><td> Input entry </td> <td> Output entry </td></tr>
    82  <tr>
    83  <td>
    84  
    85  ```json
    86  {
    87    "timestamp": "2020-06-15T11:15:50.475364-04:00",
    88    "labels": {},
    89    "record": {
    90      "production_location": "us_east",
    91      "environment": "nonproduction"
    92    }
    93  }
    94  ```
    95  
    96  </td>
    97  <td>
    98  
    99  ```json
   100  {
   101    "timestamp": "2020-06-15T11:15:50.475364-04:00",
   102    "labels": {
   103      "environment": "dev"
   104    },
   105    "record": {
   106      "production_location": "us_east",
   107      "environment": "nonproduction"
   108    }
   109  }
   110  ```
   111  
   112  </td>
   113  </tr>
   114  </table>