Prometheus源码学习(4) 通过2.24对实例化Discoverer代码的改进学习依赖倒置
前面讀的是 2.19.2 版本的代碼,最新更新了 2.24.1,發(fā)現(xiàn)在實(shí)例化 Discoverer 時(shí)改進(jìn)了設(shè)計(jì)。這個(gè)改變是在 2.21 做出的。
2.19.2 中的實(shí)現(xiàn)方式
方法簽名為
func (m *Manager) registerProviders(cfg sd_config.ServiceDiscoveryConfig, setName string) int參數(shù) cfg 是解析配置文件參數(shù)得到的各種 SD 類型
// ServiceDiscoveryConfig configures lists of different service discovery mechanisms. type ServiceDiscoveryConfig struct {// List of labeled target groups for this job.StaticConfigs []*targetgroup.Group `yaml:"static_configs,omitempty"`// List of DNS service discovery configurations.DNSSDConfigs []*dns.SDConfig `yaml:"dns_sd_configs,omitempty"`// List of file service discovery configurations.FileSDConfigs []*file.SDConfig `yaml:"file_sd_configs,omitempty"`// List of Consul service discovery configurations.ConsulSDConfigs []*consul.SDConfig `yaml:"consul_sd_configs,omitempty"`// List of DigitalOcean service discovery configurations.DigitalOceanSDConfigs []*digitalocean.SDConfig `yaml:"digitalocean_sd_configs,omitempty"`// List of Docker Swarm service discovery configurations.DockerSwarmSDConfigs []*dockerswarm.SDConfig `yaml:"dockerswarm_sd_configs,omitempty"`// List of Serverset service discovery configurations.ServersetSDConfigs []*zookeeper.ServersetSDConfig `yaml:"serverset_sd_configs,omitempty"`// NerveSDConfigs is a list of Nerve service discovery configurations.NerveSDConfigs []*zookeeper.NerveSDConfig `yaml:"nerve_sd_configs,omitempty"`// MarathonSDConfigs is a list of Marathon service discovery configurations.MarathonSDConfigs []*marathon.SDConfig `yaml:"marathon_sd_configs,omitempty"`// List of Kubernetes service discovery configurations.KubernetesSDConfigs []*kubernetes.SDConfig `yaml:"kubernetes_sd_configs,omitempty"`// List of GCE service discovery configurations.GCESDConfigs []*gce.SDConfig `yaml:"gce_sd_configs,omitempty"`// List of EC2 service discovery configurations.EC2SDConfigs []*ec2.SDConfig `yaml:"ec2_sd_configs,omitempty"`// List of OpenStack service discovery configurations.OpenstackSDConfigs []*openstack.SDConfig `yaml:"openstack_sd_configs,omitempty"`// List of Azure service discovery configurations.AzureSDConfigs []*azure.SDConfig `yaml:"azure_sd_configs,omitempty"`// List of Triton service discovery configurations.TritonSDConfigs []*triton.SDConfig `yaml:"triton_sd_configs,omitempty"` }方法內(nèi)部首先聲名一個(gè)添加 Discoverer 的閉包函數(shù) add(),閉包函數(shù)的參數(shù)有一個(gè)實(shí)例化 Discoverer 的方法
add := func(cfg interface{}, newDiscoverer func() (Discoverer, error)) {t := reflect.TypeOf(cfg).String()// 已有的 provider 如果有多個(gè) job 配置了它就把 job_name 追加到 這個(gè)provider 的 subs 中。// 否則就新建 providerfor _, p := range m.providers {if reflect.DeepEqual(cfg, p.config) {p.subs = append(p.subs, setName)level.Info(m.logger).Log("msg", "append subscribers", "sub", p.subs)added = truereturn}}d, err := newDiscoverer()if err != nil {level.Error(m.logger).Log("msg", "Cannot create service discovery", "err", err, "type", t)failedCount++return}provider := provider{name: fmt.Sprintf("%s/%d", t, len(m.providers)),d: d,config: cfg,subs: []string{setName},}m.providers = append(m.providers, &provider)added = true}這種模式要在 manager.go 文件中導(dǎo)入每一種具體的服務(wù)發(fā)現(xiàn)器,也就是要在抽象層依賴各個(gè)實(shí)現(xiàn)。
2.24.1 中的實(shí)現(xiàn)方式
*Manager.registerProviders() 里面的 add 閉包函數(shù)的初始化 Discoverer 方法是調(diào)用接口要求的 NewDiscoverer() 方法
d, err := cfg.NewDiscoverer(DiscovererOptions{Logger: log.With(m.logger, "discovery", typ),})遍歷也簡(jiǎn)化了
for _, cfg := range cfgs {add(cfg)}返回的是調(diào)用本 SD 自己的 NewDiscovery() 函數(shù)得到的具體的SD實(shí)例
// NewDiscovery returns a new file discovery for the given paths. func NewDiscovery(conf *SDConfig, logger log.Logger) *Discovery {if logger == nil {logger = log.NewNopLogger()}disc := &Discovery{paths: conf.Files,interval: time.Duration(conf.RefreshInterval),timestamps: make(map[string]float64),logger: logger,}fileSDTimeStamp.addDiscoverer(disc)return disc }模式學(xué)習(xí)
這樣就實(shí)現(xiàn)了由抽象依賴實(shí)現(xiàn)翻轉(zhuǎn)為實(shí)現(xiàn)依賴抽象。
install 是一個(gè)中介包,main 依賴它,它的內(nèi)部導(dǎo)入各個(gè)具體的 SD 實(shí)現(xiàn)包,這樣集中了多個(gè)具體實(shí)現(xiàn)的導(dǎo)入位置便于修改,也使 main 的導(dǎo)入部分變得簡(jiǎn)潔。
之前的依賴順序
#mermaid-svg-xcc1xWU9QtLwBNcH .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .label text{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .node rect,#mermaid-svg-xcc1xWU9QtLwBNcH .node circle,#mermaid-svg-xcc1xWU9QtLwBNcH .node ellipse,#mermaid-svg-xcc1xWU9QtLwBNcH .node polygon,#mermaid-svg-xcc1xWU9QtLwBNcH .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-xcc1xWU9QtLwBNcH .node .label{text-align:center;fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .node.clickable{cursor:pointer}#mermaid-svg-xcc1xWU9QtLwBNcH .arrowheadPath{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-xcc1xWU9QtLwBNcH .flowchart-link{stroke:#333;fill:none}#mermaid-svg-xcc1xWU9QtLwBNcH .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-xcc1xWU9QtLwBNcH .edgeLabel rect{opacity:0.9}#mermaid-svg-xcc1xWU9QtLwBNcH .edgeLabel span{color:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-xcc1xWU9QtLwBNcH .cluster text{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-xcc1xWU9QtLwBNcH .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-xcc1xWU9QtLwBNcH text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-xcc1xWU9QtLwBNcH .actor-line{stroke:grey}#mermaid-svg-xcc1xWU9QtLwBNcH .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-xcc1xWU9QtLwBNcH #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .sequenceNumber{fill:#fff}#mermaid-svg-xcc1xWU9QtLwBNcH #sequencenumber{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH #crosshead path{fill:#333;stroke:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .messageText{fill:#333;stroke:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-xcc1xWU9QtLwBNcH .labelText,#mermaid-svg-xcc1xWU9QtLwBNcH .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-xcc1xWU9QtLwBNcH .loopText,#mermaid-svg-xcc1xWU9QtLwBNcH .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-xcc1xWU9QtLwBNcH .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-xcc1xWU9QtLwBNcH .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-xcc1xWU9QtLwBNcH .noteText,#mermaid-svg-xcc1xWU9QtLwBNcH .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-xcc1xWU9QtLwBNcH .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-xcc1xWU9QtLwBNcH .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-xcc1xWU9QtLwBNcH .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-xcc1xWU9QtLwBNcH .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .section{stroke:none;opacity:0.2}#mermaid-svg-xcc1xWU9QtLwBNcH .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-xcc1xWU9QtLwBNcH .section2{fill:#fff400}#mermaid-svg-xcc1xWU9QtLwBNcH .section1,#mermaid-svg-xcc1xWU9QtLwBNcH .section3{fill:#fff;opacity:0.2}#mermaid-svg-xcc1xWU9QtLwBNcH .sectionTitle0{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .sectionTitle1{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .sectionTitle2{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .sectionTitle3{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-xcc1xWU9QtLwBNcH .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .grid path{stroke-width:0}#mermaid-svg-xcc1xWU9QtLwBNcH .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-xcc1xWU9QtLwBNcH .task{stroke-width:2}#mermaid-svg-xcc1xWU9QtLwBNcH .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .taskText:not([font-size]){font-size:11px}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-xcc1xWU9QtLwBNcH .task.clickable{cursor:pointer}#mermaid-svg-xcc1xWU9QtLwBNcH .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xcc1xWU9QtLwBNcH .taskText0,#mermaid-svg-xcc1xWU9QtLwBNcH .taskText1,#mermaid-svg-xcc1xWU9QtLwBNcH .taskText2,#mermaid-svg-xcc1xWU9QtLwBNcH .taskText3{fill:#fff}#mermaid-svg-xcc1xWU9QtLwBNcH .task0,#mermaid-svg-xcc1xWU9QtLwBNcH .task1,#mermaid-svg-xcc1xWU9QtLwBNcH .task2,#mermaid-svg-xcc1xWU9QtLwBNcH .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutside0,#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutside2{fill:#000}#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutside1,#mermaid-svg-xcc1xWU9QtLwBNcH .taskTextOutside3{fill:#000}#mermaid-svg-xcc1xWU9QtLwBNcH .active0,#mermaid-svg-xcc1xWU9QtLwBNcH .active1,#mermaid-svg-xcc1xWU9QtLwBNcH .active2,#mermaid-svg-xcc1xWU9QtLwBNcH .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-xcc1xWU9QtLwBNcH .activeText0,#mermaid-svg-xcc1xWU9QtLwBNcH .activeText1,#mermaid-svg-xcc1xWU9QtLwBNcH .activeText2,#mermaid-svg-xcc1xWU9QtLwBNcH .activeText3{fill:#000 !important}#mermaid-svg-xcc1xWU9QtLwBNcH .done0,#mermaid-svg-xcc1xWU9QtLwBNcH .done1,#mermaid-svg-xcc1xWU9QtLwBNcH .done2,#mermaid-svg-xcc1xWU9QtLwBNcH .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-xcc1xWU9QtLwBNcH .doneText0,#mermaid-svg-xcc1xWU9QtLwBNcH .doneText1,#mermaid-svg-xcc1xWU9QtLwBNcH .doneText2,#mermaid-svg-xcc1xWU9QtLwBNcH .doneText3{fill:#000 !important}#mermaid-svg-xcc1xWU9QtLwBNcH .crit0,#mermaid-svg-xcc1xWU9QtLwBNcH .crit1,#mermaid-svg-xcc1xWU9QtLwBNcH .crit2,#mermaid-svg-xcc1xWU9QtLwBNcH .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-xcc1xWU9QtLwBNcH .activeCrit0,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCrit1,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCrit2,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-xcc1xWU9QtLwBNcH .doneCrit0,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCrit1,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCrit2,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-xcc1xWU9QtLwBNcH .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-xcc1xWU9QtLwBNcH .milestoneText{font-style:italic}#mermaid-svg-xcc1xWU9QtLwBNcH .doneCritText0,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCritText1,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCritText2,#mermaid-svg-xcc1xWU9QtLwBNcH .doneCritText3{fill:#000 !important}#mermaid-svg-xcc1xWU9QtLwBNcH .activeCritText0,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCritText1,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCritText2,#mermaid-svg-xcc1xWU9QtLwBNcH .activeCritText3{fill:#000 !important}#mermaid-svg-xcc1xWU9QtLwBNcH .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-xcc1xWU9QtLwBNcH g.classGroup text .title{font-weight:bolder}#mermaid-svg-xcc1xWU9QtLwBNcH g.clickable{cursor:pointer}#mermaid-svg-xcc1xWU9QtLwBNcH g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-xcc1xWU9QtLwBNcH g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-xcc1xWU9QtLwBNcH .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-xcc1xWU9QtLwBNcH .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-xcc1xWU9QtLwBNcH .dashed-line{stroke-dasharray:3}#mermaid-svg-xcc1xWU9QtLwBNcH #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH .commit-id,#mermaid-svg-xcc1xWU9QtLwBNcH .commit-msg,#mermaid-svg-xcc1xWU9QtLwBNcH .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-xcc1xWU9QtLwBNcH g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-xcc1xWU9QtLwBNcH g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-xcc1xWU9QtLwBNcH g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-xcc1xWU9QtLwBNcH .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-xcc1xWU9QtLwBNcH .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-xcc1xWU9QtLwBNcH .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-xcc1xWU9QtLwBNcH .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-xcc1xWU9QtLwBNcH .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-xcc1xWU9QtLwBNcH .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-xcc1xWU9QtLwBNcH .edgeLabel text{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xcc1xWU9QtLwBNcH .node circle.state-start{fill:black;stroke:black}#mermaid-svg-xcc1xWU9QtLwBNcH .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-xcc1xWU9QtLwBNcH #statediagram-barbEnd{fill:#9370db}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-state .divider{stroke:#9370db}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-xcc1xWU9QtLwBNcH .note-edge{stroke-dasharray:5}#mermaid-svg-xcc1xWU9QtLwBNcH .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-xcc1xWU9QtLwBNcH .error-icon{fill:#522}#mermaid-svg-xcc1xWU9QtLwBNcH .error-text{fill:#522;stroke:#522}#mermaid-svg-xcc1xWU9QtLwBNcH .edge-thickness-normal{stroke-width:2px}#mermaid-svg-xcc1xWU9QtLwBNcH .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-xcc1xWU9QtLwBNcH .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-xcc1xWU9QtLwBNcH .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-xcc1xWU9QtLwBNcH .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-xcc1xWU9QtLwBNcH .marker{fill:#333}#mermaid-svg-xcc1xWU9QtLwBNcH .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-xcc1xWU9QtLwBNcH {color: rgba(0, 0, 0, 0.75);font: ;}maindiscoveryconsulfileec2kubernetes如果添加一個(gè) SD,需要添加 discovery/config/config.go 和 discovery/manager.go 中的依賴,并且要添加 *Manager.registerProviders() 的代碼
現(xiàn)在的依賴順序
#mermaid-svg-bYPvnATnn8JbkKVI .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-bYPvnATnn8JbkKVI .label text{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .node rect,#mermaid-svg-bYPvnATnn8JbkKVI .node circle,#mermaid-svg-bYPvnATnn8JbkKVI .node ellipse,#mermaid-svg-bYPvnATnn8JbkKVI .node polygon,#mermaid-svg-bYPvnATnn8JbkKVI .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-bYPvnATnn8JbkKVI .node .label{text-align:center;fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .node.clickable{cursor:pointer}#mermaid-svg-bYPvnATnn8JbkKVI .arrowheadPath{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-bYPvnATnn8JbkKVI .flowchart-link{stroke:#333;fill:none}#mermaid-svg-bYPvnATnn8JbkKVI .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-bYPvnATnn8JbkKVI .edgeLabel rect{opacity:0.9}#mermaid-svg-bYPvnATnn8JbkKVI .edgeLabel span{color:#333}#mermaid-svg-bYPvnATnn8JbkKVI .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-bYPvnATnn8JbkKVI .cluster text{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-bYPvnATnn8JbkKVI .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-bYPvnATnn8JbkKVI text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-bYPvnATnn8JbkKVI .actor-line{stroke:grey}#mermaid-svg-bYPvnATnn8JbkKVI .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-bYPvnATnn8JbkKVI .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-bYPvnATnn8JbkKVI #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-bYPvnATnn8JbkKVI .sequenceNumber{fill:#fff}#mermaid-svg-bYPvnATnn8JbkKVI #sequencenumber{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI #crosshead path{fill:#333;stroke:#333}#mermaid-svg-bYPvnATnn8JbkKVI .messageText{fill:#333;stroke:#333}#mermaid-svg-bYPvnATnn8JbkKVI .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-bYPvnATnn8JbkKVI .labelText,#mermaid-svg-bYPvnATnn8JbkKVI .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-bYPvnATnn8JbkKVI .loopText,#mermaid-svg-bYPvnATnn8JbkKVI .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-bYPvnATnn8JbkKVI .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-bYPvnATnn8JbkKVI .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-bYPvnATnn8JbkKVI .noteText,#mermaid-svg-bYPvnATnn8JbkKVI .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-bYPvnATnn8JbkKVI .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-bYPvnATnn8JbkKVI .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-bYPvnATnn8JbkKVI .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-bYPvnATnn8JbkKVI .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .section{stroke:none;opacity:0.2}#mermaid-svg-bYPvnATnn8JbkKVI .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-bYPvnATnn8JbkKVI .section2{fill:#fff400}#mermaid-svg-bYPvnATnn8JbkKVI .section1,#mermaid-svg-bYPvnATnn8JbkKVI .section3{fill:#fff;opacity:0.2}#mermaid-svg-bYPvnATnn8JbkKVI .sectionTitle0{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .sectionTitle1{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .sectionTitle2{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .sectionTitle3{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-bYPvnATnn8JbkKVI .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .grid path{stroke-width:0}#mermaid-svg-bYPvnATnn8JbkKVI .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-bYPvnATnn8JbkKVI .task{stroke-width:2}#mermaid-svg-bYPvnATnn8JbkKVI .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .taskText:not([font-size]){font-size:11px}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-bYPvnATnn8JbkKVI .task.clickable{cursor:pointer}#mermaid-svg-bYPvnATnn8JbkKVI .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-bYPvnATnn8JbkKVI .taskText0,#mermaid-svg-bYPvnATnn8JbkKVI .taskText1,#mermaid-svg-bYPvnATnn8JbkKVI .taskText2,#mermaid-svg-bYPvnATnn8JbkKVI .taskText3{fill:#fff}#mermaid-svg-bYPvnATnn8JbkKVI .task0,#mermaid-svg-bYPvnATnn8JbkKVI .task1,#mermaid-svg-bYPvnATnn8JbkKVI .task2,#mermaid-svg-bYPvnATnn8JbkKVI .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutside0,#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutside2{fill:#000}#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutside1,#mermaid-svg-bYPvnATnn8JbkKVI .taskTextOutside3{fill:#000}#mermaid-svg-bYPvnATnn8JbkKVI .active0,#mermaid-svg-bYPvnATnn8JbkKVI .active1,#mermaid-svg-bYPvnATnn8JbkKVI .active2,#mermaid-svg-bYPvnATnn8JbkKVI .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-bYPvnATnn8JbkKVI .activeText0,#mermaid-svg-bYPvnATnn8JbkKVI .activeText1,#mermaid-svg-bYPvnATnn8JbkKVI .activeText2,#mermaid-svg-bYPvnATnn8JbkKVI .activeText3{fill:#000 !important}#mermaid-svg-bYPvnATnn8JbkKVI .done0,#mermaid-svg-bYPvnATnn8JbkKVI .done1,#mermaid-svg-bYPvnATnn8JbkKVI .done2,#mermaid-svg-bYPvnATnn8JbkKVI .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-bYPvnATnn8JbkKVI .doneText0,#mermaid-svg-bYPvnATnn8JbkKVI .doneText1,#mermaid-svg-bYPvnATnn8JbkKVI .doneText2,#mermaid-svg-bYPvnATnn8JbkKVI .doneText3{fill:#000 !important}#mermaid-svg-bYPvnATnn8JbkKVI .crit0,#mermaid-svg-bYPvnATnn8JbkKVI .crit1,#mermaid-svg-bYPvnATnn8JbkKVI .crit2,#mermaid-svg-bYPvnATnn8JbkKVI .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-bYPvnATnn8JbkKVI .activeCrit0,#mermaid-svg-bYPvnATnn8JbkKVI .activeCrit1,#mermaid-svg-bYPvnATnn8JbkKVI .activeCrit2,#mermaid-svg-bYPvnATnn8JbkKVI .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-bYPvnATnn8JbkKVI .doneCrit0,#mermaid-svg-bYPvnATnn8JbkKVI .doneCrit1,#mermaid-svg-bYPvnATnn8JbkKVI .doneCrit2,#mermaid-svg-bYPvnATnn8JbkKVI .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-bYPvnATnn8JbkKVI .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-bYPvnATnn8JbkKVI .milestoneText{font-style:italic}#mermaid-svg-bYPvnATnn8JbkKVI .doneCritText0,#mermaid-svg-bYPvnATnn8JbkKVI .doneCritText1,#mermaid-svg-bYPvnATnn8JbkKVI .doneCritText2,#mermaid-svg-bYPvnATnn8JbkKVI .doneCritText3{fill:#000 !important}#mermaid-svg-bYPvnATnn8JbkKVI .activeCritText0,#mermaid-svg-bYPvnATnn8JbkKVI .activeCritText1,#mermaid-svg-bYPvnATnn8JbkKVI .activeCritText2,#mermaid-svg-bYPvnATnn8JbkKVI .activeCritText3{fill:#000 !important}#mermaid-svg-bYPvnATnn8JbkKVI .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-bYPvnATnn8JbkKVI g.classGroup text .title{font-weight:bolder}#mermaid-svg-bYPvnATnn8JbkKVI g.clickable{cursor:pointer}#mermaid-svg-bYPvnATnn8JbkKVI g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-bYPvnATnn8JbkKVI g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-bYPvnATnn8JbkKVI .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-bYPvnATnn8JbkKVI .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-bYPvnATnn8JbkKVI .dashed-line{stroke-dasharray:3}#mermaid-svg-bYPvnATnn8JbkKVI #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI .commit-id,#mermaid-svg-bYPvnATnn8JbkKVI .commit-msg,#mermaid-svg-bYPvnATnn8JbkKVI .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-bYPvnATnn8JbkKVI g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-bYPvnATnn8JbkKVI g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-bYPvnATnn8JbkKVI g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-bYPvnATnn8JbkKVI .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-bYPvnATnn8JbkKVI .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-bYPvnATnn8JbkKVI .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-bYPvnATnn8JbkKVI .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-bYPvnATnn8JbkKVI .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-bYPvnATnn8JbkKVI .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-bYPvnATnn8JbkKVI .edgeLabel text{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-bYPvnATnn8JbkKVI .node circle.state-start{fill:black;stroke:black}#mermaid-svg-bYPvnATnn8JbkKVI .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-bYPvnATnn8JbkKVI #statediagram-barbEnd{fill:#9370db}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-state .divider{stroke:#9370db}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-bYPvnATnn8JbkKVI .note-edge{stroke-dasharray:5}#mermaid-svg-bYPvnATnn8JbkKVI .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-bYPvnATnn8JbkKVI .error-icon{fill:#522}#mermaid-svg-bYPvnATnn8JbkKVI .error-text{fill:#522;stroke:#522}#mermaid-svg-bYPvnATnn8JbkKVI .edge-thickness-normal{stroke-width:2px}#mermaid-svg-bYPvnATnn8JbkKVI .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-bYPvnATnn8JbkKVI .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-bYPvnATnn8JbkKVI .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-bYPvnATnn8JbkKVI .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-bYPvnATnn8JbkKVI .marker{fill:#333}#mermaid-svg-bYPvnATnn8JbkKVI .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-bYPvnATnn8JbkKVI {color: rgba(0, 0, 0, 0.75);font: ;}maininstallconsulfileec2kubernetesdiscovery如果添加一個(gè) SD,僅需要添加 discovery/install/install.go,刪除了 discovery/config/ 目錄
總結(jié)
以上是生活随笔為你收集整理的Prometheus源码学习(4) 通过2.24对实例化Discoverer代码的改进学习依赖倒置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 南邮ctf答案php是世界,南邮ctf训
- 下一篇: 类和对象——初入江湖