Flow Configuration Template
Flow Configuration
/etc/lunar-proxy/flows/flow.yaml
name: <FlowName> # The name of the flow, e.g., ClientSideLimitingFlow
filter:
  url: <URLPattern> # Define the URL pattern for the filter, e.g., api.example.com/*
  method: ["<HTTPMethod>"] # Optional: List of HTTP methods, e.g., GET, POST
  headers:
    - key: <HeaderKey> # Optional: Header key, e.g., 'X-API-Key'
      value: <HeaderValue> # Optional: header value, e.g., '12345', '67890'
processors:
  RequestMetrics: # Collect custom metrics for API requests
    processor: UserDefinedMetrics
    parameters:
      - key: metric_name
        value: "call_size" # Name of the metric to track
      - key: metric_type
        value: "histogram" # Metric type (e.g., histogram)
      - key: metric_value
        value: "api_call_size" # Metric value based on request size
      - key: custom_metric_labels #Map of custom label name/value pairs used as label for the metric specified     
        value:
          "x-lunar-context": "$[\"headers\"][\"x-lunar-temp-context\"]"
          "x-lunar-special-context": "$[\"headers\"][\"x-lunar-special-context\"]"  
      - key: labels
        value:
          - "http_method" # Label for HTTP method
          - "url" # Label for URL
          - "consumer_tag" # Label for consumer tag
      - key: buckets
        value: # Define the histogram buckets
          - 0
          - 100
          - 250
          - 500
          - 1000
          - 2500
          - 5000
          - 10000
  ResponseMetrics: # Collect custom metrics for API responses
    processor: UserDefinedMetrics
    parameters:
      - key: metric_name
        value: "call_size" # Name of the metric to track
      - key: metric_type
        value: "histogram" # Metric type (e.g., histogram)
      - key: metric_value
        value: "api_call_size" # Metric value based on request size
      - key: custom_metric_labels #Map of custom label name/value pairs used as label for the metric specified     
        value:
          "x-lunar-context": "$[\"headers\"][\"x-lunar-temp-context\"]"
          "x-lunar-special-context": "$[\"headers\"][\"x-lunar-special-context\"]"  
      - key: labels
        value:
          - "http_method" # Label for HTTP method
          - "url" # Label for URL
          - "consumer_tag" # Label for consumer tag
      - key: buckets
        value: # Define the histogram buckets
          - 0
          - 100
          - 250
          - 500
          - 1000
          - 2500
          - 5000
          - 10000
flow:
  request:
    - from:
        stream:
          name: globalStream
          at: start # Start of the request flow
      to:
        processor:
          name: RequestMetrics # Apply custom request metrics
    - from:
        processor:
          name: RequestMetrics # After collecting metrics
      to:
        stream:
          name: globalStream
          at: end # End of the request flow
  response:
    - from:
        stream:
          name: globalStream
          at: start # Start of the response flow
      to:
        processor:
          name: ResponseMetrics # Apply custom response metrics
    - from:
        processor:
          name: ResponseMetrics # After collecting response metrics
      to:
        stream:
          name: globalStream
          at: end # End of the response flow
| Parameter | Description | Type | Example | 
|---|---|---|---|
| name | The name of the flow. | String | CustomMetricsCollector | 
| filter.url | URL pattern for filtering traffic. | String | *(All URLs) | 
| processors.RequestMetrics.metric_name | Name of the custom metric for requests. | String | call_size | 
| processors.RequestMetrics.metric_type | Type of the metric (e.g., counter, gauge, histogram). | String | histogram | 
| processors.RequestMetrics.metric_value | Value for the metric, typically a request property like size. | String | api_call_size | 
| processors.RequestMetrics.labels | Labels for organizing metrics, such as HTTP method, URL, etc. | List | http_method,url,consumer_tag | 
| processors.ResponseMetrics.metric_name | Name of the custom metric for responses. | String | rate_limit_remaining | 
| processors.ResponseMetrics.metric_value | Value for the metric, such as the value of the X-Ratelimit-Remainingheader. | String | "$[\"headers\"][\"X-Ratelimit-Remaining\"]" | 
| processors.ResponseMetrics.metric_type | Type of the response metric (e.g., counter, gauge, histogram). | String | gauge | 
| processors.ResponseMetrics.custom_metric_labels | Map of custom label name/value pairs. If specified - will be used as label for the metric specified above. Value can be taken from headers | Map of strings | $['headers']['lunar-custom-context'] |