forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] pika-exporter: let one exporter monitor the whole cluster (O…
…penAtomFoundation#1929) (OpenAtomFoundation#1953) * let one exporter monitor the whole cluster by codis * Automatically reload after cluster node changes.
- Loading branch information
Showing
5 changed files
with
488 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package discovery | ||
|
||
type CodisServerAction struct { | ||
Action string `json:"action"` | ||
} | ||
|
||
type CodisServerInfo struct { | ||
Server string `json:"server"` | ||
Datacenter string `json:"datacenter"` | ||
ServerAction CodisServerAction `json:"action"` | ||
ServerReplicaGroup bool `json:"replica_group"` | ||
} | ||
|
||
type CodisModelInfo struct { | ||
Id int `json:"id"` | ||
Servers []CodisServerInfo `json:"servers"` | ||
} | ||
|
||
type CodisGroupInfo struct { | ||
Models []CodisModelInfo `json:"models"` | ||
} | ||
|
||
type CodisStatsInfo struct { | ||
Group CodisGroupInfo `json:"group"` | ||
} | ||
|
||
type CodisTopomInfo struct { | ||
Stats CodisStatsInfo `json:"stats"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package discovery | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestNewCodisDiscovery(t *testing.T) { | ||
jsonFile := "mockCodisTopom.json" | ||
jsonData, err := ioutil.ReadFile(jsonFile) | ||
if err != nil { | ||
t.Fatalf("failed to read test data: %v", err) | ||
} | ||
|
||
var result CodisTopomInfo | ||
err = json.Unmarshal(jsonData, &result) | ||
if err != nil { | ||
t.Fatalf("failed to parse test data: %v", err) | ||
} | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
json.NewEncoder(w).Encode(result) | ||
})) | ||
defer ts.Close() | ||
|
||
url := ts.URL | ||
password := "password1,password2" | ||
alias := "" | ||
|
||
discovery, err := NewCodisDiscovery(url, password, alias) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
expectedAddrs := []string{ | ||
"1.1.1.6:1100", | ||
"1.1.1.7:1100", | ||
} | ||
expectedPasswords := []string{ | ||
"password1", | ||
"password2", | ||
} | ||
|
||
if len(discovery.instances) != len(expectedAddrs) { | ||
t.Errorf("expected %d instances but got %d", len(expectedAddrs), len(discovery.instances)) | ||
} | ||
|
||
for i := range expectedAddrs { | ||
if discovery.instances[i].Addr != expectedAddrs[i] { | ||
t.Errorf("instance %d address: expected %s but got %s", i, expectedAddrs[i], discovery.instances[i].Addr) | ||
} | ||
if discovery.instances[i].Password != expectedPasswords[i] { | ||
t.Errorf("instance %d password: expected %s but got %s", i, expectedPasswords[i], discovery.instances[i].Password) | ||
} | ||
} | ||
} |
Oops, something went wrong.