2017-11-25 13:13:54 +00:00
|
|
|
// Copyright 2016 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package discovery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-kit/kit/log"
|
|
|
|
"github.com/go-kit/kit/log/level"
|
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/config"
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
sd_config "github.com/prometheus/prometheus/discovery/config"
|
|
|
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
2017-11-25 13:13:54 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/prometheus/discovery/azure"
|
|
|
|
"github.com/prometheus/prometheus/discovery/consul"
|
|
|
|
"github.com/prometheus/prometheus/discovery/dns"
|
|
|
|
"github.com/prometheus/prometheus/discovery/ec2"
|
|
|
|
"github.com/prometheus/prometheus/discovery/file"
|
|
|
|
"github.com/prometheus/prometheus/discovery/gce"
|
|
|
|
"github.com/prometheus/prometheus/discovery/kubernetes"
|
|
|
|
"github.com/prometheus/prometheus/discovery/marathon"
|
|
|
|
"github.com/prometheus/prometheus/discovery/openstack"
|
|
|
|
"github.com/prometheus/prometheus/discovery/triton"
|
|
|
|
"github.com/prometheus/prometheus/discovery/zookeeper"
|
|
|
|
)
|
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
// Discoverer provides information about target groups. It maintains a set
|
2017-11-25 13:13:54 +00:00
|
|
|
// of sources from which TargetGroups can originate. Whenever a discovery provider
|
2017-11-26 22:18:05 +00:00
|
|
|
// detects a potential change, it sends the TargetGroup through its channel.
|
2017-11-25 13:13:54 +00:00
|
|
|
//
|
2017-11-26 22:18:05 +00:00
|
|
|
// Discoverer does not know if an actual change happened.
|
2017-11-25 13:13:54 +00:00
|
|
|
// It does guarantee that it sends the new TargetGroup whenever a change happens.
|
|
|
|
//
|
2017-11-26 22:18:05 +00:00
|
|
|
// Discoverers should initially send a full set of all discoverable TargetGroups.
|
|
|
|
type Discoverer interface {
|
2017-11-25 13:13:54 +00:00
|
|
|
// Run hands a channel to the discovery provider(consul,dns etc) through which it can send
|
|
|
|
// updated target groups.
|
|
|
|
// Must returns if the context gets canceled. It should not close the update
|
|
|
|
// channel on returning.
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
Run(ctx context.Context, up chan<- []*targetgroup.Group)
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-03 13:56:28 +00:00
|
|
|
type poolKey struct {
|
2017-12-18 19:41:31 +00:00
|
|
|
setName string
|
2017-12-03 13:56:28 +00:00
|
|
|
provider string
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
// NewManager is the Discovery Manager constructor
|
2017-12-01 12:59:24 +00:00
|
|
|
func NewManager(logger log.Logger) *Manager {
|
2017-11-26 22:18:05 +00:00
|
|
|
return &Manager{
|
|
|
|
logger: logger,
|
2017-12-01 12:59:24 +00:00
|
|
|
actionCh: make(chan func(context.Context)),
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
syncCh: make(chan map[string][]*targetgroup.Group),
|
2018-01-04 13:14:22 +00:00
|
|
|
targets: make(map[poolKey]map[string]*targetgroup.Group),
|
2017-11-26 22:18:05 +00:00
|
|
|
discoverCancel: []context.CancelFunc{},
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
// Manager maintains a set of discovery providers and sends each update to a channel used by other packages.
|
|
|
|
type Manager struct {
|
|
|
|
logger log.Logger
|
2017-12-01 12:59:24 +00:00
|
|
|
actionCh chan func(context.Context)
|
2017-11-26 22:18:05 +00:00
|
|
|
discoverCancel []context.CancelFunc
|
2018-01-04 21:57:28 +00:00
|
|
|
// Some Discoverers(eg. k8s) send only the updates for a given target group
|
2018-01-12 12:19:52 +00:00
|
|
|
// so we use map[tg.Source]*targetgroup.Group to know which group to update.
|
2018-01-04 13:14:22 +00:00
|
|
|
targets map[poolKey]map[string]*targetgroup.Group
|
2017-12-03 13:56:28 +00:00
|
|
|
// The sync channels sends the updates in map[targetSetName] where targetSetName is the job value from the scrape config.
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
syncCh chan map[string][]*targetgroup.Group
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run starts the background processing
|
2017-12-01 12:59:24 +00:00
|
|
|
func (m *Manager) Run(ctx context.Context) error {
|
2017-11-25 13:13:54 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case f := <-m.actionCh:
|
2017-12-01 12:59:24 +00:00
|
|
|
f(ctx)
|
|
|
|
case <-ctx.Done():
|
2017-11-29 22:38:52 +00:00
|
|
|
m.cancelDiscoverers()
|
2017-12-01 12:59:24 +00:00
|
|
|
return ctx.Err()
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:38:52 +00:00
|
|
|
// SyncCh returns a read only channel used by all Discoverers to send target updates.
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
func (m *Manager) SyncCh() <-chan map[string][]*targetgroup.Group {
|
2017-11-25 13:13:54 +00:00
|
|
|
return m.syncCh
|
|
|
|
}
|
|
|
|
|
|
|
|
// ApplyConfig removes all running discovery providers and starts new ones using the provided config.
|
2017-11-26 22:18:05 +00:00
|
|
|
func (m *Manager) ApplyConfig(cfg *config.Config) error {
|
2017-11-25 13:13:54 +00:00
|
|
|
err := make(chan error)
|
2017-12-01 12:59:24 +00:00
|
|
|
m.actionCh <- func(ctx context.Context) {
|
2017-11-26 22:18:05 +00:00
|
|
|
m.cancelDiscoverers()
|
2017-11-25 13:13:54 +00:00
|
|
|
for _, scfg := range cfg.ScrapeConfigs {
|
|
|
|
for provName, prov := range m.providersFromConfig(scfg.ServiceDiscoveryConfig) {
|
2017-12-18 19:41:31 +00:00
|
|
|
m.startProvider(ctx, poolKey{setName: scfg.JobName, provider: provName}, prov)
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return <-err
|
|
|
|
}
|
|
|
|
|
2017-12-03 13:56:28 +00:00
|
|
|
func (m *Manager) startProvider(ctx context.Context, poolKey poolKey, worker Discoverer) {
|
2017-12-01 12:59:24 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
updates := make(chan []*targetgroup.Group)
|
2017-11-27 01:59:34 +00:00
|
|
|
|
|
|
|
m.discoverCancel = append(m.discoverCancel, cancel)
|
|
|
|
|
|
|
|
go worker.Run(ctx, updates)
|
2017-12-03 13:56:28 +00:00
|
|
|
go m.runProvider(ctx, poolKey, updates)
|
2017-12-01 12:59:24 +00:00
|
|
|
}
|
|
|
|
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
func (m *Manager) runProvider(ctx context.Context, poolKey poolKey, updates chan []*targetgroup.Group) {
|
2017-12-01 12:59:24 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
case tgs, ok := <-updates:
|
|
|
|
// Handle the case that a target provider exits and closes the channel
|
|
|
|
// before the context is done.
|
|
|
|
if !ok {
|
2017-11-27 01:59:34 +00:00
|
|
|
return
|
|
|
|
}
|
2018-01-04 13:14:22 +00:00
|
|
|
m.updateGroup(poolKey, tgs)
|
|
|
|
m.syncCh <- m.allGroups()
|
2017-11-27 01:59:34 +00:00
|
|
|
}
|
2017-12-01 12:59:24 +00:00
|
|
|
}
|
2017-11-27 01:59:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
func (m *Manager) cancelDiscoverers() {
|
|
|
|
for _, c := range m.discoverCancel {
|
|
|
|
c()
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
2018-01-04 13:14:22 +00:00
|
|
|
m.targets = make(map[poolKey]map[string]*targetgroup.Group)
|
2017-12-01 12:59:24 +00:00
|
|
|
m.discoverCancel = nil
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 13:57:34 +00:00
|
|
|
func (m *Manager) updateGroup(poolKey poolKey, tgs []*targetgroup.Group) {
|
2017-12-01 12:59:24 +00:00
|
|
|
done := make(chan struct{})
|
2017-11-29 22:38:52 +00:00
|
|
|
|
2017-12-01 12:59:24 +00:00
|
|
|
m.actionCh <- func(ctx context.Context) {
|
2018-01-05 10:56:56 +00:00
|
|
|
if tgs == nil {
|
|
|
|
close(done)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tg := range tgs {
|
|
|
|
if tg != nil { // Some Discoverers send nil targetgroup so need to check for it to avoid panics.
|
|
|
|
if _, ok := m.targets[poolKey]; !ok {
|
|
|
|
m.targets[poolKey] = make(map[string]*targetgroup.Group)
|
2018-01-04 13:14:22 +00:00
|
|
|
}
|
2018-01-05 10:56:56 +00:00
|
|
|
m.targets[poolKey][tg.Source] = tg
|
2018-01-04 13:14:22 +00:00
|
|
|
}
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
2017-12-01 12:59:24 +00:00
|
|
|
close(done)
|
|
|
|
|
|
|
|
}
|
|
|
|
<-done
|
|
|
|
}
|
|
|
|
|
2018-01-04 13:14:22 +00:00
|
|
|
func (m *Manager) allGroups() map[string][]*targetgroup.Group {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
tSets := make(chan map[string][]*targetgroup.Group)
|
2017-12-01 12:59:24 +00:00
|
|
|
|
|
|
|
m.actionCh <- func(ctx context.Context) {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
tSetsAll := map[string][]*targetgroup.Group{}
|
2018-01-04 21:41:54 +00:00
|
|
|
for pkey, tsets := range m.targets {
|
2018-01-12 13:10:59 +00:00
|
|
|
del := true
|
2018-01-04 21:41:54 +00:00
|
|
|
for _, tg := range tsets {
|
2018-01-12 13:10:59 +00:00
|
|
|
if len(tg.Targets) != 0 {
|
|
|
|
tSetsAll[pkey.setName] = append(tSetsAll[pkey.setName], tg)
|
|
|
|
del = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Delete the empty map for this target set to avoid memory leaks.
|
|
|
|
if del {
|
|
|
|
delete(m.targets, pkey)
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-03 13:56:28 +00:00
|
|
|
tSets <- tSetsAll
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
2017-12-03 13:56:28 +00:00
|
|
|
return <-tSets
|
2017-12-01 12:59:24 +00:00
|
|
|
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
func (m *Manager) providersFromConfig(cfg sd_config.ServiceDiscoveryConfig) map[string]Discoverer {
|
2017-11-26 22:18:05 +00:00
|
|
|
providers := map[string]Discoverer{}
|
2017-11-25 13:13:54 +00:00
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
app := func(mech string, i int, tp Discoverer) {
|
2017-11-25 13:13:54 +00:00
|
|
|
providers[fmt.Sprintf("%s/%d", mech, i)] = tp
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, c := range cfg.DNSSDConfigs {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
app("dns", i, dns.NewDiscovery(*c, log.With(m.logger, "discovery", "dns")))
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
for i, c := range cfg.FileSDConfigs {
|
|
|
|
app("file", i, file.NewDiscovery(c, log.With(m.logger, "discovery", "file")))
|
|
|
|
}
|
|
|
|
for i, c := range cfg.ConsulSDConfigs {
|
|
|
|
k, err := consul.NewDiscovery(c, log.With(m.logger, "discovery", "consul"))
|
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot create Consul discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("consul", i, k)
|
|
|
|
}
|
|
|
|
for i, c := range cfg.MarathonSDConfigs {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
t, err := marathon.NewDiscovery(*c, log.With(m.logger, "discovery", "marathon"))
|
2017-11-25 13:13:54 +00:00
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot create Marathon discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("marathon", i, t)
|
|
|
|
}
|
|
|
|
for i, c := range cfg.KubernetesSDConfigs {
|
|
|
|
k, err := kubernetes.New(log.With(m.logger, "discovery", "k8s"), c)
|
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot create Kubernetes discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("kubernetes", i, k)
|
|
|
|
}
|
|
|
|
for i, c := range cfg.ServersetSDConfigs {
|
|
|
|
app("serverset", i, zookeeper.NewServersetDiscovery(c, log.With(m.logger, "discovery", "zookeeper")))
|
|
|
|
}
|
|
|
|
for i, c := range cfg.NerveSDConfigs {
|
|
|
|
app("nerve", i, zookeeper.NewNerveDiscovery(c, log.With(m.logger, "discovery", "nerve")))
|
|
|
|
}
|
|
|
|
for i, c := range cfg.EC2SDConfigs {
|
|
|
|
app("ec2", i, ec2.NewDiscovery(c, log.With(m.logger, "discovery", "ec2")))
|
|
|
|
}
|
|
|
|
for i, c := range cfg.OpenstackSDConfigs {
|
|
|
|
openstackd, err := openstack.NewDiscovery(c, log.With(m.logger, "discovery", "openstack"))
|
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot initialize OpenStack discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("openstack", i, openstackd)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, c := range cfg.GCESDConfigs {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
gced, err := gce.NewDiscovery(*c, log.With(m.logger, "discovery", "gce"))
|
2017-11-25 13:13:54 +00:00
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot initialize GCE discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("gce", i, gced)
|
|
|
|
}
|
|
|
|
for i, c := range cfg.AzureSDConfigs {
|
|
|
|
app("azure", i, azure.NewDiscovery(c, log.With(m.logger, "discovery", "azure")))
|
|
|
|
}
|
|
|
|
for i, c := range cfg.TritonSDConfigs {
|
|
|
|
t, err := triton.New(log.With(m.logger, "discovery", "trition"), c)
|
|
|
|
if err != nil {
|
|
|
|
level.Error(m.logger).Log("msg", "Cannot create Triton discovery", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
app("triton", i, t)
|
|
|
|
}
|
|
|
|
if len(cfg.StaticConfigs) > 0 {
|
|
|
|
app("static", 0, NewStaticProvider(cfg.StaticConfigs))
|
|
|
|
}
|
|
|
|
|
|
|
|
return providers
|
|
|
|
}
|
|
|
|
|
|
|
|
// StaticProvider holds a list of target groups that never change.
|
|
|
|
type StaticProvider struct {
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
TargetGroups []*targetgroup.Group
|
2017-11-25 13:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewStaticProvider returns a StaticProvider configured with the given
|
|
|
|
// target groups.
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
func NewStaticProvider(groups []*targetgroup.Group) *StaticProvider {
|
2017-11-25 13:13:54 +00:00
|
|
|
for i, tg := range groups {
|
|
|
|
tg.Source = fmt.Sprintf("%d", i)
|
|
|
|
}
|
|
|
|
return &StaticProvider{groups}
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:18:05 +00:00
|
|
|
// Run implements the Worker interface.
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 20:01:34 +00:00
|
|
|
func (sd *StaticProvider) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
|
2017-11-25 13:13:54 +00:00
|
|
|
// We still have to consider that the consumer exits right away in which case
|
|
|
|
// the context will be canceled.
|
|
|
|
select {
|
|
|
|
case ch <- sd.TargetGroups:
|
|
|
|
case <-ctx.Done():
|
|
|
|
}
|
|
|
|
close(ch)
|
|
|
|
}
|