Skip to content

Commit

Permalink
lib: implement server metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Koch committed Jun 22, 2023
1 parent 70cb4a8 commit 30c037b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/hcloud/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Server
destructible

has_actions
has_metrics

def enable_rescue(type: 'linux64', ssh_keys: [])
query = COLLECT_ARGS.call(__method__, binding)
Expand Down
2 changes: 2 additions & 0 deletions spec/hcloud/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'support/it_supports_update'
require 'support/it_supports_destroy'
require 'support/it_supports_labels_on_update'
require 'support/it_supports_metrics'
require 'support/it_supports_action_fetch'

RSpec.describe Hcloud::Server, doubles: :server do
Expand All @@ -26,6 +27,7 @@
include_examples 'it_supports_update', described_class, { name: 'new_name' }
include_examples 'it_supports_destroy', described_class
include_examples 'it_supports_labels_on_update', described_class
include_examples 'it_supports_metrics', described_class, %i[cpu disk network]
include_examples 'it_supports_action_fetch', described_class

it 'fetch server' do
Expand Down
4 changes: 4 additions & 0 deletions spec/support/it_supports_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def build_metrics(params)
end: params[:end],
step: step,
time_series: {
# In reality the time series name does not necessarily have to be the same
# as the queried type. E.g. server metrics for the type "network" returns multiple time
# series called "network.0.pps.in", "network.0.pps.out" and so on. But for our unit
# tests returning a single time series is enough at the moment.
params[:type].to_sym => {
# generate a random length list of a few random values
values: Array.new(Faker::Number.within(range: 0..100)).map.with_index do |_, idx|
Expand Down

0 comments on commit 30c037b

Please sign in to comment.