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

mysql_user: get full mysql version string as a variable #114

Closed
rndmh3ro opened this issue Mar 11, 2021 · 10 comments · Fixed by #115
Closed

mysql_user: get full mysql version string as a variable #114

rndmh3ro opened this issue Mar 11, 2021 · 10 comments · Fixed by #115

Comments

@rndmh3ro
Copy link
Contributor

SUMMARY

Right now if you use mysql_info to get the version of the database, you get back a dict with three items for the major, minor and release version. However it's hard to use this variable in a version-comparison (e.g. when: mysql_version is version('5.6', '>=')), because you first have to construct a new variable from the dict.

Therefore I propose to add a new variable (e.g. full_mysql_version) that contains the full version string.

One open question for me: would this be a new filter or should this new variable be returned in the version-filter?

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

mysql_info

ADDITIONAL INFORMATION

Sample code:

    def __get_global_variables(self):
        """Get global variables (instance settings)."""
        res = self.__exec_sql('SHOW GLOBAL VARIABLES')

        if res:
            for var in res:
                self.info['settings'][var['Variable_name']] = self.__convert(var['Value'])

            ver = self.info['settings']['version'].split('.')
            release = ver[2].split('-')[0]

            self.info['version'] = dict(
                major=int(ver[0]),
                minor=int(ver[1]),
                release=int(release),
            )

+            self.info['full_version']  = self.info['settings']['version']
@Andersson007
Copy link
Collaborator

@rndmh3ro hi, thanks for the issue!
I like the idea, sounds sensible!
I suggest naming it maybe like raw_mysq_version?
Would you like to implement it yourself or i could?

@Andersson007
Copy link
Collaborator

oh, sorry, "full_version" is OK!

@Andersson007
Copy link
Collaborator

One open question for me: would this be a new filter or should this new variable be returned in the version-filter?

@rndmh3ro I think we could add this to version, e.g.:

            self.info['version'] = dict(
                major=int(ver[0]),
                minor=int(ver[1]),
                release=int(release),
                full_version='...',
            )

@rndmh3ro
Copy link
Contributor Author

rndmh3ro commented Mar 11, 2021

I'll try to implement it.
I'll use as a new filter full_version and return raw_mysql_version? Or should have both the filter and the variable the same name?

I like that as you suggested:

            self.info['version'] = dict(
                major=int(ver[0]),
                minor=int(ver[1]),
                release=int(release),
                full_version='...',
            )```

@Andersson007
Copy link
Collaborator

Andersson007 commented Mar 11, 2021

@rndmh3ro cool, thanks!
And i don't remember (i have no instance of mysql right now) whether it always contains mariadb / mysql in it? I think it does.
If yes, we could put a key with it to the dict as well but i'm not sure how to name it.

@Andersson007
Copy link
Collaborator

(@rndmh3ro don't forget to add a check to tests/integration/targets/test_mysql_info)

@Andersson007
Copy link
Collaborator

(and feel free to add yourself to authors:)

@Andersson007
Copy link
Collaborator

So, i think we should also put in the dict a key, say called type:, containing mariadb or mysql (i.e. what is before - in a version string)

@rndmh3ro
Copy link
Contributor Author

So, i think we should also put in the dict a key, say called type:, containing mariadb or mysql (i.e. what is before - in a version string)

I'll add that, however it's not always mariadb or mysql. Maybe call the variable simply suffix?

        
MariaDB [(none)]> select version();
+----------------+
| version()      |
+----------------+
| 5.5.68-MariaDB |


mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.33-0ubuntu0.18.04.1 |
+-------------------------+

@Andersson007
Copy link
Collaborator

@rndmh3ro ah, thanks, i mixed up the format with postgresql. Yeah, suffix sounds good to me, I'm sure it can be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants