Skip to content

Commit

Permalink
GOCBC-631: Add Metrics to QueryOptions
Browse files Browse the repository at this point in the history
Motivation
----------
We now disable metrics by default so we need an option to
enable them.

Changes
-------
Add Metrics to QueryOptions. Make Metrics optional on the
metadata for query result.
Change-Id: I0c3cff36d3c254763122a5258b5009726064b4a9
Reviewed-on: http://review.couchbase.org/115659
Reviewed-by: Mike Goldsmith <goldsmith.mike@gmail.com>
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
chvck committed Oct 1, 2019
1 parent 3d037f3 commit fc3f3d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cluster_query.go
Expand Up @@ -59,7 +59,7 @@ type QueryMetrics struct {
type QueryMetadata struct {
requestID string
clientContextID string
metrics QueryMetrics
metrics *QueryMetrics
signature interface{}
warnings []QueryWarning
sourceAddr string
Expand Down Expand Up @@ -186,7 +186,7 @@ func (r *QueryMetadata) ClientContextID() string {
}

// Metrics returns metrics about execution of this result.
func (r *QueryMetadata) Metrics() QueryMetrics {
func (r *QueryMetadata) Metrics() *QueryMetrics {
return r.metrics
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func (r *QueryResult) readAttribute(decoder *json.Decoder, t json.Token) (bool,
logDebugf("Failed to parse execution time duration (%s)", err)
}

r.metadata.metrics = QueryMetrics{
r.metadata.metrics = &QueryMetrics{
ElapsedTime: elapsedTime,
ExecutionTime: executionTime,
ResultCount: metrics.ResultCount,
Expand Down
1 change: 1 addition & 0 deletions cluster_query_test.go
Expand Up @@ -393,6 +393,7 @@ func TestBasicQuery(t *testing.T) {

queryOptions := &QueryOptions{
PositionalParameters: []interface{}{"brewery"},
Metrics: true,
}

statement := "select `beer-sample`.* from `beer-sample` WHERE `type` = ? ORDER BY brewery_id, name"
Expand Down
6 changes: 6 additions & 0 deletions queryoptions.go
Expand Up @@ -51,6 +51,8 @@ type QueryOptions struct {
NamedParameters map[string]interface{}
// Custom allows specifying custom query options.
Custom map[string]interface{}
// Metrics specifies whether or not to fetch metrics when executing the query.
Metrics bool

// JSONSerializer is used to deserialize each row in the result. This should be a JSON deserializer as results are JSON.
// NOTE: if not set then query will always default to DefaultJSONSerializer.
Expand Down Expand Up @@ -128,6 +130,10 @@ func (opts *QueryOptions) toMap(statement string) (map[string]interface{}, error
}
}

if !opts.Metrics {
execOpts["metrics"] = false
}

if opts.ClientContextID == "" {
execOpts["client_context_id"] = uuid.New()
} else {
Expand Down

0 comments on commit fc3f3d8

Please sign in to comment.