diff --git a/pkg/datasource/models.go b/pkg/datasource/models.go index b866eae..9b50cfd 100644 --- a/pkg/datasource/models.go +++ b/pkg/datasource/models.go @@ -53,7 +53,11 @@ type QueryModel struct { Options QueryOptions `json:"options"` // Direct from the gRPC interfaces - TimeRange backend.TimeRange `json:"-"` + RefID string `json:"-"` + QueryType string `json:"-"` + TimeRange backend.TimeRange `json:"-"` + MaxDataPoints int64 `json:"-"` + Interval time.Duration `json:"-"` } // QueryOptions model @@ -91,11 +95,16 @@ type QueryFunctionParam = interface{} // ReadQuery will read and validate Settings from the DataSourceConfg func ReadQuery(query backend.DataQuery) (QueryModel, error) { - model := QueryModel{} + model := QueryModel{ + RefID: query.RefID, + QueryType: query.QueryType, + TimeRange: query.TimeRange, + MaxDataPoints: query.MaxDataPoints, + Interval: query.Interval, + } if err := json.Unmarshal(query.JSON, &model); err != nil { return model, fmt.Errorf("could not read query: %w", err) } - model.TimeRange = query.TimeRange return model, nil } diff --git a/pkg/datasource/zabbix.go b/pkg/datasource/zabbix.go index 0893d27..d6a547b 100644 --- a/pkg/datasource/zabbix.go +++ b/pkg/datasource/zabbix.go @@ -94,6 +94,21 @@ func (ds *ZabbixDatasourceInstance) queryNumericDataForItems(ctx context.Context return nil, err } + for _, s := range series { + if int64(s.Len()) > query.MaxDataPoints && true { + downsampleFunc := consolidateBy + if downsampleFunc == "" { + downsampleFunc = "avg" + } + downsampled, err := applyGroupBy(s.TS, query.Interval.String(), downsampleFunc) + if err == nil { + s.TS = downsampled + } else { + ds.logger.Debug("Error downsampling series", "error", err) + } + } + } + frames := convertTimeSeriesToDataFrames(series) return frames, nil }