Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #170 from phylake/haproxy
Browse files Browse the repository at this point in the history
haproxy configurable log and compression
  • Loading branch information
phylake authored Mar 22, 2017
2 parents 962548d + 203289f commit ea13032
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
`porter` is [semantically versioned](http://semver.org/spec/v2.0.0.html)

### v4.5.0

- added opt-in HAProxy compression
- added configurable list of MIME types to compress
- HAProxy logs can be turned off

### v4.4.0

- disabled userland proxy
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ See the [CHANGELOG](CHANGELOG.md) for a complete list of changes.

`porter` is [semantically versioned](http://semver.org/spec/v2.0.0.html)

v4.5
====

Exposed HAProxy configuration to adjust logging and compression.

v4.4
====

Expand Down
6 changes: 6 additions & 0 deletions commands/host/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type (
StatsPassword string
StatsUri string
IpBlacklistPath string
Log bool
Compression bool
CompressTypes string
ReqHeaderCaptures []conf.HeaderCapture
ResHeaderCaptures []conf.HeaderCapture
}
Expand Down Expand Up @@ -176,6 +179,9 @@ func hotswap(log log15.Logger, environmentStr, regionStr string, hapStdin HAPStd
StatsPassword: config.HAProxyStatsPassword,
StatsUri: constants.HAProxyStatsUri,
IpBlacklistPath: ipBlacklistPath,
Log: (environment.HAProxy.Log == nil || *environment.HAProxy.Log == true),
Compression: environment.HAProxy.Compression,
CompressTypes: strings.Join(environment.HAProxy.CompressTypes, " "),
ReqHeaderCaptures: environment.HAProxy.ReqHeaderCaptures,
ResHeaderCaptures: environment.HAProxy.ResHeaderCaptures,
}
Expand Down
7 changes: 7 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ type (
// Capture headers for logging
ReqHeaderCaptures []HeaderCapture `yaml:"request_header_captures"`
ResHeaderCaptures []HeaderCapture `yaml:"response_header_captures"`
Log *bool `yaml:"log"`
Compression bool `yaml:"compression"`
CompressTypes []string `yaml:"compress_types"`
}

HeaderCapture struct {
Expand Down Expand Up @@ -220,6 +223,10 @@ func (recv *Config) SetDefaults() {
env.InstanceType = "m3.medium"
}

if len(env.HAProxy.CompressTypes) > 0 {
env.HAProxy.Compression = true
}

for _, region := range env.Regions {

if len(region.AutoScalingGroup.SecurityGroupEgress) == 0 {
Expand Down
47 changes: 45 additions & 2 deletions docs/detailed_design/config-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ For each field the following notation is used
- [instance_type](#instance_type) (==1?)
- [blackout_windows](#blackout_windows) (>=1?)
- [hot_swap](#hot_swap) (==1?)
- [haproxy](#haproxy) (==1?)
- [haproxy](==1?)
- [request_header_captures](#header-captures) (>=1?)
- [response_header_captures](#header-captures) (>=1?)
- [log](#log) (==1?)
- [compression](#compression) (==1?)
- [compress_types](#compress_types) (==1?)
- [regions](#regions) (>=1!)
- [name](#region-name) (==1!)
- [stack_definition_path](#stack_definition_path) (==1?)
Expand Down Expand Up @@ -252,7 +257,7 @@ environments:
hot_swap: true
```
### haproxy
### header-captures
Header captures can be defined. See the [HAProxy docs](https://cbonte.github.io/haproxy-dconv/1.5/configuration.html#8.8)
for more about how to parse these logs.
Expand All @@ -272,6 +277,44 @@ environments:
length: 40
```
### log
Turn off HAProxy logs which saves CPU cycles
```yaml
environments:
- name: dev
haproxy:
log: false
```
### compression
Turn on gzip compression.
If no [`compress_types`](#compress_types) are defined all responses are
compressed.

```yaml
environments:
- name: dev
haproxy:
compression: true
```

### compress_types

List of MIME types to compress.

Any value here implies [`compression: true`](#compression)

```yaml
environments:
- name: dev
haproxy:
compress_types: text/plain text/html application/json
```

### regions

region is a complex object defining region-specific things
Expand Down
11 changes: 11 additions & 0 deletions files/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ global
defaults
log global
mode http
{{- if .Log }}
option httplog
option dontlognull
{{- else }}
no log
{{- end }}
retries 3
option redispatch

Expand All @@ -34,6 +38,13 @@ defaults
timeout client 3600s
timeout server 3600s

{{ if .Compression }}
compression algo gzip
{{- end }}
{{- if .CompressTypes }}
compression type {{ .CompressTypes }}
{{- end }}

frontend {{ .ServiceName }}-frontend

{{- range $port := .FrontEndPorts }}
Expand Down

0 comments on commit ea13032

Please sign in to comment.