-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from KyberNetwork/develop
tomaster
- Loading branch information
Showing
15 changed files
with
583 additions
and
33 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,33 @@ | ||
language: go | ||
|
||
go: | ||
- "1.14.x" | ||
|
||
services: | ||
- docker | ||
|
||
env: | ||
global: | ||
- GO111MODULE=on | ||
- GOLANGCI_LINT_VERSION=1.23.0 | ||
- GO111MODULE=on | ||
|
||
install: | ||
# - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ${TRAVIS_HOME}/bin v${GOLANGCI_LINT_VERSION} | ||
- echo "skip install" | ||
|
||
script: | ||
# - golangci-lint run --config .golangci.yml | ||
- go test -v ./... | ||
|
||
after_success: | ||
- cd cmd/cclog-server && go build -ldflags '-linkmode external -w -extldflags "-static"' && cd ../.. | ||
- docker --version | ||
- docker build -f Dockerfile --label "commit=$TRAVIS_COMMIT" -t kybernetwork/cclog:$TRAVIS_COMMIT . | ||
|
||
deploy: | ||
- provider: script | ||
script: bash .travis/docker_push.sh | ||
on: | ||
all_branches: true | ||
condition: $TRAVIS_BRANCH =~ ^develop|staging|master$ |
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 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
readonly DOCKER_PASSWORD=${DOCKER_PASSWORD:-} | ||
|
||
if [[ -z "$DOCKER_PASSWORD" ]]; then | ||
echo 'DOCKER_PASSWORD is not available, aborting.' | ||
exit 1 | ||
fi | ||
|
||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | ||
|
||
docker tag kybernetwork/cclog:"$TRAVIS_COMMIT" kybernetwork/cclog:"$TRAVIS_BRANCH" | ||
if [[ -n "$TRAVIS_TAG" ]]; then | ||
docker tag kybernetwork/cclog:"$TRAVIS_COMMIT" kybernetwork/cclog:"$TRAVIS_TAG" | ||
fi | ||
|
||
docker push kybernetwork/cclog |
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,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/urfave/cli" | ||
|
||
"github.com/KyberNetwork/cclog/lib/client" | ||
) | ||
|
||
const ( | ||
flagRemoteAddr = "remote-addr" | ||
flagName = "name" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "cli to send log to server" | ||
app.Usage = "cli to send log to server" | ||
app.Action = run | ||
|
||
app.Flags = append(app.Flags, | ||
cli.StringFlag{ | ||
Name: flagRemoteAddr, | ||
Usage: "remote address", | ||
Value: "127.0.0.1:4560", | ||
EnvVar: "REMOTE_ADDR", | ||
}, | ||
cli.StringFlag{ | ||
Name: flagName, | ||
Usage: "name of log file", | ||
Value: "test", | ||
EnvVar: "LOG_NAME", | ||
}, | ||
) | ||
if err := app.Run(os.Args); err != nil { | ||
fmt.Println("run error", err) | ||
} | ||
} | ||
|
||
func run(c *cli.Context) error { | ||
stat, _ := os.Stdin.Stat() | ||
if (stat.Mode() & os.ModeCharDevice) != 0 { | ||
fmt.Println("nothing to send") | ||
return nil | ||
} | ||
w2 := client.NewSyncLogClient(c.String(flagName), c.String(flagRemoteAddr)) | ||
n, err := io.Copy(w2, os.Stdin) | ||
if err != nil { | ||
fmt.Println("write failed", err) | ||
return nil | ||
} | ||
fmt.Println("done with", n, "bytes") | ||
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
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
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
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
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,76 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"sync" | ||
"time" | ||
|
||
"github.com/KyberNetwork/cclog/lib/common" | ||
) | ||
|
||
type SyncLogClient struct { | ||
remoteAddr string | ||
streamClient net.Conn | ||
name string | ||
lock sync.Mutex | ||
lastConnect time.Time | ||
} | ||
|
||
func NewSyncLogClient(name string, remoteAddr string) *SyncLogClient { | ||
return NewSyncLogClientWithBuffer(name, remoteAddr) | ||
} | ||
func NewSyncLogClientWithBuffer(name string, remoteAddr string) *SyncLogClient { | ||
c := &SyncLogClient{ | ||
name: name, | ||
remoteAddr: remoteAddr, | ||
lastConnect: time.Now().Add(-time.Minute), | ||
} | ||
return c | ||
} | ||
|
||
func (l *SyncLogClient) Write(p []byte) (n int, err error) { | ||
l.lock.Lock() | ||
defer l.lock.Unlock() | ||
if l.streamClient == nil { | ||
secs := time.Since(l.lastConnect).Seconds() | ||
if secs < backOffSeconds { | ||
// skip due recent reconnect failed, we drop data as we can't hold | ||
return | ||
} | ||
l.lastConnect = time.Now() | ||
l.streamClient, err = net.Dial("tcp", l.remoteAddr) | ||
if err != nil { | ||
return 0, err | ||
} | ||
err = common.WriteConnectRequest(l.streamClient, common.ConnectRequest{Name: l.name}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
var resp common.ConnectResponse | ||
resp, err = common.ReadConnectResponse(l.streamClient) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if !resp.Success { | ||
fmt.Println("server error", resp.Status) | ||
_ = l.streamClient.Close() | ||
l.streamClient = nil | ||
return | ||
} | ||
} | ||
n, err = l.streamClient.Write(p) | ||
if err != nil { | ||
fmt.Printf("write failed, %+v", err) | ||
_ = l.streamClient.Close() | ||
l.streamClient = nil | ||
} | ||
return | ||
} | ||
|
||
func (l *SyncLogClient) Close() error { | ||
if l.streamClient != nil { | ||
return l.streamClient.Close() | ||
} | ||
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
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,4 +1,4 @@ | ||
package cclog | ||
package server | ||
|
||
import ( | ||
"testing" | ||
|
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
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,4 +1,4 @@ | ||
package cclog | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package cclog | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
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,4 +1,4 @@ | ||
package cclog | ||
package server | ||
|
||
import ( | ||
"path/filepath" | ||
|