Skip to content

Conversation

@neel5481
Copy link
Contributor

@neel5481 neel5481 commented Sep 3, 2020

User can define the range of database server version where query is to be executed in yml configuration file.

If user want to run the query on database version greater than 10.0.0, use below format.
runonserver: ">=10.0.0"

  Below are the example of db version range user can defined in yml file.
        <=10.1.0
        >=12.1.0
        =11.0.0
        <9.6.0 || >=11.0.0

neel5481 added 2 commits June 15, 2020 18:05
By default query will run on all the databases if "runonserver" is not provided.

If user want the query to be run on multiple database versions, use below string.
  runonserver: "9.5, 9.6"

Example yml file as below. ( e.g. below query will run only on database version 9.5 )

pg_replication:
  query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
  master: true
  runonserver: "9.5"
  metrics:
    - lag:
        usage: "GAUGE"
        description: "Replication lag behind master in seconds"
    Instead of having db version string from yml file, user can define the range of
    database server version where query is to be executed.

    If user want to run the query on database version greater than 10.0.0, use below format.
      runonserver: ">=10.0.0"

      Below are the example of db version range user can defined in yml file.
            <=10.1.0
            >=12.1.0
            =11.0.0
            <9.6.0 || >=11.0.0
@neel5481
Copy link
Contributor Author

@wrouesnel Can you please update what is wrong here ?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 66.051% when pulling c1b5087 on neel5481:master into 301976c on wrouesnel:master.

@wrouesnel wrouesnel merged commit 8531aba into prometheus-community:master Feb 17, 2021
@cobolbaby
Copy link

@neel5481 Have a few questions:

  • How to load the configuration? --extend.query-path?
  • Server.runonserver have nothing to do with metric cycle acquisition
  • Should the UserQuery.RunOnServer be used in parseUserQueries function?

@neel5481
Copy link
Contributor Author

@cobolbaby When user want to execute queries on specific database only to collect metrics, "RunOnServer" will be useful and it will be used along with "PG_EXPORTER_EXTEND_QUERY_PATH" where user defined the queries in yaml file and give to the exporter. You can check detail usage in the commit message.

@cobolbaby
Copy link

@neel5481 After trying and debugging, I found that only the exporter's startup configuration runonserver does work, but the runonserver in the yml file actually had no practical effect.

@cobolbaby
Copy link

// check if the query is to be run on specific database server version range or not
if len(server.runonserver) > 0 {
serVersion, _ := semver.Parse(server.lastMapVersion.String())
runServerRange, _ := semver.ParseRange(server.runonserver)
if !runServerRange(serVersion) {
level.Debug(logger).Log("msg", "Query skipped for this database version", "version", server.lastMapVersion.String(), "target_version", server.runonserver)
continue
}
}

Are you sure that the above logic should be placed in the loop logic?

@neel5481
Copy link
Contributor Author

// check if the query is to be run on specific database server version range or not
if len(server.runonserver) > 0 {
serVersion, _ := semver.Parse(server.lastMapVersion.String())
runServerRange, _ := semver.ParseRange(server.runonserver)
if !runServerRange(serVersion) {
level.Debug(logger).Log("msg", "Query skipped for this database version", "version", server.lastMapVersion.String(), "target_version", server.runonserver)
continue
}
}

Are you sure that the above logic should be placed in the loop logic?

Yes, you are right. Do you have any suggestion where should we add this skip block after reading the actual database version and runonserver given in yaml file, before I debug ?

@neel5481
Copy link
Contributor Author

// check if the query is to be run on specific database server version range or not
if len(server.runonserver) > 0 {
serVersion, _ := semver.Parse(server.lastMapVersion.String())
runServerRange, _ := semver.ParseRange(server.runonserver)
if !runServerRange(serVersion) {
level.Debug(logger).Log("msg", "Query skipped for this database version", "version", server.lastMapVersion.String(), "target_version", server.runonserver)
continue
}
}

Are you sure that the above logic should be placed in the loop logic?

Can you please verify this pull request ?

#509

@cobolbaby
Copy link

cobolbaby commented Mar 30, 2021

LGTM.

In fact, I have already commited #503, but still need to do more for parseUserQueries. Glad you have done such support.

@Kimi450
Copy link

Kimi450 commented Jan 19, 2023

Ah I spent ages thinking something was wrong with my flow through the codebase instead of questioning the codebase :p Thanks for raising this issue, @neel5481 your changes were what I was thinking to do too so thanks for making them. This should be merged ASAP I think @wrouesnel (if you dont mind please)

ritbl pushed a commit to heniek/postgres_exporter that referenced this pull request Mar 19, 2023
…rver version from single yml file (prometheus-community#428)

* Run the query for specific database version if provided from yml file.
By default query will run on all the databases if "runonserver" is not provided.

If user want the query to be run on multiple database versions, use below string.
  runonserver: "9.5, 9.6"

Example yml file as below. ( e.g. below query will run only on database version 9.5 )

pg_replication:
  query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
  master: true
  runonserver: "9.5"
  metrics:
    - lag:
        usage: "GAUGE"
        description: "Replication lag behind master in seconds"

* Fixed the below review comments given by Ashesh Vashi

    Instead of having db version string from yml file, user can define the range of
    database server version where query is to be executed.

    If user want to run the query on database version greater than 10.0.0, use below format.
      runonserver: ">=10.0.0"

      Below are the example of db version range user can defined in yml file.
            <=10.1.0
            >=12.1.0
            =11.0.0
            <9.6.0 || >=11.0.0

* Remove the call from unused places where 'runOnServer' is not required.
Only Server type hold that value.

* Fix compilation issues.

* Fix the issue with Debugln to print the database server version
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 this pull request may close these issues.

5 participants