Skip to content

Commit bd1c0bb

Browse files
authored
Merge pull request #2 from jancajthaml/feature/circle-ci
Quality Assurance (codacy), Continuous Improvements (circle) Coordinates (DockerHUB) integration
2 parents 97ec01d + 468a8c6 commit bd1c0bb

File tree

260 files changed

+135
-148758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+135
-148758
lines changed

.circleci/config.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: 2
2+
3+
jobs:
4+
test:
5+
docker:
6+
- image: circleci/golang:1.9
7+
8+
working_directory: /go/src/jancajthaml
9+
steps:
10+
- checkout
11+
12+
- run:
13+
name: Sync dependencies
14+
command: |
15+
go get -u github.com/kardianos/govendor
16+
govendor sync -v
17+
18+
- run:
19+
name: Run tests
20+
command: |
21+
cd /go/src/jancajthaml/src/datadog-mock
22+
go test -v ./...
23+
24+
- run:
25+
name: Build server
26+
command: |
27+
cd /go/src/jancajthaml/src/datadog-mock
28+
go clean
29+
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go/src/github.com/jancajthaml/target/datadog_mock
30+
31+
- persist_to_workspace:
32+
root: /go/src/github.com/jancajthaml
33+
paths:
34+
- target/datadog_mock
35+
36+
deploy:
37+
docker:
38+
- image: docker:17.05.0-ce-git
39+
40+
working_directory: /app
41+
steps:
42+
- attach_workspace:
43+
at: /go/src/github.com/jancajthaml
44+
45+
- checkout
46+
47+
- setup_remote_docker
48+
49+
- run:
50+
name: Build application Docker image
51+
command: |
52+
cp -r /go/src/github.com/jancajthaml/target /app/target
53+
docker build -t bundle .
54+
55+
- run:
56+
name: List images
57+
command: |
58+
docker images
59+
60+
- deploy:
61+
name: Push image to DockerHUB
62+
command: |
63+
docker login -e ${DOCKER_EMAIL} -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
64+
docker tag bundle "jancajthaml/datadog_mock:${CIRCLE_SHA1}"
65+
docker push "jancajthaml/datadog_mock:${CIRCLE_SHA1}"
66+
67+
workflows:
68+
version: 2
69+
test_and_deploy:
70+
jobs:
71+
- test
72+
- deploy:
73+
requires:
74+
- test

AUTHORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
AUTHORS
1+
Jan Cajthaml <[email protected]>

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ all: install test authors run
66
.PHONY: install
77
install: prepare-dev lint bundle
88

9+
.PHONY: perf
10+
perf:
11+
@./dev/siege.sh
12+
913
.PHONY: fmt
1014
fmt:
1115
docker-compose run --rm fmt

README.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
1-
# DataDog Server mock
1+
# datadog-mock #
22

3-
golang server listening on port 8125 writing metrics to stdout. (datadog/mock 3.02MB)
3+
datadog-mock is a golang statsd mock server listening on port 8125 and relaying events to stdout.
44

5-
### Bootstrap
5+
[![Build Status](https://circleci.com/gh/jancajthaml/datadog-mock.svg?style=svg)](https://circleci.com/gh/jancajthaml/datadog-mock) [![Static Analysis](https://api.codacy.com/project/badge/Grade/c5c255a292f84cf88972f92f74f9174d)](https://www.codacy.com/app/jan-cajthaml/datadog-mock?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jancajthaml/datadog-mock&amp;utm_campaign=Badge_Grade) [![Test Coverage](https://coveralls.io/repos/github/jancajthaml/datadog-mock/badge.svg?branch=master)](https://coveralls.io/github/jancajthaml/datadog-mock?branch=master)
66

7-
Require docker to assembly
7+
## Getting started ##
88

9-
`make install test`
9+
Bootstrap environment with `make install test` then grab `./target/datadog_mock`
10+
or docker image `datadog/mock`.
1011

11-
### Running
12+
## Usage ##
1213

13-
automagically
14+
Run in docker with `make run` or `./target/datadog_mock` locally.
1415

15-
`make run`
16+
## Testing ##
1617

17-
run in docker
18+
When datadog/mock is running you can either test simple relay
19+
`./dev/event-producer.sh` or siege with `make perf`.
1820

19-
`docker run -it --log-driver none --rm -p 0.0.0.0:8125:8125/UDP datadog/mock`
20-
21-
run on host
22-
23-
`./target/datadog_mock`
24-
25-
26-
### Verify
27-
28-
When datadog/mock is running run manually
29-
30-
`echo "deploys.test.myservice:1|c" > /dev/udp/127.0.0.1/8125`
31-
32-
or send MESSAGE repeat EACH second
33-
34-
`MESSAGE="deploys.test.myservice:1|c" EACH=.001 ./dev/event-producer.sh`
21+
## License ##
3522

23+
This service is distributed under the Apache License, Version 2.0 license found
24+
in the [LICENSE](./LICENSE) file.

dev/event-producer.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/bin/bash
22

33
set -eo pipefail
4-
54
trap exit INT TERM
65

76
####
87

9-
[ -z $EACH ] && EACH=2 || :
10-
[ -z $MESSAGE ] && MESSAGE="deploys.test.myservice:1|c" || :
8+
if [ -z $EACH ]; then EACH=2; fi
9+
if [ -z $MESSAGE ]; then MESSAGE="deploys.test.myservice:1|c"; fi
1110

1211
printf "[info] sending \"%s\" every %ssec\n" $MESSAGE $EACH
1312

dev/siege.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
exec 3>&1 4>&2
6+
7+
post_stop() {
8+
exit_code=$?
9+
printf "\n"
10+
if [ -n "$error" ]; then
11+
printf "Error: %s\n" $error
12+
fi
13+
exec 3>&- 4>&-
14+
exit $exit_code
15+
}
16+
17+
trap post_stop INT TERM
18+
trap "kill 0" EXIT
19+
20+
MESSAGE="deploys.test.myservice:1|c" EACH=.0001 ./dev/event-producer.sh &> /dev/null &
21+
MESSAGE="deploys.test.myservice:2|c" EACH=.0001 ./dev/event-producer.sh &> /dev/null &
22+
MESSAGE="deploys.test.myservice:3|c" EACH=.0001 ./dev/event-producer.sh &> /dev/null &
23+
24+
docker rm -f $(docker ps -aq --filter="name=datadog" --filter="status=running") &> /dev/null || :
25+
26+
printf "processing [0 / sec]"
27+
28+
error=$( { (docker-compose run --rm --no-deps --service-ports artefact 2>&4 || :) | perl -e 'open(TTY, ">:unix", "/dev/tty");while (<>) {$l++;if (time > $e) {$e=time;print TTY "\rprocessing [$l / sec]";$l=0}}' 1>&3; } 2>&1 )

src/datadog-mock/processor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ func init() {
3131

3232
var pattern = regexp.MustCompile(`(?P<name>.*?):(?P<value>.*?)\|(?P<type>[a-z])(?:\|#(?P<tags>.*))?`)
3333

34-
func processEvent(event string) {
35-
match := pattern.FindStringSubmatch(event)
34+
func processEvent(event []byte) {
35+
parsed := string(event)
36+
match := pattern.FindStringSubmatch(parsed)
3637

3738
if len(match) < 3 {
3839
return
3940
}
4041

41-
nanolog.Log(h, strings.TrimSuffix(event, "\n")+"\r\n")
42+
nanolog.Log(h, strings.TrimSuffix(parsed, "\n")+"\r\n")
4243
nanolog.Flush()
4344
}

src/datadog-mock/sink.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import (
2020
"os"
2121
)
2222

23+
// NewSink creates new UDP sink with channel for complete events
2324
func NewSink() *sink {
24-
return &sink{event: make(chan string)}
25+
return &sink{event: make(chan []byte)}
2526
}
2627

28+
// Run starts UDP sink with UPD stream source
2729
func (r *sink) Run(addr *net.UDPAddr) {
2830
inputStreamConn, err := net.ListenUDP("udp", addr)
2931

@@ -34,7 +36,7 @@ func (r *sink) Run(addr *net.UDPAddr) {
3436

3537
defer inputStreamConn.Close()
3638

37-
buf := make([]byte, BUF_SIZE)
39+
buf := make([]byte, BufferSize)
3840

3941
forever:
4042
n, _, err := inputStreamConn.ReadFromUDP(buf)
@@ -43,7 +45,7 @@ forever:
4345
goto forever
4446
}
4547

46-
r.event <- string(buf[0:n])
48+
r.event <- buf[0:n]
4749

4850
goto forever
4951
}

src/datadog-mock/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
package main
1616

1717
type sink struct {
18-
event chan string
18+
event chan []byte
1919
}
2020

21-
const BUF_SIZE int = 1024
21+
// BufferSize is upper boundary of UDP recieve window
22+
const BufferSize int = 1024

0 commit comments

Comments
 (0)