Skip to content

Commit 986d0fb

Browse files
authored
fix(lbagent,monitor): use victoria-metrics for telegraf and fix influxql translation (#24733)
1 parent e6ba085 commit 986d0fb

7 files changed

Lines changed: 183 additions & 22 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ require (
8383
github.com/vmihailenco/msgpack v4.0.4+incompatible
8484
github.com/xuri/excelize/v2 v2.7.1
8585
github.com/zeebo/xxh3 v1.0.2
86-
github.com/zexi/influxql-to-metricsql v0.1.1
86+
github.com/zexi/influxql-to-metricsql v0.1.2
8787
go.etcd.io/etcd/api/v3 v3.5.7
8888
go.etcd.io/etcd/client/v3 v3.5.7
8989
golang.org/x/crypto v0.41.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,8 @@ github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
12031203
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
12041204
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
12051205
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
1206-
github.com/zexi/influxql-to-metricsql v0.1.1 h1:dXnVzlxVLuo88zGkDca7erEnmvprGWjzsBcs8qIoQGQ=
1207-
github.com/zexi/influxql-to-metricsql v0.1.1/go.mod h1:JlC5FY+6De9ZPxG47G5DOgva8P9X1VaKS4ExzCmhSCc=
1206+
github.com/zexi/influxql-to-metricsql v0.1.2 h1:Akkn1PLuNWjwt+Aqxf1fV+Gg+KUIgouVwtzm4XWy/5w=
1207+
github.com/zexi/influxql-to-metricsql v0.1.2/go.mod h1:JlC5FY+6De9ZPxG47G5DOgva8P9X1VaKS4ExzCmhSCc=
12081208
github.com/zexi/promql/v2 v2.12.1 h1:crHKpULdLLsBZ9b78Rg6qQkugzlk6BHeCj93tw/F5RU=
12091209
github.com/zexi/promql/v2 v2.12.1/go.mod h1:2UtzWZGmth95n2qdIZWpJ5yQ0cE5hEvz0dGsajI1Sqg=
12101210
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=

pkg/cloudcommon/tsdb/tsdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewTSDBServiceSource(t string, urls []string) *TSDBServiceSource {
3838

3939
func GetDefaultServiceSource(s *mcclient.ClientSession, endpointType string) (*TSDBServiceSource, error) {
4040
errs := []error{}
41-
for _, sType := range []string{apis.SERVICE_TYPE_INFLUXDB, apis.SERVICE_TYPE_VICTORIA_METRICS} {
41+
for _, sType := range []string{apis.SERVICE_TYPE_VICTORIA_METRICS, apis.SERVICE_TYPE_INFLUXDB} {
4242
urls, err := s.GetServiceURLs(sType, endpointType, httputils.POST)
4343
if err != nil {
4444
errs = append(errs, errors.Wrapf(err, "get %s service type %q", endpointType, sType))

pkg/compute/models/loadbalanceragents.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ func (p *SLoadbalancerAgentParamsTelegraf) updateBy(pp *SLoadbalancerAgentParams
280280
}
281281

282282
func (p *SLoadbalancerAgentParamsTelegraf) initDefault(data *jsonutils.JSONDict) {
283-
if p.InfluxDbOutputUrl == "" {
283+
{
284284
baseOpts := &options.Options
285285
u, _ := tsdb.GetDefaultServiceSourceURL(auth.GetAdminSession(context.Background(), baseOpts.Region), identity_apis.EndpointInterfacePublic)
286-
p.InfluxDbOutputUrl = u
286+
if u != "" {
287+
p.InfluxDbOutputUrl = u
288+
}
287289
p.InfluxDbOutputUnsafeSsl = true
288290
}
289291
if p.HaproxyInputInterval == 0 {
@@ -910,6 +912,8 @@ listen stats
910912
urls = ["{{ .telegraf.influx_db_output_url }}"]
911913
database = "{{ .telegraf.influx_db_output_name }}"
912914
insecure_skip_verify = {{ .telegraf.influx_db_output_unsafe_ssl }}
915+
skip_database_creation = true
916+
timeout = "30s"
913917
914918
[[inputs.haproxy]]
915919
interval = "{{ .telegraf.haproxy_input_interval }}s"

pkg/lbagent/haproxy.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ import (
3333
"yunion.io/x/pkg/gotypes"
3434

3535
"yunion.io/x/onecloud/pkg/apis"
36+
identity_apis "yunion.io/x/onecloud/pkg/apis/identity"
37+
"yunion.io/x/onecloud/pkg/cloudcommon/tsdb"
3638
"yunion.io/x/onecloud/pkg/hostman/hostinfo/hostconsts"
3739
"yunion.io/x/onecloud/pkg/hostman/system_service"
3840
agentmodels "yunion.io/x/onecloud/pkg/lbagent/models"
3941
agentutils "yunion.io/x/onecloud/pkg/lbagent/utils"
42+
"yunion.io/x/onecloud/pkg/mcclient/auth"
4043
"yunion.io/x/onecloud/pkg/util/sysutils"
4144
)
4245

@@ -187,6 +190,13 @@ func (h *HaproxyHelper) handleUseCorpusCmd(ctx context.Context, cmd *LbagentCmd)
187190
return err
188191
}
189192
}
193+
// refresh telegraf URL from service catalog
194+
s := auth.GetAdminSession(ctx, h.opts.Region)
195+
tsdbSrc, _ := tsdb.GetDefaultServiceSource(s, identity_apis.EndpointInterfacePublic)
196+
if tsdbSrc != nil && len(tsdbSrc.URLs) > 0 {
197+
agentParams.AgentModel.Params.Telegraf.InfluxDbOutputUrl = tsdbSrc.URLs[0]
198+
agentParams.SetTelegrafParams("influx_db_output_url", tsdbSrc.URLs[0])
199+
}
190200
if agentParams.AgentModel.Params.Telegraf.InfluxDbOutputUrl != "" {
191201
agentParams.SetTelegrafParams("haproxy_input_stats_socket", h.haproxyStatsSocketFile())
192202
// telegraf config
@@ -198,7 +208,7 @@ func (h *HaproxyHelper) handleUseCorpusCmd(ctx context.Context, cmd *LbagentCmd)
198208
p := filepath.Join(dir, "telegraf.conf")
199209
err := os.WriteFile(p, d, agentutils.FileModeFile)
200210
if err == nil {
201-
err := h.reloadTelegraf(ctx, agentParams)
211+
err := h.reloadTelegraf(ctx, agentParams, tsdbSrc)
202212
if err != nil {
203213
log.Errorf("reloading telegraf.conf failed: %s", err)
204214
}
@@ -420,15 +430,15 @@ func (h *HaproxyHelper) telegrafPidFile() *agentutils.PidFile {
420430
return pf
421431
}
422432

423-
func (h *HaproxyHelper) reloadTelegraf(ctx context.Context, agentParams *agentmodels.AgentParams) error {
433+
func (h *HaproxyHelper) reloadTelegraf(ctx context.Context, agentParams *agentmodels.AgentParams, tsdbSrc *tsdb.TSDBServiceSource) error {
424434
if h.opts.EnableRemoteExecutor {
425-
return h.remoteReloadTelegraf(ctx, agentParams)
435+
return h.remoteReloadTelegraf(ctx, agentParams, tsdbSrc)
426436
} else {
427437
return h.localReloadTelegraf(ctx)
428438
}
429439
}
430440

431-
func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *agentmodels.AgentParams) error {
441+
func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *agentmodels.AgentParams, tsdbSrc *tsdb.TSDBServiceSource) error {
432442
telegraf := system_service.GetService("telegraf")
433443
conf := map[string]interface{}{}
434444
conf["hostname"] = h.getHostname()
@@ -442,7 +452,13 @@ func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *a
442452
hostconsts.TELEGRAF_TAG_KEY_HOST_TYPE: hostconsts.TELEGRAF_TAG_ONECLOUD_HOST_TYPE_LBAGENT,
443453
}
444454
conf["nics"] = h.getNicsTelegrafConf()
445-
if len(agentParams.AgentModel.Params.Telegraf.InfluxDbOutputUrl) > 0 {
455+
if tsdbSrc != nil && len(tsdbSrc.URLs) > 0 {
456+
conf[apis.SERVICE_TYPE_INFLUXDB] = map[string]interface{}{
457+
"url": tsdbSrc.URLs,
458+
"database": agentParams.AgentModel.Params.Telegraf.InfluxDbOutputName,
459+
"tsdb_type": tsdbSrc.Type,
460+
}
461+
} else if len(agentParams.AgentModel.Params.Telegraf.InfluxDbOutputUrl) > 0 {
446462
conf[apis.SERVICE_TYPE_INFLUXDB] = map[string]interface{}{
447463
"url": []string{
448464
agentParams.AgentModel.Params.Telegraf.InfluxDbOutputUrl,
@@ -452,13 +468,13 @@ func (h *HaproxyHelper) remoteReloadTelegraf(ctx context.Context, agentParams *a
452468
}
453469
conf["haproxy"] = map[string]interface{}{
454470
"interval": agentParams.AgentModel.Params.Telegraf.HaproxyInputInterval,
455-
"stats_socket_path": h.haproxyStatsSocketFile(),
471+
"stats_socket_path": filepath.Join("/hostfs", h.haproxyStatsSocketFile()),
456472
}
457473
oldConf := telegraf.GetConf()
458474
log.Debugf("old config: %s", oldConf)
459475
log.Debugf("new config: %s", conf)
460476
if gotypes.IsNil(oldConf) || !reflect.DeepEqual(oldConf, conf) {
461-
log.Debugf("telegraf config: %s", conf)
477+
log.Debugf("telegraf config: %s", telegraf.GetConfig(conf))
462478
telegraf.SetConf(conf)
463479
telegraf.BgReloadConf(conf)
464480
}

vendor/github.com/zexi/influxql-to-metricsql/converter/translator/promql.go

Lines changed: 149 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ github.com/yusufpapurcu/wmi
18461846
# github.com/zeebo/xxh3 v1.0.2
18471847
## explicit; go 1.17
18481848
github.com/zeebo/xxh3
1849-
# github.com/zexi/influxql-to-metricsql v0.1.1
1849+
# github.com/zexi/influxql-to-metricsql v0.1.2
18501850
## explicit; go 1.18
18511851
github.com/zexi/influxql-to-metricsql/converter
18521852
github.com/zexi/influxql-to-metricsql/converter/translator

0 commit comments

Comments
 (0)