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

munin: add a check for existing PID files #1363

Merged
merged 25 commits into from
May 30, 2022
Merged

munin: add a check for existing PID files #1363

merged 25 commits into from
May 30, 2022

Conversation

komainu8
Copy link
Member

@komainu8 komainu8 commented May 27, 2022

Because protocols that have not exist PID files are invalid.

The result of execution is the following.

$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | http                                   
groonga_cpu_time_          | yes  | http                                   
groonga_disk_              | yes  | http                                   
groonga_memory_            | yes  | http                                   
groonga_n_records_         | yes  | http                                   
groonga_query_performance_ | yes  | http                                   
groonga_status_            | yes  | http                                   
groonga_throughput_        | yes  | http             

Comment on lines 193 to 197
pid_file_exist = false
pid_paths.each do |pid_path|
next unless File.exist?(pid_path)
pid_file_exist = true
end
Copy link
Member

Choose a reason for hiding this comment

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

We can return false here when no PID file exist.

Copy link
Member

Choose a reason for hiding this comment

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

We need similar check in suggest too. If http_pid_path doesn't exist, suggest doesn't print http. Without similar check, suggest will print http when http://127.0.0.1/d/... is accesible by groonga-httpd not groonga --protocol http.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for your coments.
I've fixed them at aecf24d.

@komainu8 komainu8 marked this pull request as ready for review May 29, 2022 14:54
data/munin/groonga_disk_ Outdated Show resolved Hide resolved
@@ -146,18 +146,21 @@ end
def setup_http
@http_host = ENV["http_host"] || @default_host
@http_port = (ENV["http_port"] || @default_http_port).to_i
@http_pid_path = File.exist?(ENV["http_pid_path"]) || nil
Copy link
Member

Choose a reason for hiding this comment

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

File.exist?(ENV["http_pid_path"]) isn't a PID path. How about @http_running = File.exist?(ENV["http_pid_path"]) or something?

BTW, can we use /run/groonga/groonga-http.pid as the default PID path?

Copy link
Member Author

Choose a reason for hiding this comment

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

What does BTW, can we use /run/groonga/groonga-http.pid as the default PID path? mean?
Sorry, I don't understand this.

Copy link
Member

Choose a reason for hiding this comment

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

http_hosthttp_portみたいにデフォルト値を設定できませんか?
この変更が入ると必ずPIDパスを設定しないと動きませんが、適切なデフォルト値があれば以前のように設定なしでも(デフォルトの設定のままgroonga --protocol http -sを使っていれば)動く気がします。

@@ -169,7 +172,39 @@ def setup
setup_gqtp
end

def pid_files_esists?
Copy link
Member

Choose a reason for hiding this comment

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

We should use exist? not exists? like File.exist?. (File.exists? is deprecated.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh.. I see.

Comment on lines 177 to 178
"pid_path",
"pid_file", # For backward compatibility. Remove me when 5.0.0.
Copy link
Member

Choose a reason for hiding this comment

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

If we support them, setup_XXX should also support them.

Comment on lines 206 to 207
exit(false) unless pid_files_esists?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

Can we check @http_running instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is needless.
I've deleted this.

Comment on lines 240 to 241
exit(false) unless pid_files_esists?

Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is needless.
I've deleted this.

@komainu8
Copy link
Member Author

Thank you for your comment. I've fixed them.

data/munin/groonga_disk_ Outdated Show resolved Hide resolved
data/munin/groonga_n_records_ Outdated Show resolved Hide resolved
@@ -10,7 +10,39 @@ label = ENV["label"]

command = ARGV.shift

def pid_files_esists?
Copy link
Member

Choose a reason for hiding this comment

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

We need to update this file too.

@komainu8
Copy link
Member Author

Thank you for your comment. I've fixed them.

def autoconf
exit(false) unless (@http_running or @httpd_running or @gqtp_running)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah... This is needless.
I've removed it.

@@ -46,13 +56,13 @@ def suggest
query_log_path = ENV[variable_name]
query_log_path and File.exist?(query_log_path)
end
if exist_p.call("http_query_log_path")
if exist_p.call("http_query_log_path") and @http_running
Copy link
Member

Choose a reason for hiding this comment

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

How about using the same implementation in data/munin/groonga_disk_?

@komainu8
Copy link
Member Author

Thank you for your comments.
I've fixed them.

Comment on lines 17 to 20
@http_running = File.exist?(ENV["http_pid_path"] || @default_http_pid_path)
@httpd_running = File.exist?(ENV["httpd_pid_path"] || @default_httpd_pid_path)
@gqtp_running = File.exist?(ENV["gqtp_pid_path"] || @default_gqtp_pid_path)

Copy link
Member

Choose a reason for hiding this comment

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

Can we remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed them.

Comment on lines 13 to 15
@default_http_pid_path = "/run/groonga/groonga-http.pid"
@default_httpd_pid_path = "/run/groonga/groonga-httpd.pid"
@default_gqtp_pid_path = "/run/groonga/groonga-gptp.pid"
Copy link
Member

Choose a reason for hiding this comment

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

Can we use them?

@komainu8
Copy link
Member Author

Thank you for your comments.
I've fixed them.

database_path = ENV[variable_name]
database_path and File.exist?(database_path)
exist_p = lambda do |database_path_name, pid_file_path_name|
File.exist?(ENV[database_path_name]) and File.exist?(ENV[pid_file_path_name])
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this will raise an error when it's not specified:

$ ruby -e 'File.exist?(nil)'
-e:1:in `exist?': no implicit conversion of nil into String (TypeError)
	from -e:1:in `<main>'

Comment on lines 160 to 167
exist_p = lambda do |database_path_name, pid_file_path_name|
database_path = ENV[database_path_name]
pid_file_path = ENV[pid_file_path_name]

(database_path and File.exist?(ENV[database_path_name])) and (pid_file_path and File.exist?(ENV[pid_file_path_name]))
end
Copy link
Member

Choose a reason for hiding this comment

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

How about creating a helper lambda?

env_path_exist_p = lambda do |variable_name|
  path = ENV[variable_name]
  path and File.exist?(path)
end
exist_p = lambda do |database_path_name, pid_file_path_name|
  env_path_exist_p.call(database_path_name) and
    env_path_exist_p.call(pid_file_path_name)
end

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

We can merge this once we confirm all patterns by hand. (We don't have tests for this yet.)

komainu8 and others added 17 commits May 30, 2022 17:08
Because protocols that have not exist PID files are invalid.
Because these block variables are not the path itself. They are variable names.

Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Because "File.exist?(ENV["http_pid_path"])" isn't a PID path.
Because "File.exist?(ENV["http_pid_path"])" isn't a PID path.
We can check @http_running and @httpd_running and, @gqtp_running instead.
Because if default values for the PID path don't exist, these plugins
don't work.
If default values for the PID path exist, these plugins work without
setting the PID path.
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
We can check @http_running and @httpd_running and, @gqtp_running instead.
@komainu8
Copy link
Member Author

  • Use groonga-server-http
$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | http                                   
groonga_cpu_time_          | yes  | http                                   
groonga_disk_              | yes  | http                                   
groonga_memory_            | yes  | http                                   
groonga_n_records_         | yes  | http                                   
groonga_query_performance_ | yes  | http                                   
groonga_status_            | yes  | http                                   
groonga_throughput_        | yes  | http         

@komainu8
Copy link
Member Author

  • Use groonga-httpd
$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | httpd                                  
groonga_cpu_time_          | yes  | httpd                                  
groonga_disk_              | yes  | httpd                                  
groonga_memory_            | yes  | httpd                                  
groonga_n_records_         | yes  | httpd                                  
groonga_query_performance_ | yes  | httpd                                  
groonga_status_            | yes  | httpd                                  
groonga_throughput_        | yes  | httpd              

@komainu8
Copy link
Member Author

  • Use gqtp
$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | gqtp                                   
groonga_cpu_time_          | yes  | gqtp                                   
groonga_disk_              | yes  | gqtp                                   
groonga_memory_            | yes  | gqtp                                   
groonga_n_records_         | yes  | gqtp                                   
groonga_query_performance_ | yes  | gqtp                                   
groonga_status_            | yes  | gqtp                                   
groonga_throughput_        | yes  | gqtp                            

@komainu8
Copy link
Member Author

  • Use groonga-httpd and groonga-gqtp
$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | gqtp httpd                             
groonga_cpu_time_          | yes  | gqtp httpd                             
groonga_disk_              | yes  | gqtp httpd                             
groonga_memory_            | yes  | gqtp httpd                             
groonga_n_records_         | yes  | gqtp httpd                             
groonga_query_performance_ | yes  | gqtp httpd                             
groonga_status_            | yes  | gqtp httpd                             
groonga_throughput_        | yes  | gqtp httpd             
  • Use groonga-server-http and groonga-gqtp
$ sudo munin-node-configure |grep groonga
groonga_cpu_load_          | yes  | gqtp http                              
groonga_cpu_time_          | yes  | gqtp http                              
groonga_disk_              | yes  | gqtp http                              
groonga_memory_            | yes  | gqtp http                              
groonga_n_records_         | yes  | gqtp http                              
groonga_query_performance_ | yes  | gqtp http                              
groonga_status_            | yes  | gqtp http                              
groonga_throughput_        | yes  | gqtp http                  

@komainu8
Copy link
Member Author

We have confirmed all patterns by hand.

@kou kou merged commit 2182721 into master May 30, 2022
@kou kou deleted the detect-pid-file branch May 30, 2022 08:57
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.

None yet

2 participants