Author: Paolo Lulli <paolo@lulli.net>
Remove hardcoded max page size
client/main.go | 78 ++++++++++++++++++++++++++-------------------------
diff --git a/client/main.go b/client/main.go
index 20e68222d7fdb6a134f78ca7cc8a59d48f971060..1397a849309c42c5365854250f31d0edc43ebd75 100644
--- a/client/main.go
+++ b/client/main.go
@@ -26,6 +26,8 @@ type YatsClient struct {
config config.ClientConfiguration
}
+var MaxPageSize = 100
+
func main() {
var configPath string
recordSeparator := ","
@@ -166,7 +168,7 @@ eventListModel, maxpage, _ := responseToEventArray(listEvents)
var composedList []EventModel
composedList = append(composedList, eventListModel...)
- for (len(eventListModel) == 100) && !stopSearching(maxpage, toTimestamp) {
+ for (len(eventListModel) == MaxPageSize) && !stopSearching(maxpage, toTimestamp) {
listEvents = yatsClient.EventList(*sourceOption, maxpage/1000, toTimestamp)
eventListModel, maxpage, _ = responseToEventArray(listEvents)
composedList = append(composedList, eventListModel...)
@@ -185,50 +187,54 @@ }
if "" != *listMetrics {
listResponse, err := yatsClient.MetricList(*sourceOption, *listMetrics, fromTimestamp, toTimestamp)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
metricListModel, maxpage, _ := responseToMetricArray(listResponse)
var composedList []MetricModel
composedList = append(composedList, metricListModel...)
- for (len(metricListModel) == 100) && !stopSearching(maxpage, toTimestamp) {
+ for (len(metricListModel) == MaxPageSize) && !stopSearching(maxpage, toTimestamp) {
listResponse, _ = yatsClient.MetricList(*sourceOption, *listMetrics, maxpage/1000, toTimestamp)
metricListModel, maxpage, _ = responseToMetricArray(listResponse)
composedList = append(composedList, metricListModel...)
}
- if err == nil {
- if *reformatOutput {
- if err == nil {
- for _, metric := range composedList {
- fmt.Printf("%d %s=%s\n", metric.Mtime, metric.Name, metric.Value)
- }
- } else {
- fmt.Println(err)
+ if *reformatOutput {
+ if err == nil {
+ for _, metric := range composedList {
+ fmt.Printf("%d %s=%s\n", metric.Mtime, metric.Name, metric.Value)
}
- os.Exit(0)
+ } else {
+ fmt.Println(err)
}
- if *logOutput {
- if err == nil {
- for _, metric := range composedList {
- if *decodeBase64Output {
- decodedBytes, err := base64.StdEncoding.DecodeString(metric.Value)
- if err != nil {
- fmt.Println("Error decoding string:", err)
- return
- }
- fmt.Println(string(decodedBytes))
- } else {
- fmt.Printf("%s\n", metric.Value)
+ os.Exit(0)
+ }
+ if *logOutput {
+ if err == nil {
+ for _, metric := range composedList {
+ if *decodeBase64Output {
+ decodedBytes, err := base64.StdEncoding.DecodeString(metric.Value)
+ if err != nil {
+ fmt.Println("Error decoding string:", err)
+ return
}
+ fmt.Println(string(decodedBytes))
+ } else {
+ fmt.Printf("%s\n", metric.Value)
}
- } else {
- fmt.Println(err)
}
- os.Exit(0)
+ } else {
+ fmt.Println(err)
}
+ os.Exit(0)
+ }
- if *unpackJsonPayload {
- if err == nil {
- metric := composedList[0]
+ if *unpackJsonPayload {
+ if err == nil {
+ for _, metric := range composedList {
dataMap, errNoValue := mapFromBase64(metric.Value)
if errNoValue {
return
@@ -243,7 +249,6 @@
for _, k := range keys {
fmt.Printf("\"%s\"%s", k, recordSeparator)
}
- //fmt.Printf("%s", rowSeparator)
for _, row := range composedList {
rowMap, errNoValue := mapFromBase64(row.Value)
if errNoValue {
@@ -258,17 +263,14 @@ fmt.Printf("%s\"%v\"", recordSeparator, rowMap[k])
}
fmt.Printf("%s", rowSeparator)
}
- } else {
- fmt.Println(err)
}
- os.Exit(0)
+ } else {
+ fmt.Println(err)
}
+ os.Exit(0)
+ }
- fmt.Printf("%s", listResponse)
-
- } else {
- fmt.Println(err)
- }
+ fmt.Printf("%s", listResponse)
os.Exit(0)
}