فهرست منبع

Added some helpers, and updated status.go

Matt Bolt 5 سال پیش
والد
کامیت
e7f86b96ed
2فایلهای تغییر یافته به همراه26 افزوده شده و 1 حذف شده
  1. 2 0
      pkg/kubecost/status.go
  2. 24 1
      pkg/prom/error.go

+ 2 - 0
pkg/kubecost/status.go

@@ -27,4 +27,6 @@ type FileStatus struct {
 	Size         string            `json:"size"`
 	LastModified time.Time         `json:"lastModified"`
 	Details      map[string]string `json:"details,omitempty"`
+	Errors       []string          `json:"errors,omitempty"`
+	Warnings     []string          `json:"warnings,omitempty"`
 }

+ 24 - 1
pkg/prom/error.go

@@ -54,9 +54,21 @@ func (qw *QueryWarning) String() string {
 
 // QueryErrorCollection represents a collection of query errors and warnings made via context.
 type QueryErrorCollection interface {
-	//
+	// Warnings is a slice of the QueryWarning instances
 	Warnings() []*QueryWarning
+
+	// Errors is a slice of the QueryError instances
 	Errors() []*QueryError
+
+	// ToErrorAndWarningStrings returns the errors and warnings in the collection
+	// as two string slices.
+	ToErrorAndWarningStrings() (errors []string, warnings []string)
+}
+
+// ErrorsAndWarningStrings is a container struct for string representation storage/caching
+type ErrorsAndWarningStrings struct {
+	Errors   []string
+	Warnings []string
 }
 
 // QueryErrorCollector is used to collect prometheus query errors and warnings, and also meets the
@@ -151,6 +163,17 @@ func (ec *QueryErrorCollector) Error() string {
 	return sb.String()
 }
 
+// ToErrorAndWarningStrings returns the errors and warnings in the collection as two string slices.
+func (ec *QueryErrorCollector) ToErrorAndWarningStrings() (errors []string, warnings []string) {
+	for _, e := range ec.Errors() {
+		errors = append(errors, e.String())
+	}
+	for _, w := range ec.Warnings() {
+		warnings = append(warnings, w.String())
+	}
+	return
+}
+
 // As is a special method that implicitly works with the `errors.As()` go
 // helper to locate the _first_ instance of the provided target type in the
 // collection.