-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8b22b7
commit 44dc7b7
Showing
7 changed files
with
135 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COMPOSE_PROJECT_NAME=logvac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,5 @@ logvac.json | |
*.cover* | ||
db | ||
vendor/*/ | ||
|
||
*.secret | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM golang:1.10 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
# build tools, for compiling | ||
build-essential \ | ||
# install curl to fetch dev things | ||
curl \ | ||
# we'll need git for fetching golang deps | ||
git \ | ||
# we need aws-cli to publish | ||
awscli | ||
|
||
# install dep (not using it yet, but probably will switch to it) | ||
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
|
||
# setup the app dir/working directory | ||
RUN mkdir -p /go/src/github.com/nanopack/logvac | ||
WORKDIR /go/src/github.com/nanopack/logvac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: build deps #release run test | ||
|
||
# directory to output build | ||
DIST_DIR=./dist | ||
# get the date and time to use as a buildstamp | ||
DATE=$$(TZ=":US/Mountain" date '+%Y-%m-%d') | ||
TIME=$$(TZ=":US/Mountain" date '+%I:%M:%S%p') | ||
LDFLAGS="-s -w -X main.buildDate=$(DATE) -X main.buildTime=$(TIME)" | ||
|
||
build: | ||
@go build --ldflags=$(LDFLAGS) -o $(DIST_DIR)/logvac main.go | ||
|
||
deps: | ||
@go get -t -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.1' | ||
|
||
services: | ||
dev: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
volumes: | ||
- .:/go/src/github.com/nanopack/logvac | ||
env_file: | ||
- '.env' | ||
- '.env.secret' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
package drain | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/logs/sender" | ||
|
||
"github.com/nanopack/logvac/core" | ||
) | ||
|
||
// Datadog drain implements the publisher interface for publishing logs to datadog. | ||
type Datadog struct { | ||
connManager *sender.ConnectionManager | ||
Conn net.Conn | ||
Key string // datadog api key | ||
} | ||
|
||
// NewDatadogClient creates a new mist publisher | ||
func NewDatadogClient(key string) (*Datadog, error) { | ||
_, err := net.ResolveTCPAddr("tcp", "intake.logs.datadoghq.com:10514") | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to resolve datadog address - %s", err.Error()) | ||
} | ||
|
||
cm := sender.NewConnectionManager("intake.logs.datadoghq.com", 10514, true) | ||
conn := cm.NewConnection() | ||
|
||
return &Datadog{Key: key, connManager: cm, Conn: conn}, nil | ||
} | ||
|
||
// Init initializes a connection to mist | ||
func (p Datadog) Init() error { | ||
|
||
// add drain | ||
logvac.AddDrain("datadog", p.Publish) | ||
|
||
return nil | ||
} | ||
|
||
// Publish utilizes mist's Publish to "drain" a log message | ||
func (p *Datadog) Publish(msg logvac.Message) { | ||
msg.PubTries++ | ||
|
||
if p.Conn == nil { | ||
fmt.Println("Redialing datadog") | ||
p.Conn = p.connManager.NewConnection() // doesn't block (don't goroutine call to Publish) | ||
} | ||
|
||
var ms []byte | ||
if len(msg.Raw) > 4 { | ||
ms = append(append([]byte(p.Key+" "), msg.Raw[4:]...), []byte("\n")...) | ||
} else { | ||
ms = append(append([]byte(p.Key+" "), msg.Raw...), []byte("\n")...) | ||
} | ||
|
||
_, err := p.Conn.Write(ms) | ||
if err != nil { | ||
fmt.Printf("Failed writing log - %s %d\n", err.Error(), msg.PubTries) | ||
p.connManager.CloseConnection(p.Conn) | ||
p.Conn = nil | ||
if msg.PubTries <= 3 { | ||
time.Sleep(2 * time.Second) | ||
p.Publish(msg) | ||
} | ||
} | ||
} | ||
|
||
// Close closes the connection to datadog. | ||
func (p *Datadog) Close() error { | ||
p.connManager.CloseConnection(p.Conn) | ||
return nil | ||
} | ||
// import ( | ||
// "fmt" | ||
// "net" | ||
// "time" | ||
// | ||
// "github.com/DataDog/datadog-agent/pkg/logs/sender" | ||
// | ||
// "github.com/nanopack/logvac/core" | ||
// ) | ||
// | ||
// // Datadog drain implements the publisher interface for publishing logs to datadog. | ||
// type Datadog struct { | ||
// connManager *sender.ConnectionManager | ||
// Conn net.Conn | ||
// Key string // datadog api key | ||
// } | ||
// | ||
// // NewDatadogClient creates a new mist publisher | ||
// func NewDatadogClient(key string) (*Datadog, error) { | ||
// _, err := net.ResolveTCPAddr("tcp", "intake.logs.datadoghq.com:10514") | ||
// if err != nil { | ||
// return nil, fmt.Errorf("Failed to resolve datadog address - %s", err.Error()) | ||
// } | ||
// | ||
// cm := sender.NewConnectionManager("intake.logs.datadoghq.com", 10514, true) | ||
// conn := cm.NewConnection() | ||
// | ||
// return &Datadog{Key: key, connManager: cm, Conn: conn}, nil | ||
// } | ||
// | ||
// // Init initializes a connection to mist | ||
// func (p Datadog) Init() error { | ||
// | ||
// // add drain | ||
// logvac.AddDrain("datadog", p.Publish) | ||
// | ||
// return nil | ||
// } | ||
// | ||
// // Publish utilizes mist's Publish to "drain" a log message | ||
// func (p *Datadog) Publish(msg logvac.Message) { | ||
// msg.PubTries++ | ||
// | ||
// if p.Conn == nil { | ||
// fmt.Println("Redialing datadog") | ||
// p.Conn = p.connManager.NewConnection() // doesn't block (don't goroutine call to Publish) | ||
// } | ||
// | ||
// var ms []byte | ||
// if len(msg.Raw) > 4 { | ||
// ms = append(append([]byte(p.Key+" "), msg.Raw[4:]...), []byte("\n")...) | ||
// } else { | ||
// ms = append(append([]byte(p.Key+" "), msg.Raw...), []byte("\n")...) | ||
// } | ||
// | ||
// _, err := p.Conn.Write(ms) | ||
// if err != nil { | ||
// fmt.Printf("Failed writing log - %s %d\n", err.Error(), msg.PubTries) | ||
// p.connManager.CloseConnection(p.Conn) | ||
// p.Conn = nil | ||
// if msg.PubTries <= 3 { | ||
// time.Sleep(2 * time.Second) | ||
// p.Publish(msg) | ||
// } | ||
// } | ||
// } | ||
// | ||
// // Close closes the connection to datadog. | ||
// func (p *Datadog) Close() error { | ||
// p.connManager.CloseConnection(p.Conn) | ||
// return nil | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters