Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karios db executor #12

Merged
merged 9 commits into from Jun 13, 2017
Merged

Karios db executor #12

merged 9 commits into from Jun 13, 2017

Conversation

vkhatale
Copy link

@vkhatale vkhatale commented Jun 7, 2017

Added kairos db executor to query kairos db api's

Vaishali Khatale added 4 commits May 16, 2017 13:27
…fana model and convert it to kairos api. Also added api's to get the response from kairos metric query rest api and transform it to grafana model.
@ddhirajkumar
Copy link

Please write unit tests for these.

@vkhatale
Copy link
Author

@ddhirajkumar : There is a sperate story to write unit tests for all the go files added as part of kairosdb executor. This will be taken up in next sprint.

Copy link

@ddhirajkumar ddhirajkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make necessary changes wherever applicable

}

func NewKairosdbExecutor(datasource *models.DataSource) (tsdb.Executor, error) {
plog.Info("Inside NewKairosdbExecutor - 0")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vkhatale please remove these if no longer needed. Or convert them to debug logs. Whatever seems appropriate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddhirajkumar : Will change to debug

result := &tsdb.BatchResult{}

kairosdbQuery := NewQueryBuilder()
kairosdbQuery.SetAbsoluteStart(queryContext.TimeRange.MustGetFrom().UTC())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time handling seems to be correct code-wise. But would advise to test with different formats from the UI in Grafana's time range field.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will test this when writing unit tests and also do manual testing to ensure this.

queryRes.Series = append(queryRes.Series, &series)
}
}
queryResults["A"] = queryRes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this hardcoding to "A"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ddhirajkumar : That is how it is done in all other executors. AFAIK it is because there is only one query allowed for alert execution. You can opentsdb.go, influxdb.go, prometheus.go....they all do the same way.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... I digged up a further and found that when Grafana code makes a request to the executor, it refers to the query by the string "A". If interested, you can take a look at pkg/services/alerting/conditions/alerting.go#getRequestForAlertRule() function.


func (e *KairosdbExecutor) createRequest(kairosdbQuery QueryBuilder) (*http.Request, error) {
u, _ := url.Parse(e.Url)
u.Path = path.Join(u.Path, "api/v1/datapoints/query/")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to move the url path to config.ini?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In opentsdb the url path is defined here. I did same thing for Kairosdb. Moreover I don't see seperate sections in ini file to configure datasource specific configurations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't appear to be a reasonable justification. You can add a new section for karios datasource configuration (if it's not already there). Since this is code that we would be releasing to Opensource, would be good to have this as config instead of being hardcoded.

Copy link
Author

@vkhatale vkhatale Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I will create seperate story to put this in config.ini file. Not sure how to add it in ini file. Please merge this for now

return nil, err
}

if res.StatusCode/100 != 2 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this check. Instead of checking for equality with 200.

err = json.Unmarshal(body, queryResponse)

if err != nil {
plog.Info("Failed to unmarshal opentsdb response", "error", err, "status", res.Status, "body", string(body))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in the log: please search for 'opentsb' across all files and replace them with kairosdb

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the log level should be 'error' or 'warning' here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that there is no other place where 'opentsdb' string is used. Changed log level from info to error.

@ddhirajkumar ddhirajkumar merged this pull request into master Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants