Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 1364146

Browse files
committed
Improve the logdriver modules.
1 parent b7a4aab commit 1364146

File tree

14 files changed

+965
-127
lines changed

14 files changed

+965
-127
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13+
14+
humpback-logdriver

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ RUN apk add --no-cache bash
44

55
RUN mkdir -p /plugin/logs
66

7+
RUN mkdir -p /run/docker/logging/meta_confs
8+
9+
RUN mkdir -p /run/docker/logging/blocks
10+
711
ADD ./conf /plugin/conf
812

913
ADD ./humpback-logdriver /plugin/

conf/conf.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package conf
33
import (
44
"io/ioutil"
55
"os"
6+
"strconv"
67
"strings"
78
"time"
89

910
"github.com/humpback/gounits/convert"
1011
"github.com/humpback/gounits/logger"
12+
"github.com/humpback/humpback-logdriver/driver/stay"
1113
yaml "gopkg.in/yaml.v2"
1214
)
1315

@@ -25,14 +27,21 @@ type NodeConfig struct {
2527
//Configuration is exported
2628
type Configuration struct {
2729
Environment string `yaml:"environment" json:"environment"`
30+
HostIP string `yaml:"hostip" json:"hostip"`
2831
Discovery struct {
2932
Hosts map[string]interface{} `yaml:"hosts" json:"hosts"`
3033
RetryInterval time.Duration `yaml:"retryinterval" json:"retryinterval"`
3134
Heartbeat time.Duration `yaml:"heartbeat" json:"heartbeat"`
3235
TTL time.Duration `yaml:"ttl" json:"ttl"`
3336
} `yaml:"discovery" json:"discovery"`
3437
Providers interface{} `yaml:"providers" json:"providers"`
35-
Logs struct {
38+
Blocks struct {
39+
Enable bool `yaml:"enable" json:"enable"`
40+
MaxSize int64 `yaml:"maxsize" json:"maxsize"`
41+
MaxCount int `yaml:"maxcount" json:"maxcount"`
42+
RetryInterval time.Duration `yaml:"retryinterval" json:"retryinterval"`
43+
} `yaml:"blocks" json:"blocks"`
44+
Logs struct {
3645
FileName string `yaml:"filename" json:"filename"`
3746
Level string `yaml:"level" json:"level"`
3847
MaxSize int64 `yaml:"maxsize" json:"maxsize"`
@@ -67,6 +76,38 @@ func New(fname string) error {
6776
c.Logs.Level = pluginLogsLevel
6877
}
6978

79+
pluginBlockEnable := os.Getenv("PLUGIN_BLOCK_ENABLE")
80+
if pluginBlockEnable != "" {
81+
if value, err := strconv.ParseBool(pluginBlockEnable); err == nil {
82+
c.Blocks.Enable = value
83+
}
84+
}
85+
86+
pluginBlockMaxSize := os.Getenv("PLUGIN_BLOCK_MAXSIZE")
87+
if pluginBlockMaxSize != "" {
88+
if value, err := strconv.Atoi(pluginBlockMaxSize); err == nil {
89+
c.Blocks.MaxSize = (int64)(value)
90+
}
91+
}
92+
93+
pluginBlockMaxCount := os.Getenv("PLUGIN_BLOCK_MAXCOUNT")
94+
if pluginBlockMaxCount != "" {
95+
if value, err := strconv.Atoi(pluginBlockMaxCount); err == nil {
96+
c.Blocks.MaxCount = value
97+
}
98+
}
99+
100+
pluginBlockRetryInterval := os.Getenv("PLUGIN_BLOCK_RETRYINTERVAL")
101+
if pluginBlockRetryInterval != "" {
102+
if value, err := time.ParseDuration(pluginBlockRetryInterval); err == nil {
103+
c.Blocks.RetryInterval = value
104+
}
105+
}
106+
107+
pluginHostIP := os.Getenv("PLUGIN_HOST_IP")
108+
if pluginHostIP != "" {
109+
c.HostIP = pluginHostIP
110+
}
70111
configuration = &c
71112
return nil
72113
}
@@ -81,6 +122,14 @@ func Environment() string {
81122
return "dev"
82123
}
83124

125+
func HostIP() string {
126+
127+
if configuration != nil {
128+
return configuration.HostIP
129+
}
130+
return ""
131+
}
132+
84133
func NodeConfigArgs() *NodeConfig {
85134

86135
if configuration != nil {
@@ -100,6 +149,19 @@ func NodeConfigArgs() *NodeConfig {
100149
return nil
101150
}
102151

152+
func StayBlocksConfig() *stay.StayBlocksConfig {
153+
154+
if configuration != nil {
155+
return &stay.StayBlocksConfig{
156+
Enable: configuration.Blocks.Enable,
157+
MaxSize: configuration.Blocks.MaxSize,
158+
MaxCount: configuration.Blocks.MaxCount,
159+
RetryInterval: configuration.Blocks.RetryInterval,
160+
}
161+
}
162+
return nil
163+
}
164+
103165
func Providers() map[string]interface{} {
104166

105167
providers := map[string]interface{}{}

conf/config.yaml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,14 @@ discovery:
88
heartbeat: 60s
99
ttl: 320s
1010
providers:
11-
wh7:
11+
dev:
1212
logstash:
1313
host: 192.168.2.70:5000
14-
prd:
15-
kafka:
16-
host: 192.168.2.80:9092
17-
topic: humpback-logs
18-
partition: 2
19-
dev:
20-
redis:
21-
host: 192.168.2.70:6379
22-
database: 0
23-
list: humpback-logs
14+
blocks:
15+
enable: true
16+
maxsize: 3145728
17+
maxcount: 40
18+
retryinterval: 180s
2419
logs:
2520
filename: ./logs/humpback-logdriver.log
2621
level: error

config.json

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
{
2-
"version": "1.0.0",
3-
"description": "Newegg.Inc Humpback Log Driver",
4-
"documentation": "-",
5-
"entrypoint": ["./humpback-logdriver"],
6-
"workdir": "/plugin",
7-
"network": {
8-
"type": "host"
9-
},
10-
"interface": {
11-
"types": [
2+
"version": "1.0.0",
3+
"description": "humpback log driver plugin",
4+
"documentation": "https://github.com/humpback/humpback-logdriver.git",
5+
"entrypoint": ["./humpback-logdriver"],
6+
"workdir": "/plugin",
7+
"network": {
8+
"type": "host"
9+
},
10+
"interface": {
11+
"types": [
1212
"docker.logdriver/1.0"
13-
],
14-
"socket": "humpbacklogdriver.sock"
13+
],
14+
"socket": "humpbacklogdriver.sock"
15+
},
16+
"propagatedmount": "/run/docker/logging",
17+
"env": [
18+
{
19+
"name": "PLUGIN_ENV",
20+
"description": "set plugin env value.",
21+
"value": "dev",
22+
"settable": ["value"]
23+
},
24+
{
25+
"name": "PLUGIN_LOGS_LEVEL",
26+
"description": "set plugin debug out logs level.",
27+
"value": "error",
28+
"settable": ["value"]
29+
},
30+
{
31+
"name": "PLUGIN_BLOCK_ENABLE",
32+
"description": "set plugin stay block enable.",
33+
"value": "true",
34+
"settable": ["value"]
35+
},
36+
{
37+
"name": "PLUGIN_BLOCK_MAXSIZE",
38+
"description": "set plugin stay block max size.",
39+
"value": "3145728",
40+
"settable": ["value"]
41+
},
42+
{
43+
"name": "PLUGIN_BLOCK_MAXCOUNT",
44+
"description": "set plugin stay blocks max count.",
45+
"value": "40",
46+
"settable": ["value"]
47+
},
48+
{
49+
"name": "PLUGIN_BLOCK_RETRYINTERVAL",
50+
"description": "set plugin stay blocks retry interval.",
51+
"value": "180s",
52+
"settable": ["value"]
1553
},
16-
"env": [
17-
{
18-
"name": "PLUGIN_ENV",
19-
"description": "set plugin env value.",
20-
"value": "dev",
21-
"settable": ["value"]
22-
},
23-
{
24-
"name": "PLUGIN_LOGS_LEVEL",
25-
"description": "set plugin debug out logs level.",
26-
"value": "error",
27-
"settable": ["value"]
28-
}
29-
]
30-
}
31-
54+
{
55+
"name": "PLUGIN_HOST_IP",
56+
"description": "set plugin host ipaddr.",
57+
"value": "",
58+
"settable": ["value"]
59+
}
60+
]
61+
}

0 commit comments

Comments
 (0)