Skip to content

Latest commit

 

History

History
176 lines (162 loc) · 6.75 KB

baragon_agent_config.md

File metadata and controls

176 lines (162 loc) · 6.75 KB

Example Baragon Agent Config

{% raw %}

# Configuration for Baragon Agent instances running on each load balancer
#
# Example configuration for use with nginx is shown
#
# The `server` section is the `server` configuration for a dropwizard application.
# `logging` and other dropwizard configurations can also be used
server:
  type: simple
  applicationContextPath: /baragon-agent/v2
  connector:
    type: http
    port: 8882

zookeeper:
  quorum: localhost:2181  # comma separated list of ZK host:port goes here
  zkNamespace: baragon    # name of the base zk node
  sessionTimeoutMillis: 60000
  connectTimeoutMillis: 5000
  retryBaseSleepTimeMilliseconds: 1000
  retryMaxTries: 3

loadBalancerConfig:
  name: loadBalancerGroupName  # load balancer group name
  rootPath: /etc/nginx/conf.d  # base path for writing load balancer configs goes here
  checkConfigCommand: "nginx -t"              # command for checking configs goes here
  reloadConfigCommand: "service nginx reload" # command for reloading configs goes here

# Auth configuration
auth:
  enabled: true

# Host on which this agent is running, will be used to build the baseUrl
hostname: localhost

# (Optional) used to define the base url that Baragon Service will use to contact the Agent
baseUrlTemplate: "http://%s:%d%s"

# (Optional) amount of time to block other requests to this agent while an initial request is being processed
agentLockTimeoutMs: 5000

# (Optional) used in the formatTimestamp handlebars helper
defaultDateFormat: "yyyy-MM-dd hh:mm a"

# (Optional) enable a cors filter for this host, defaults to false
enableCorsFilter: false

# (Optional) set the heartbeat/agent-check-in interval for updating knownAgents metadata, default is 15
heartbeatIntervalSeconds: 15

# (Optional) Testing configuration
testing:
  enabled: false
  applyDelayMs: 0 # delay the processing of apply requests
  applyFailRate: 0 # Cause more failures during the application of a request
  revertDelayMs: 0 # Delay the processing of revert requests
  revertFailRate: 0 # Cause more failures during the processing of a revert request

# Templates used to render load balancer configuration files
templates:
  # File to render, the file will be written to `loadBalancerConfig.rootPath`/`filename` with %s replaced by the serivce ID
  - filename: "proxy/%s.conf"
    # Handlebars template used for this file, this template will be the default for all requests if no template name is specified
    # All variables from the BaragonService object will be available here,
    # this includes any custom `options` fields sent in the BAragonRequest
    #
    # The template below is an example used to proxy requests for a service at a particular path (serviceBasePath) on this
    # load balancer to one of the defined upstreams
    template: |
      # This configuration is automatically generated by Baragon, local changes may be lost!
      #
      # Service ID: {{{service.serviceId}}}
      # Service base path: {{{service.serviceBasePath}}}
      #
      # Service owner(s):
      {{#each service.owners}}
      #   - {{{.}}}
      {{else}}#   (no owners defined)
      {{/each}}#
      {{#if upstreams}}
      {{#if service.options.nginxExtraConfigs}}
      # BEGIN CUSTOM NGINX CONFIGS
      {{#each service.options.nginxExtraConfigs}}{{{.}}}
      {{/each}}
      # END CUSTOM NGINX CONFIGS
      {{/if}}
      location {{{service.options.nginxLocationModifier}}} {{{service.serviceBasePath}}} {
          proxy_pass_header Server;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Scheme $scheme;
          proxy_set_header X-Request-Start "${msec}";
          {{#if service.options.nginxProxyPassOverride}}
          proxy_pass http://{{{service.options.nginxProxyPassOverride}}};
          {{else}}
          proxy_pass http://baragon_{{{service.serviceId}}};
          {{/if}}
          proxy_connect_timeout {{firstOf service.options.nginxProxyConnectTimeout 55}};
          proxy_read_timeout {{firstOf service.options.nginxProxyReadTimeout 60}};
          {{#if service.options.nginxExtraLocationConfigs}}
          # BEGIN CUSTOM NGINX LOCATION CONFIGS
          {{#each service.options.nginxExtraLocationConfigs}}{{{.}}}
          {{/each}}
          # END CUSTOM NGINX LOCATION CONFIGS
          {{/if}}
      }
      {{else}}
      #
      # Service has no defined upstreams -- delete service from Baragon if not needed
      #
      location {{{service.options.nginxLocationModifier}}} {{{service.serviceBasePath}}} {
        return 503;
      }
      {{/if}}

    # Additional templates for this file path can also be  specified and given a name. To render an alternate template for a request
    # include the `templateName` field in your BaragonRequest
    #
    # The example below shows a template named `custom` which will write each line of the config defined in the `proxyConfig`
    # section of the BaragonRequest options to the nginx config file
    #
    # Named templates will be written to the file path under when they are defined
    namedTemplates:
      custom: |
        # This configuration is automatically generated by Baragon, local changes may be lost!
        # Service ID: {{{service.serviceId}}}
        # Service base path: {{{service.serviceBasePath}}}
        # Template: loadbalancer
        # Owners:
        {{#each service.owners}}
        #   - {{{.}}}
        {{else}}
        #   No owners!
        {{/each}}
        # This is a blank template for writing custom configuration
        # BEGIN CUSTOM PROXY CONFIG
        {{#each service.options.proxyConfig}}{{{.}}}
        {{/each}}
        # END CUSTOM PROXY CONFIG

  # Multiple filenames to render for each request can be specified. While the file defined above writes the proxy config,
  # this additional file will define the upstreams
   - filename: "upstreams/%s.conf"
    template: |
      # This configuration is automatically generated by Baragon, local changes may be lost!
      #
      # Service ID: {{{service.serviceId}}}
      # Service base path: {{{service.serviceBasePath}}}
      #
      # Service owner(s):
      {{#each service.owners}}#   - {{{.}}}
      {{else}}#   (no owners defined)
      {{/each}}#
      {{#if upstreams}}
      upstream baragon_{{{service.serviceId}}} {
          {{#each upstreams}}server {{{upstream}}};  # {{{requestId}}}
          {{/each}}
          {{#if service.options.nginxExtraUpstreamConfigs}}
          # BEGIN CUSTOM NGINX UPSTREAM CONFIGS
          {{#each service.options.nginxExtraUpstreamConfigs}}{{{.}}}
          {{/each}}
          # END CUSTOM NGINX UPSTREAM CONFIGS
          {{/if}}
      }
      {{else}}
      #
      # Service is disabled due to no defined upstreams!
      # It's safe to delete this file if not needed.
      #
      {{/if}}

{% endraw %}