jcf 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dc40224058bf16a626b143c430840d71b08e7c40c2075cc4bb37792fd2c578c
4
- data.tar.gz: 170d182549a2b12db87edcf56fb6d8303614c7b7a6448ee45fa81b08ea48e9fe
3
+ metadata.gz: f9477e6264cb699c3505cfe016acb802bff09e9c71fe98072ea9a1598a021119
4
+ data.tar.gz: 05a70e89d7593faa6308a6d0b78d03a3990466dae549a8343625288bf104a4ea
5
5
  SHA512:
6
- metadata.gz: 0616d831613106555a42498d7b578675e72187deac999d92ea460458c3ae345f18b1439429bd354d03e0b9dd8e265c388e7170e6bf21ae344fe13966076f39f7
7
- data.tar.gz: bf2190ff13ffcfe11195d7bc03f6a5c6b652e9aa3019d2973ef1b4fba6db1abe5c923191444ecae17a3ccb5e1b09b3d0112e60427b40f8438f9151b2c2c53f7c
6
+ metadata.gz: ec4fa652bb3341babc362145fe150e9418944e3b5c2d5aeb2b798c7d82af39849a3c467b1432941638a9c4b0650f468b56c537e927c4ab5b7793884faf31e491
7
+ data.tar.gz: 25bad72e4df60a12ef1df353abb6472e9db88623f9a4c7ebcd1e4150222bb92c4a2a63684582c9b5758eec353bdcab263b59cfdd67e259aeb42be071f9691827
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [Unreleased]
1
+ ## [0.0.10] - 2023-10-03
2
+
3
+ - Added the template parsing options to metrics command
4
+ This allows you to specify the AWS instance name with a template, and
5
+ then supply the values to fill in the template with the --values flag.
6
+ This makes metrics available to everyone, maybe.
7
+
2
8
  ## [0.0.9] - 2023-10-02
3
9
 
4
10
  - Automatically increase table width for wide tables
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  ![tests](https://github.com/fearoffish/paas-org-metric-gathering-gem/actions/workflows/main.yml/badge.svg)
2
+ [![Gem Version](https://badge.fury.io/rb/jcf.svg)](https://badge.fury.io/rb/jcf)
2
3
 
3
4
  # Jcf
4
5
 
5
6
  ## Installation
6
7
 
7
- Currently this gem is not available on rubygems.org so you will need to build it yourself. A convenience rake task has been included:
8
+ ```sh
9
+ gem install jcf
10
+ ```
11
+
12
+ A convenience rake task has been included to do this locally:
8
13
 
9
14
  ```sh
10
15
  rake install
@@ -63,21 +68,32 @@ jcf organizations my-org
63
68
 
64
69
  #### Metrics
65
70
 
66
- > **_NOTE:_** Metrics are a little different. They are specific to the gov.uk PaaS. Plans to make this more generic are in the works.
71
+ Metrics queries AWS for backend CloudWatch metrics. It will output a table of the metrics for each service instance.
67
72
 
68
- You need to specify the environment and the service type you want to query.
73
+ Because CF doesn't give access to the underlying AWS details for us to query, we have to make some assumptions:
69
74
 
70
- Query the `production` environment, `rds-broker` service for the organization `my-org`:
75
+ - You need to be logged into the AWS account that the CF is using
76
+ - The AWS account has the correct permissions to query the metrics
71
77
 
72
- ```sh
73
- jcf metrics production rds-broker --org=my-org
74
- ```
78
+ We need a `template` for the instance names on AWS. This is a regex that will be used to match the instance names. For example, the `rds-broker` service has instances with names like `rdsbroker-GUID1`, `rdsbroker-GUID2`, etc. The template for this would be `rdsbroker-{guid}`.
79
+
80
+ Examples for the template, note that guid is a special value that is filled automatically with the instance guid from CF:
81
+
82
+ - `rdsbroker-{guid}`
83
+ - `s3broker-{guid}`
84
+ - `s3broker-{guid}-bucket-{name}`
85
+
86
+ When you supply a template token that is _not_ `guid`, you need to supply a `--values` flag to fill in the value. For example:
75
87
 
76
- Query the `staging` environment, `aws-s3-bucket-broker` service for the organizations `my-org` and `my-org2`:
77
88
  ```sh
78
- jcf metrics staging aws-s3-bucket-broker --org=my-org,my-org2
89
+ jcf metrics OFFERING \
90
+ --org=my-org \
91
+ --template='rdsbroker-{guid}-{name}' \
92
+ --values='name=foobar'
79
93
  ```
80
94
 
95
+ `jcf` will use the template to determine the AWS guid to query for metrics.
96
+
81
97
  ### Formatting
82
98
 
83
99
  The default format is a table. You can also format as JSON or CSV. For example:
@@ -14,11 +14,13 @@ module JCF
14
14
  module Commands
15
15
  module CF
16
16
  class Metrics < Command
17
- argument :env, required: true, values: %w[dev01 dev02 dev03 dev04 dev05 staging prod prod-lon],
18
- desc: "Choose an environment"
19
- argument :type, required: true, values: %w[postgres aws-s3-bucket],
20
- desc: "Choose a service instance type to query", default: "postgres"
17
+ argument :offering, required: true, values: %w[postgres aws-s3-bucket],
18
+ desc: "Choose a service instance offering to query"
21
19
 
20
+ option :template, aliases: ["-t"], required: true, type: :string,
21
+ desc: "Template for backend service instance names e.g. \"rdsbroker-{guid}-{name}\""
22
+ option :values, aliases: ["-v"], required: false, type: :string, default: "",
23
+ desc: "Values for the template. 'guid' is the service instance guid e.g. \"name=test\""
22
24
  option :org, aliases: ["-o"], required: true, type: :string,
23
25
  desc: "Choose an organization (can be multiple comma-separated)"
24
26
  option :name, aliases: ["-n"], type: :string, desc: "Choose a service instance name"
@@ -31,11 +33,11 @@ module JCF
31
33
  org_guid = organizations.find { |o| o.name == org }.guid
32
34
  err.puts "Found org guid: #{org_guid}"
33
35
 
34
- offering_guid = service_offerings.find { |s| s.name == options[:type] }&.guid
36
+ offering_guid = service_offerings.find { |s| s.name == options[:offering] }&.guid
35
37
  err.puts "Found offering guid: #{offering_guid}"
36
38
 
37
39
  unless offering_guid
38
- err.puts "No offerings found for type #{options[:type]}"
40
+ err.puts "No offerings found for type #{options[:offering]}"
39
41
  exit(1)
40
42
  end
41
43
 
@@ -64,11 +66,6 @@ module JCF
64
66
  service_plan = instance.relationships.service_plan.populate!
65
67
  service_offering = service_plan.relationships.service_offering.populate!
66
68
  service_broker = service_offering.relationships.service_broker.populate!
67
- # puts "Getting metrics for #{instance.name}"
68
- # puts "service_plan: #{service_plan.name}"
69
- # puts "service_offering: #{service_offering.name}"
70
- # puts "service_broker: #{service_broker.name}"
71
- # return nil
72
69
 
73
70
  Thread.new do
74
71
  m = JCF::CF::Metric.new
@@ -85,15 +82,20 @@ module JCF
85
82
  m.service_broker_guid = service_broker.guid
86
83
  m.service_offering = service_offering.name
87
84
  m.service_plan = service_plan.name
85
+
86
+ template = options[:template]
87
+ t_values = parse_values(options[:values], instance.guid)
88
+
88
89
  if service_offering.name == "postgres"
89
- m.storage_used = to_gb(cw.rds_storage_used(name: rds_guid(instance.guid)) || "")
90
- m.storage_allocated = to_gb(cw.storage_allocated(name: rds_guid(instance.guid)) || "")
91
- m.storage_free = to_gb(cw.storage_free(name: rds_guid(instance.guid)) || "")
92
- m.iops = (cw.iops(name: rds_guid(instance.guid)).to_fs(:rounded, precision: 0) || "")
93
- m.cpu = (cw.cpu(name: rds_guid(instance.guid)).to_fs(:rounded, precision: 0) || "")
90
+ m.storage_used = to_gb(cw.rds_storage_used(name: JCF::CLI.template_parser(template, t_values)) || "")
91
+ m.storage_allocated = to_gb(cw.storage_allocated(name: JCF::CLI.template_parser(template, t_values)) || "")
92
+ m.storage_free = to_gb(cw.storage_free(name: JCF::CLI.template_parser(template, t_values)) || "")
93
+ m.iops = (cw.iops(name: JCF::CLI.template_parser(template, t_values)).to_fs(:rounded, precision: 0) || "")
94
+ m.cpu = (cw.cpu(name: JCF::CLI.template_parser(template, t_values)).to_fs(:rounded, precision: 0) || "")
94
95
  end
96
+
95
97
  if service_offering.name == "aws-s3-bucket"
96
- m.storage_used = to_gb(cw.s3_storage_used(name: s3_guid(options[:env], instance.guid)) || "")
98
+ m.storage_used = to_gb(cw.s3_storage_used(name: JCF::CLI.template_parser(template, t_values)) || "")
97
99
  end
98
100
  values << m
99
101
  end
@@ -108,18 +110,16 @@ module JCF
108
110
 
109
111
  private
110
112
 
111
- def rds_guid(guid)
112
- "rdsbroker-#{guid}"
113
- end
114
-
115
- def s3_guid(deploy_env, guid)
116
- "paas-s3-broker-#{deploy_env}-#{guid}"
117
- end
118
-
119
113
  def validate_options(options)
120
114
  raise JCF::CLI::InvalidOptionError, "No organization given" unless options[:org]
121
115
  end
122
116
 
117
+ def parse_values(values, guid)
118
+ values = values.split(",")
119
+ values << "guid=#{guid}"
120
+ values.join(",")
121
+ end
122
+
123
123
  def organizations
124
124
  @organizations ||= JCF::CF::Organization.all
125
125
  end
data/lib/jcf/cli.rb CHANGED
@@ -34,6 +34,18 @@ module JCF
34
34
  end
35
35
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
36
36
 
37
+ # template parsing: "{guid}-{name}", "guid=1234,name=test"
38
+ # TODO: add some form of validation and error handling
39
+ def self.template_parser(template, values)
40
+ result = template.dup
41
+
42
+ (values || "").split(",").each do |value|
43
+ key, val = value.split("=")
44
+ result.gsub!("{#{key}}", val)
45
+ end
46
+ result
47
+ end
48
+
37
49
  loader.setup
38
50
  ActiveSupport::Inflector.inflections(:en) do |inflect|
39
51
  inflect.irregular "quota", "quotas"
data/lib/jcf/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JCF
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jcf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie van Dyke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-02 00:00:00.000000000 Z
11
+ date: 2023-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler