Skip to content

Commit

Permalink
Merge pull request #153 from K-Phoen/prometheus-exemplars
Browse files Browse the repository at this point in the history
Support definition of exemplars on Prometheus datasources
  • Loading branch information
K-Phoen authored Dec 25, 2021
2 parents aeb936a + f957eef commit 277967b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datasource/prometheus/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ func ForwardCookies(cookies ...string) Option {
datasource.builder.JSONData.(map[string]interface{})["keepCookies"] = cookies
}
}

// Exemplars configures a list of exemplars on this datasource.
func Exemplars(exemplars ...Exemplar) Option {
return func(datasource *Prometheus) {
datasource.builder.JSONData.(map[string]interface{})["exemplarTraceIdDestinations"] = exemplars
}
}
13 changes: 13 additions & 0 deletions datasource/prometheus/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,16 @@ func TestForwardCookies(t *testing.T) {

req.ElementsMatch([]string{"foo", "bar"}, datasource.builder.JSONData.(map[string]interface{})["keepCookies"])
}

func TestExemplars(t *testing.T) {
req := require.New(t)

traceIDExemplar := Exemplar{
LabelName: "traceID",
DatasourceUID: "tempo",
}

datasource := New("", "", Exemplars(traceIDExemplar))

req.ElementsMatch([]Exemplar{traceIDExemplar}, datasource.builder.JSONData.(map[string]interface{})["exemplarTraceIdDestinations"])
}
13 changes: 13 additions & 0 deletions datasource/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import (

var _ datasource.Datasource = Prometheus{}

type Exemplar struct {
// The name of the field in the labels object that should be used to get the traceID.
LabelName string `json:"name"`

// The data source the exemplar is going to navigate to.
// Set this value for internal exemplar links.
DatasourceUID string `json:"datasourceUid"`

// The URL of the trace backend the user would go to see its trace.
// Set this value for external exemplar links.
URL string `json:"url,omitempty"`
}

type Prometheus struct {
builder *sdk.Datasource
}
Expand Down

0 comments on commit 277967b

Please sign in to comment.