Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ contains the following fields:
* instance group
* instance ID

The structured data may also contain an optional `environment` field if
provided by the operator.

The whole thing looks something like this:

```
Expand Down Expand Up @@ -224,14 +227,8 @@ will need to [install Go][go-installation].
Note that the `go.mod` and `go.sum` files in this repo are only for the test
code.

Before running tests, you'll need to create a bosh director. First, ensure the
bosh cli is installed and the bosh-deployment repository is downloaded and
located at `~/workspace/bosh-deployment`. You can then run
`./scripts/setup-bosh-lite-for-tests.sh` to create the director. Afterwards
execute `source export-bosh-lite-creds.sh` to target the bosh director.

(Alternatively, if you wish to run the specs against the CI env, you can
`source` the `.envrc` in your env-repo.)
The tests expect that your local environment has the BOSH CLI installed and
configured correctly to point to a BOSH Director.

The tests can then be run from the top of the repo with `./scripts/test`.

Expand Down
4 changes: 3 additions & 1 deletion jobs/syslog_forwarder/spec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ properties:
syslog.director:
description: "BOSH Director name"
default: ""

syslog.environment:
description: "Optional environment identifier"
default: ""
syslog.forward_files:
description: If enabled, use BlackBox to forward logs.
default: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ end

%>
set $.director = "<%= p('syslog.director') %>";
<% if p('syslog.environment') != '' -%>
set $.environment = "<%= p('syslog.environment') %>";
<% end -%>
set $.deployment = "<%= spec.deployment %>";
set $.instance = "<%= spec.name %>";
set $.az = "<%= spec.az %>";
Expand All @@ -37,6 +40,10 @@ template(name="SyslogForwarderTemplate" type="list") {
# 47450 is CFF in https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
constant(value=" [instance@47450 director=\"")
property(name="$.director")
<% if p('syslog.environment') != '' -%>
constant(value="\" environment=\"")
property(name="$.environment")
<% end -%>
constant(value="\" deployment=\"")
property(name="$.deployment")
constant(value="\" group=\"")
Expand Down
18 changes: 3 additions & 15 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@
## Development

The following commands assume you are operating
from the top level of the repo, have go inistalled,
from the top level of the repo, have go installed,
and have initialized and updated the blackbox submodule
as described in the main [README](../README.md).

First, you'll need to setup a bosh-lite and login to it.
If you don't have a bosh-lite running
and aliased as `vbox` already:

```sh
scripts/setup-bosh-lite-for-tests.sh
```

If you don't already have BOSH credential
environment variables in your session:

```sh
source scripts/export-bosh-lite-creds.sh
```
Ensure that you have a BOSH Director deployed and your local environment is
configured to point to the BOSH Director.

To then run the tests locally:

Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ var _ = Describe("Forwarding loglines to a TCP syslog drain", func() {
Expect(string(sdata.ID())).To(Equal("instance@47450"))
properties := sdata.Properties()
Expect(properties).To(ContainElement(logrfc.Property{Key: ("director"), Value: ("")}))
Expect(properties).ToNot(ContainElement(logrfc.Property{Key: ("environment"), Value: ("")}))
Expect(properties).To(ContainElement(logrfc.Property{Key: ("deployment"), Value: (DeploymentName())}))
Expect(properties).To(ContainElement(logrfc.Property{Key: ("group"), Value: ("forwarder")}))
break
Expand Down Expand Up @@ -246,6 +247,45 @@ var _ = Describe("Forwarding loglines to a TCP syslog drain", func() {
})
})

var _ = Describe("Tagging logs with environment identifiers", func() {
AfterEach(func() {
Cleanup()
})

Context("when an environment identifier is specified", func() {
BeforeEach(func() {
Cleanup()
Deploy("manifests/environment-identifier.yml")
})
It("includes the environment identifier in the structured data", func() {
SendLogMessage("test-environment-identifier", DEFAULT_LOGGER_SIZE)
Eventually(func() string {
return ForwardedLogs()
}).Should(ContainSubstring("test-environment-identifier"))

logs := bytes.NewBufferString(ForwardedLogs())
reader := bufio.NewReader(logs)

for {
line, _, err := reader.ReadLine()
Expect(err).ToNot(HaveOccurred())
if len(line) == 0 {
break
}
logLine, _, err := logrfc.Parse(line)
Expect(err).ToNot(HaveOccurred())
if string(logLine.Message()) == "test-environment-identifier" {
sdata := logLine.StructureData()[0]
Expect(string(sdata.ID())).To(Equal("instance@47450"))
properties := sdata.Properties()
Expect(properties).To(ContainElement(logrfc.Property{Key: ("environment"), Value: ("some-environment-identifier")}))
break
}
}
})
})
})

var _ = Describe("Optional features to reduce CF log volume", func() {
AfterEach(func() {
Cleanup()
Expand Down
40 changes: 40 additions & 0 deletions tests/manifests/environment-identifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: ((deployment))
releases:
- name: syslog
version: latest
stemcells:
- alias: default
os: ((stemcell-os))
version: latest
instance_groups:
- name: forwarder
instances: 1
vm_type: default
stemcell: default
networks:
- name: default
azs:
- z1
jobs:
- name: syslog_forwarder
release: syslog
properties:
syslog:
environment: "some-environment-identifier"
- name: storer
instances: 1
vm_type: default
stemcell: default
networks:
- name: default
azs:
- z1
jobs:
- name: syslog_storer
release: syslog
update:
canaries: 1
max_in_flight: 1
canary_watch_time: 1000-60000
update_watch_time: 1000-60000