(client *topom.ApiClient)
| 119 | } |
| 120 | |
| 121 | func newHealthyChecker(client *topom.ApiClient) *HealthyChecker { |
| 122 | stats, err := client.Stats() |
| 123 | if err != nil { |
| 124 | log.PanicErrorf(err, "rpc stats failed") |
| 125 | } |
| 126 | |
| 127 | hc := &HealthyChecker{Stats: stats} |
| 128 | |
| 129 | hc.pstatus = make(map[string]int) |
| 130 | for _, p := range hc.Proxy.Models { |
| 131 | switch stats := hc.Proxy.Stats[p.Token]; { |
| 132 | case stats == nil: |
| 133 | hc.pstatus[p.Token] = CodeMissing |
| 134 | case stats.Error != nil: |
| 135 | hc.pstatus[p.Token] = CodeError |
| 136 | case stats.Timeout || stats.Stats == nil: |
| 137 | hc.pstatus[p.Token] = CodeTimeout |
| 138 | default: |
| 139 | hc.pstatus[p.Token] = CodeAlive |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | hc.sstatus = make(map[string]int) |
| 144 | for _, g := range hc.Group.Models { |
| 145 | for i, x := range g.Servers { |
| 146 | var addr = x.Addr |
| 147 | switch stats := hc.Group.Stats[addr]; { |
| 148 | case stats == nil: |
| 149 | hc.sstatus[addr] = CodeMissing |
| 150 | case stats.Error != nil: |
| 151 | hc.sstatus[addr] = CodeError |
| 152 | case stats.Timeout || stats.Stats == nil: |
| 153 | hc.sstatus[addr] = CodeTimeout |
| 154 | default: |
| 155 | if i == 0 { |
| 156 | if stats.Stats["master_addr"] != "" { |
| 157 | hc.sstatus[addr] = CodeSyncError |
| 158 | } else { |
| 159 | hc.sstatus[addr] = CodeSyncReady |
| 160 | } |
| 161 | } else { |
| 162 | if stats.Stats["master_addr"] != g.Servers[0].Addr { |
| 163 | hc.sstatus[addr] = CodeSyncError |
| 164 | } else { |
| 165 | switch stats.Stats["master_link_status"] { |
| 166 | default: |
| 167 | hc.sstatus[addr] = CodeSyncError |
| 168 | case "up": |
| 169 | hc.sstatus[addr] = CodeSyncReady |
| 170 | case "down": |
| 171 | hc.sstatus[addr] = CodeSyncBroken |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | return hc |
no test coverage detected