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

MS SQL db Metricset (main PR) #9414

Merged
merged 12 commits into from
Dec 27, 2018

Conversation

sayden
Copy link
Contributor

@sayden sayden commented Dec 6, 2018

Main PR suffix refers to the fact that this PR contains the first metricset plus the sql engine to do the queries concurrently. It's expected that follow PR with new metricset just contains the queries to fetch the telemetry information.

Continuation of #9202 which grouped 4 different metricsets.

This is the single db metricset to facilitate reviewing.

db metricset is a subset of some of the most relevant information you can find here.

The way it has to work is: the metricset has the SQL queries it needs to get the information from the DB. Queries are sent to a central engine created for each metricset in x-pack/metricbeat/module/mssql which run them, returning the results so that they can be reported. io.Closer is implemented on the engine to close the db connection and in the metricset.

GA

  • Supported versions are documented
  • Supported operating systems are documented (if applicable)
  • Integration tests
  • System tests
  • Automated checks that all fields are documented
  • Documentation
  • Example data.json exists and an automated way to generate it exists (go test -data)
  • Fields follow naming conventions: https://www.elastic.co/guide/en/beats/devguide/master/event-conventions.html
  • Dashboards exists (if applicable)
  • Kibana Home Tutorial (if applicable)

@sayden sayden added module Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Dec 6, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/infrastructure

@ruflin
Copy link
Member

ruflin commented Dec 6, 2018

It's up to you to make sure the connections are properly closed. Best check the mysql metricset on how it's done there.

@sayden sayden mentioned this pull request Dec 6, 2018
33 tasks
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

Only skimmed through the code and left some high level comments. Overall looks good 👍

NOTICE.txt Show resolved Hide resolved
x-pack/metricbeat/module/mssql/_meta/Dockerfile Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/_meta/fields.yml Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/doc.go Show resolved Hide resolved
x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
@sayden sayden added the in progress Pull request is currently in progress. label Dec 11, 2018
@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 7fbd115 to 2ec8561 Compare December 11, 2018 21:17
- module: mssql
metricsets:
- "db"
hosts: ["sqlserver://sa@localhost"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: sa is the common name for system administrator in MS SQL

@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from c85e4bd to 3a9d5d6 Compare December 12, 2018 08:38
@sayden sayden added review and removed in progress Pull request is currently in progress. labels Dec 12, 2018
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

This is looking good 👍 Only some small comments.

x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
x-pack/metricbeat/docker-compose.yml Show resolved Hide resolved
x-pack/metricbeat/module/mssql/db/_meta/fields.yml Outdated Show resolved Hide resolved
fields:
- name: database
type: group
description: Database metricset
Copy link
Member

Choose a reason for hiding this comment

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

Should this be the description of the db group?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, actually not but just after your comment I thought for a second that you were right 😄 Many along different metricsets returns id's of databases and this group is specifically tailored to share this names between metricsets. This was actually some suggestion from you on one of the old PR.

What you make me doubt now is if the database group field should be place at the module level. But I actually don't know very well how this actually works. I mean, how do I apply the common eventMapping function of the data.go files to generate a field / group that belongs to the module? I thought that all event mapping produce there is automatically a subchild of the module group.

Copy link
Member

@jsoriano jsoriano Dec 13, 2018

Choose a reason for hiding this comment

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

My comment here was only about their descriptions, I don't understand why db.database description is "Database metricset" and the one for db is "db". I'd say that db description should say something about the metricset metrics, and db.database something about database info, or just be empty.

Regarding organization, if database is going to be shared between metricsets as I think I suggested in some of the other PRs then yes, this should be placed at the module level, so the id is in mssql.database.id.

Notice that after applying an schema you can still modify the events before publishing them.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @jsoriano that as soon as we see more metricsets, we potentially should redicuss how we organise the fields and which ones are on the module level.

Copy link
Member

Choose a reason for hiding this comment

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

@sayden I think these descriptions should be fixed on this PR

x-pack/metricbeat/module/mssql/db/_meta/fields.yml Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/db/db_integration_test.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/db/db.go Show resolved Hide resolved
x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
@sayden
Copy link
Contributor Author

sayden commented Dec 12, 2018

Waiting this #9509 to merge before rebasing and try again

@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 6296a44 to 4820504 Compare December 13, 2018 07:13
@sayden
Copy link
Contributor Author

sayden commented Dec 13, 2018

jenkins, test this

@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 4820504 to 1c8107e Compare December 13, 2018 09:33
@sayden
Copy link
Contributor Author

sayden commented Dec 13, 2018

Rebased over #9509

@sayden
Copy link
Contributor Author

sayden commented Dec 13, 2018

jenkins, test this

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

I'm missing 2 things:

  • An integration tests that can generated the data.json + the generated data.json as we use this in the docs
  • A (system)test that checks that all fields are documented which we used.

x-pack/metricbeat/module/mssql/_meta/docs.asciidoc Outdated Show resolved Hide resolved
@@ -0,0 +1 @@
This is the db metricset of the module mssql.
Copy link
Member

Choose a reason for hiding this comment

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

Should we add some more details here on what metrics are fetched?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can but it's going to be redundant with the in fields.yml, right? I want to be sure that you mean that information

Copy link
Member

Choose a reason for hiding this comment

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

Yes. I should rephrase this to not necessarly about the metrics but that it describes it fetches metrics about DB and also potentially links to MSSQL docs where these metrics are. We can do this in a follow up.

fields:
- name: database
type: group
description: Database metricset
Copy link
Member

Choose a reason for hiding this comment

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

Agree with @jsoriano that as soon as we see more metricsets, we potentially should redicuss how we organise the fields and which ones are on the module level.

x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/fetcher.go Show resolved Hide resolved
}
defer func() {
if err = rows.Close(); err != nil {
logp.Error(errors.Wrap(err, "error closing query row"))
Copy link
Member

Choose a reason for hiding this comment

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

Could we use a name return value here instead so we don't have to log it and still get the error reported as return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Good catch! Because I was actually ofuscating err from any of the other calls in case of an error here. So, as far as I can see it could be done like this (but it's ugly as hell):

func (f *Fetcher) getEventsWithQuery(db *sql.DB, query string, reporter mb.ReporterV2) (err error) {
	var rows *sql.Rows
	rows, err = db.Query(query)
	if err != nil {
		return errors.Wrapf(err, "error performing db query='%v'", query)
	}
	defer func() {
		if err2 := rows.Close(); err != nil {
			if err != nil {
				err = errors.Wrap(err, err2.Error())
			} else {
				err = err2
			}
		}
	}()

@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 1c8107e to 1a1eae8 Compare December 20, 2018 11:38
@sayden sayden requested a review from a team as a code owner December 20, 2018 11:38
@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 0742f39 to 43acd7e Compare December 20, 2018 17:47
err = err2
}
}
}()
Copy link
Member

@jsoriano jsoriano Dec 21, 2018

Choose a reason for hiding this comment

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

Sorry, but as you said this is actually a bit ugly 😬 Also according to documentation rows are closed automatically by Next, so this should only be needed if the Scan/Next loop is unexpectedly interrupted (having rows creation and the Scan/Next loop in the same place would be another reason in favour of this proposal).

Also for better or worse it is quite usual to ignore the error on calls to Close(), even in the examples in the documentation for the sql module... I think we'd be fine with reducing this to defer Close(), or at much log this error at the debug level, because an error here is probably very very rare.

I'd change it here, but we will have to revisit this code in any case, so as you prefer... but if you keep this here, please at least use a more meaningful name for the inner error, like closeErr.

Copy link
Contributor Author

@sayden sayden Dec 21, 2018

Choose a reason for hiding this comment

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

I think we should not block this PR with more stylish and subjective things.

Very very rare errors that are hidden on purpose leads to a very very difficult to debug, discover and fix bugs so also very very difficult to maintain. That's why I prefer explicit approaches (say ugly if you want) Than just to obfuscate the error.

So please, if you don't mind, let's move this PR forward because it has been hanging for months already, it has 81 comments and there's still has a lot of work to do with the upcoming metricsets that will need a lot of review in many aspects.

Copy link
Member

Choose a reason for hiding this comment

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

I think the problem is that code that gets merge gets rarely changed again. My main issue with the above is that when I read the code, I don't really understand what it's doing above.

To keep this moving the following suggestion: Please add it to the module meta issue as an entry that has to be looked at again so we don't forget about the cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy with any proposal that doesn't involve a function with 4 or 5 responsibilities 🥇 In any case, I already have some notes for the next PR that I'm planning to write in the header of the upcoming metricset PR once it's open. I already have to change few stylish things also in this particular file so we have time to discuss a way that is easy for everybody to understand / look 😄

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

LGTM. Let's move forward with this. I think it will still need some follow up work like for the fields description or docs but we are good to move forward here.

Lets wait on CI to go green(-ish).

@sayden One other cleanup thing we must do after merging this is remove the "example" module as we will not need it anymore.

@sayden
Copy link
Contributor Author

sayden commented Dec 24, 2018

The follow up actions of this PR are in this meta-issue about the entire module #8698 including the docs reviewing, the sql row close action error handling

@sayden
Copy link
Contributor Author

sayden commented Dec 24, 2018

jenkins, test this please

@sayden
Copy link
Contributor Author

sayden commented Dec 24, 2018

Trying to figure out what's the Travis error of cat: build/TEST-go-integration.out: No such file or directory

@sayden sayden force-pushed the feature/xp/mb/mssql-db-metricset branch from 4d4623d to 85dbeab Compare December 24, 2018 13:21
@sayden
Copy link
Contributor Author

sayden commented Dec 24, 2018

jenkins, test this please

1 similar comment
@sayden
Copy link
Contributor Author

sayden commented Dec 24, 2018

jenkins, test this please

@ruflin
Copy link
Member

ruflin commented Dec 27, 2018

@sayden Failures on CI are not related.

@sayden sayden merged commit 4966017 into elastic:master Dec 27, 2018
sayden added a commit to sayden/beats that referenced this pull request Dec 27, 2018
New MS SQL Metricbeat module with a single `db` Metricset which fetches information about the space usage of each database log. This PR is the seed to continue evolving this metricset and add new ones.

Includes system tests and integration tests, a data.json generated file and documentation
@sayden sayden added the v6.7.0 label Dec 27, 2018
@sayden sayden mentioned this pull request Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat module review Team:Integrations Label for the Integrations team v6.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants