apisonator 2.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +317 -0
- data/Gemfile +11 -0
- data/Gemfile.base +65 -0
- data/Gemfile.lock +319 -0
- data/Gemfile.on_prem +1 -0
- data/Gemfile.on_prem.lock +297 -0
- data/LICENSE +202 -0
- data/NOTICE +15 -0
- data/README.md +230 -0
- data/Rakefile +287 -0
- data/apisonator.gemspec +47 -0
- data/app/api/api.rb +13 -0
- data/app/api/internal/alert_limits.rb +32 -0
- data/app/api/internal/application_keys.rb +49 -0
- data/app/api/internal/application_referrer_filters.rb +43 -0
- data/app/api/internal/applications.rb +77 -0
- data/app/api/internal/errors.rb +54 -0
- data/app/api/internal/events.rb +42 -0
- data/app/api/internal/internal.rb +104 -0
- data/app/api/internal/metrics.rb +40 -0
- data/app/api/internal/service_tokens.rb +46 -0
- data/app/api/internal/services.rb +58 -0
- data/app/api/internal/stats.rb +42 -0
- data/app/api/internal/usagelimits.rb +62 -0
- data/app/api/internal/utilization.rb +23 -0
- data/bin/3scale_backend +223 -0
- data/bin/3scale_backend_worker +26 -0
- data/config.ru +4 -0
- data/config/puma.rb +192 -0
- data/config/schedule.rb +9 -0
- data/ext/mkrf_conf.rb +64 -0
- data/lib/3scale/backend.rb +67 -0
- data/lib/3scale/backend/alert_limit.rb +56 -0
- data/lib/3scale/backend/alerts.rb +137 -0
- data/lib/3scale/backend/analytics/kinesis.rb +3 -0
- data/lib/3scale/backend/analytics/kinesis/adapter.rb +180 -0
- data/lib/3scale/backend/analytics/kinesis/exporter.rb +86 -0
- data/lib/3scale/backend/analytics/kinesis/job.rb +135 -0
- data/lib/3scale/backend/analytics/redshift.rb +3 -0
- data/lib/3scale/backend/analytics/redshift/adapter.rb +367 -0
- data/lib/3scale/backend/analytics/redshift/importer.rb +83 -0
- data/lib/3scale/backend/analytics/redshift/job.rb +33 -0
- data/lib/3scale/backend/application.rb +330 -0
- data/lib/3scale/backend/application_events.rb +76 -0
- data/lib/3scale/backend/background_job.rb +65 -0
- data/lib/3scale/backend/configurable.rb +20 -0
- data/lib/3scale/backend/configuration.rb +151 -0
- data/lib/3scale/backend/configuration/loader.rb +42 -0
- data/lib/3scale/backend/constants.rb +19 -0
- data/lib/3scale/backend/cors.rb +84 -0
- data/lib/3scale/backend/distributed_lock.rb +67 -0
- data/lib/3scale/backend/environment.rb +21 -0
- data/lib/3scale/backend/error_storage.rb +52 -0
- data/lib/3scale/backend/errors.rb +343 -0
- data/lib/3scale/backend/event_storage.rb +120 -0
- data/lib/3scale/backend/experiment.rb +84 -0
- data/lib/3scale/backend/extensions.rb +5 -0
- data/lib/3scale/backend/extensions/array.rb +19 -0
- data/lib/3scale/backend/extensions/hash.rb +26 -0
- data/lib/3scale/backend/extensions/nil_class.rb +13 -0
- data/lib/3scale/backend/extensions/redis.rb +44 -0
- data/lib/3scale/backend/extensions/string.rb +13 -0
- data/lib/3scale/backend/extensions/time.rb +110 -0
- data/lib/3scale/backend/failed_jobs_scheduler.rb +141 -0
- data/lib/3scale/backend/job_fetcher.rb +122 -0
- data/lib/3scale/backend/listener.rb +728 -0
- data/lib/3scale/backend/listener_metrics.rb +99 -0
- data/lib/3scale/backend/logging.rb +48 -0
- data/lib/3scale/backend/logging/external.rb +44 -0
- data/lib/3scale/backend/logging/external/impl.rb +93 -0
- data/lib/3scale/backend/logging/external/impl/airbrake.rb +66 -0
- data/lib/3scale/backend/logging/external/impl/bugsnag.rb +69 -0
- data/lib/3scale/backend/logging/external/impl/default.rb +18 -0
- data/lib/3scale/backend/logging/external/resque.rb +57 -0
- data/lib/3scale/backend/logging/logger.rb +18 -0
- data/lib/3scale/backend/logging/middleware.rb +62 -0
- data/lib/3scale/backend/logging/middleware/json_writer.rb +21 -0
- data/lib/3scale/backend/logging/middleware/text_writer.rb +60 -0
- data/lib/3scale/backend/logging/middleware/writer.rb +143 -0
- data/lib/3scale/backend/logging/worker.rb +107 -0
- data/lib/3scale/backend/manifest.rb +80 -0
- data/lib/3scale/backend/memoizer.rb +277 -0
- data/lib/3scale/backend/metric.rb +275 -0
- data/lib/3scale/backend/metric/collection.rb +91 -0
- data/lib/3scale/backend/oauth.rb +4 -0
- data/lib/3scale/backend/oauth/token.rb +26 -0
- data/lib/3scale/backend/oauth/token_key.rb +30 -0
- data/lib/3scale/backend/oauth/token_storage.rb +313 -0
- data/lib/3scale/backend/oauth/token_value.rb +25 -0
- data/lib/3scale/backend/period.rb +3 -0
- data/lib/3scale/backend/period/boundary.rb +107 -0
- data/lib/3scale/backend/period/cache.rb +28 -0
- data/lib/3scale/backend/period/period.rb +402 -0
- data/lib/3scale/backend/queue_storage.rb +16 -0
- data/lib/3scale/backend/rack.rb +49 -0
- data/lib/3scale/backend/rack/exception_catcher.rb +136 -0
- data/lib/3scale/backend/rack/internal_error_catcher.rb +23 -0
- data/lib/3scale/backend/rack/prometheus.rb +19 -0
- data/lib/3scale/backend/saas.rb +6 -0
- data/lib/3scale/backend/saas_analytics.rb +4 -0
- data/lib/3scale/backend/server.rb +30 -0
- data/lib/3scale/backend/server/falcon.rb +52 -0
- data/lib/3scale/backend/server/puma.rb +71 -0
- data/lib/3scale/backend/service.rb +317 -0
- data/lib/3scale/backend/service_token.rb +97 -0
- data/lib/3scale/backend/stats.rb +8 -0
- data/lib/3scale/backend/stats/aggregator.rb +170 -0
- data/lib/3scale/backend/stats/aggregators/base.rb +72 -0
- data/lib/3scale/backend/stats/aggregators/response_code.rb +58 -0
- data/lib/3scale/backend/stats/aggregators/usage.rb +34 -0
- data/lib/3scale/backend/stats/bucket_reader.rb +135 -0
- data/lib/3scale/backend/stats/bucket_storage.rb +108 -0
- data/lib/3scale/backend/stats/cleaner.rb +195 -0
- data/lib/3scale/backend/stats/codes_commons.rb +14 -0
- data/lib/3scale/backend/stats/delete_job_def.rb +60 -0
- data/lib/3scale/backend/stats/key_generator.rb +73 -0
- data/lib/3scale/backend/stats/keys.rb +104 -0
- data/lib/3scale/backend/stats/partition_eraser_job.rb +58 -0
- data/lib/3scale/backend/stats/partition_generator_job.rb +46 -0
- data/lib/3scale/backend/stats/period_commons.rb +34 -0
- data/lib/3scale/backend/stats/stats_parser.rb +141 -0
- data/lib/3scale/backend/stats/storage.rb +113 -0
- data/lib/3scale/backend/statsd.rb +14 -0
- data/lib/3scale/backend/storable.rb +35 -0
- data/lib/3scale/backend/storage.rb +40 -0
- data/lib/3scale/backend/storage_async.rb +4 -0
- data/lib/3scale/backend/storage_async/async_redis.rb +21 -0
- data/lib/3scale/backend/storage_async/client.rb +205 -0
- data/lib/3scale/backend/storage_async/pipeline.rb +79 -0
- data/lib/3scale/backend/storage_async/resque_extensions.rb +30 -0
- data/lib/3scale/backend/storage_helpers.rb +278 -0
- data/lib/3scale/backend/storage_key_helpers.rb +9 -0
- data/lib/3scale/backend/storage_sync.rb +43 -0
- data/lib/3scale/backend/transaction.rb +62 -0
- data/lib/3scale/backend/transactor.rb +177 -0
- data/lib/3scale/backend/transactor/limit_headers.rb +54 -0
- data/lib/3scale/backend/transactor/notify_batcher.rb +139 -0
- data/lib/3scale/backend/transactor/notify_job.rb +47 -0
- data/lib/3scale/backend/transactor/process_job.rb +33 -0
- data/lib/3scale/backend/transactor/report_job.rb +84 -0
- data/lib/3scale/backend/transactor/status.rb +236 -0
- data/lib/3scale/backend/transactor/usage_report.rb +182 -0
- data/lib/3scale/backend/usage.rb +63 -0
- data/lib/3scale/backend/usage_limit.rb +115 -0
- data/lib/3scale/backend/use_cases/provider_key_change_use_case.rb +60 -0
- data/lib/3scale/backend/util.rb +17 -0
- data/lib/3scale/backend/validators.rb +26 -0
- data/lib/3scale/backend/validators/base.rb +36 -0
- data/lib/3scale/backend/validators/key.rb +17 -0
- data/lib/3scale/backend/validators/limits.rb +57 -0
- data/lib/3scale/backend/validators/oauth_key.rb +15 -0
- data/lib/3scale/backend/validators/oauth_setting.rb +15 -0
- data/lib/3scale/backend/validators/redirect_uri.rb +33 -0
- data/lib/3scale/backend/validators/referrer.rb +60 -0
- data/lib/3scale/backend/validators/service_state.rb +15 -0
- data/lib/3scale/backend/validators/state.rb +15 -0
- data/lib/3scale/backend/version.rb +5 -0
- data/lib/3scale/backend/views/oauth_access_tokens.builder +14 -0
- data/lib/3scale/backend/views/oauth_app_id_by_token.builder +4 -0
- data/lib/3scale/backend/worker.rb +87 -0
- data/lib/3scale/backend/worker_async.rb +88 -0
- data/lib/3scale/backend/worker_metrics.rb +44 -0
- data/lib/3scale/backend/worker_sync.rb +32 -0
- data/lib/3scale/bundler_shim.rb +17 -0
- data/lib/3scale/prometheus_server.rb +10 -0
- data/lib/3scale/tasks/connectivity.rake +41 -0
- data/lib/3scale/tasks/helpers.rb +3 -0
- data/lib/3scale/tasks/helpers/environment.rb +23 -0
- data/lib/3scale/tasks/stats.rake +131 -0
- data/lib/3scale/tasks/swagger.rake +46 -0
- data/licenses.xml +1215 -0
- metadata +227 -0
data/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Red Hat 3scale API Management Platform Apisonator
|
|
2
|
+
Copyright (c) 2010-2016 3scale, Inc
|
|
3
|
+
Copyright (c) 2016-2018 Red Hat, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Apisonator
|
|
2
|
+
|
|
3
|
+
[](https://quay.io/repository/3scale/apisonator)
|
|
4
|
+
[](https://circleci.com/gh/3scale/apisonator)
|
|
5
|
+
[](https://codeclimate.com/github/3scale/apisonator/maintainability)
|
|
6
|
+
|
|
7
|
+
This software is licensed under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
|
|
8
|
+
|
|
9
|
+
See the LICENSE and NOTICE files that should have been provided along with this
|
|
10
|
+
software for details.
|
|
11
|
+
|
|
12
|
+
## Description
|
|
13
|
+
|
|
14
|
+
This is the Red Hat 3scale API Management backend.
|
|
15
|
+
|
|
16
|
+
It has the following components:
|
|
17
|
+
|
|
18
|
+
### Apisonator listener
|
|
19
|
+
|
|
20
|
+
It provides the point of entry of the API Management Platform's Backend.
|
|
21
|
+
The Service management API (SM API) is provided to authorize and report consumer
|
|
22
|
+
API requests.
|
|
23
|
+
|
|
24
|
+
Three main operations can be performed with this API:
|
|
25
|
+
|
|
26
|
+
* Report: Reports a number of hits to one or more metrics, performing the
|
|
27
|
+
corresponding metric aggregations
|
|
28
|
+
* Authorize: Authorize a request. The authorization of a request checks that:
|
|
29
|
+
* The provided API key to authorize the request is valid
|
|
30
|
+
* The current usage metrics of the API related to the request are within
|
|
31
|
+
the specified limits
|
|
32
|
+
* Authrep: Combination of both the above
|
|
33
|
+
|
|
34
|
+
Make sure to read the corresponding Swagger-generated documentation of this
|
|
35
|
+
operations, located in [docs/active_docs/Service Management API.json](docs%2Factive_docs%2FService%20Management%20API.json)
|
|
36
|
+
|
|
37
|
+
It attempts to respond with lowest possible latency, performing minimal work
|
|
38
|
+
and offloading other work to Apisonator workers by enqueuing tasks into job queues.
|
|
39
|
+
|
|
40
|
+
This component needs access to a Redis database to perform the following actions:
|
|
41
|
+
* Enqueue reports, which will be processed by the Apisonator worker component
|
|
42
|
+
* Perform authorization of the requests
|
|
43
|
+
|
|
44
|
+
These two actions can be configured to be performed in different Redis
|
|
45
|
+
databases if desired (see the [Prerequisites](#prerequisites)
|
|
46
|
+
and [Configuration](#configuration) sections).
|
|
47
|
+
|
|
48
|
+
Finally, another API named 'Internal API' is provided to configure services
|
|
49
|
+
in Apisonator. This API is intended only for administrative purposes and not
|
|
50
|
+
for general consumption. Therefore, usage of this API should be protected or
|
|
51
|
+
not exposed to untrusted parties. You can also generate its documentation with
|
|
52
|
+
Rake tasks. The [Pisoni](https://github.com/3scale/pisoni) API client can be
|
|
53
|
+
used to interact with the Internal API.
|
|
54
|
+
|
|
55
|
+
To quickly test Apisonator, random services can be created and configured on it
|
|
56
|
+
via the use of the 'Buddhi' tool located in our performance tests
|
|
57
|
+
toolkit: [3scale perftest-toolkit](https://github.com/3scale/perftest-toolkit/).
|
|
58
|
+
|
|
59
|
+
This component may also be referred to as '3scale_backend'.
|
|
60
|
+
|
|
61
|
+
### Apisonator worker
|
|
62
|
+
|
|
63
|
+
It is responsible for performing background tasks off-loaded from
|
|
64
|
+
Apisonator listeners (enqueued jobs).
|
|
65
|
+
|
|
66
|
+
The worker component takes care of running these enqueued jobs, mainly related
|
|
67
|
+
to reporting of previous traffic.
|
|
68
|
+
|
|
69
|
+
Specifically, this component:
|
|
70
|
+
* Dequeues and runs the report jobs that have been submitted to the Redis
|
|
71
|
+
background jobs database by the Apisonator listener/s or the
|
|
72
|
+
Apisonator failed jobs rescheduler
|
|
73
|
+
* Stores the results of running the report jobs in the Redis Storage database
|
|
74
|
+
|
|
75
|
+
This component may also be referred to as '3scale_backend_worker'.
|
|
76
|
+
|
|
77
|
+
### Apisonator failed jobs rescheduler
|
|
78
|
+
|
|
79
|
+
This is a simple task that acts as a cron scheduler to requeue jobs that failed
|
|
80
|
+
when being processed by an Apisonator worker. The jobs are requeued into
|
|
81
|
+
the Redis background jobs database.
|
|
82
|
+
|
|
83
|
+
This component may also be referred to as 'backend-cron'.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
See the file [DEVELOPMENT](DEVELOPMENT.md)
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
91
|
+
You can find documentation about Apisonator (also called referred to as `3scale
|
|
92
|
+
backend`) at the [Red Hat 3scale API Management product pages](https://access.redhat.com/products/red-hat-3scale/).
|
|
93
|
+
|
|
94
|
+
Documentation about specific parts of Apisonator (APIs, specs, behaviour, etc)
|
|
95
|
+
can be found in the [`docs`](https://github.com/3scale/apisonator/tree/master/docs) folder, though this is mostly meant for development and design purposes rather
|
|
96
|
+
than user documentation.
|
|
97
|
+
|
|
98
|
+
## How to run
|
|
99
|
+
|
|
100
|
+
### Prerequisites
|
|
101
|
+
|
|
102
|
+
* Docker (requires version 1.10.0 or later)
|
|
103
|
+
* A Redis database, used to store API request statistics and services. Also
|
|
104
|
+
used to perform API requests authorizations. In Apisonator this database
|
|
105
|
+
is commonly referred to as 'Redis Storage'
|
|
106
|
+
* A Redis database, used to store background jobs. The Redis Resque library
|
|
107
|
+
is used for this. In Apisonator this database is commonly referred to as
|
|
108
|
+
'Redis Resque', or as the 'background jobs database'
|
|
109
|
+
|
|
110
|
+
The two previous Redis databases can be configured in the following ways:
|
|
111
|
+
|
|
112
|
+
* In a single machine/vm, using a single Redis process by specifying
|
|
113
|
+
different database identifiers, which is supported by the Redis URI
|
|
114
|
+
specification. i.e. redis://host:port/0, redis://host:port/1
|
|
115
|
+
* In a single machine/vm, using different Redis processes with different
|
|
116
|
+
assigned ports
|
|
117
|
+
* In separate machines/vms
|
|
118
|
+
|
|
119
|
+
The first thing you will need is cloning the project:
|
|
120
|
+
> `$ git clone git@github.com:3scale/apisonator.git`
|
|
121
|
+
|
|
122
|
+
Next cd into the directory, `cd apisonator`.
|
|
123
|
+
|
|
124
|
+
### Apisonator image generation
|
|
125
|
+
|
|
126
|
+
Go to the `openshift` directory and execute `make build`. This will generate
|
|
127
|
+
a local docker image named `amp:apisonator-<version_number>` based on CentOS 7.
|
|
128
|
+
|
|
129
|
+
### Configuration
|
|
130
|
+
|
|
131
|
+
To run any Apisonator component, application-related environment variables must
|
|
132
|
+
be previously set. This can be done by setting them via the `--env` flag in
|
|
133
|
+
Docker or by placing them in a ENV file and setting the ENV file in Docker via
|
|
134
|
+
the `--env-file` flag.
|
|
135
|
+
|
|
136
|
+
The most important variables to set are:
|
|
137
|
+
|
|
138
|
+
* CONFIG_QUEUES_MASTER_NAME: Set this to the [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis)
|
|
139
|
+
of where the Redis Storage has been installed
|
|
140
|
+
* CONFIG_REDIS_PROXY: Set this to the [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis)
|
|
141
|
+
of where the Redis Resque has been installed
|
|
142
|
+
* CONFIG_INTERNAL_API_USER: Set this to an arbitrary username <username>
|
|
143
|
+
that will be the one used to be able to use the Apisonator internal api
|
|
144
|
+
* CONFIG_INTERNAL_API_PASSWORD: Set this to an arbitrary
|
|
145
|
+
password <password> that will be the one used to be able to use the
|
|
146
|
+
Apisonator internal api
|
|
147
|
+
* RACK_ENV: Set this to 'production'
|
|
148
|
+
|
|
149
|
+
A complete list of configuration variables that can be set can be
|
|
150
|
+
found in the file `openshift/3scale_backend.conf`
|
|
151
|
+
|
|
152
|
+
An example of an ENV file can be found at `openshift/.env.test`
|
|
153
|
+
|
|
154
|
+
### Automatic execution (with Makefile)
|
|
155
|
+
|
|
156
|
+
Makefile rules can be run to execute the different Apisonator components
|
|
157
|
+
with some predefined behaviour. To do this a file named `.env` in
|
|
158
|
+
the `openshift` directory must be created before.
|
|
159
|
+
|
|
160
|
+
Once this has been performed, go to the `openshift` directory and execute
|
|
161
|
+
one of the available Makefile commands to run Apisonator components:
|
|
162
|
+
|
|
163
|
+
#### Apisonator Listener
|
|
164
|
+
|
|
165
|
+
Execute the Apisonator Listener, exposing the port 3001:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
make listener
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Apisonator Worker
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
make worker
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Apisonator failed jobs rescheduler
|
|
178
|
+
|
|
179
|
+
Execute the 'cron' Apisonator component:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
make cron
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### Apisonator bash shell
|
|
186
|
+
|
|
187
|
+
Execute a bash shell with the Apisonator source code with all the available
|
|
188
|
+
components:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
make bash
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Manual execution
|
|
195
|
+
|
|
196
|
+
Another way of executing the Apisonator components is by running a container
|
|
197
|
+
using the previously generated Apisonator image:
|
|
198
|
+
|
|
199
|
+
#### Apisonator Listener
|
|
200
|
+
|
|
201
|
+
To run an Apisonator listener, the script bin/3scale_backend is used. To
|
|
202
|
+
run it from a previously generated Apisonator docker image:
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
docker run -p 3001:3001 --env-file <myenv_file> -it amp:apisonator-<version_number> 3scale_backend start -p 3001 -x /dev/stdout
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
You can see all the available options of the apisonator listener by executing:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
docker run -it amp:apisonator-<version_number> 3scale_backend help
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Apisonator Worker
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
docker run --env-file <myenv_file> -it amp:apisonator-<version_number> 3scale_backend_worker
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Apisonator failed jobs rescheduler
|
|
221
|
+
|
|
222
|
+
```
|
|
223
|
+
docker run --env-file <myenv_file> -it amp:apisonator-<version_number> backend-cron
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Apisonator bash shell
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
docker run --env-file <myenv_file> -it amp:apisonator-<version_number> bash
|
|
230
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require '3scale/backend/configuration'
|
|
4
|
+
require '3scale/backend'
|
|
5
|
+
require '3scale/tasks/helpers'
|
|
6
|
+
|
|
7
|
+
include ThreeScale::Tasks::Helpers
|
|
8
|
+
|
|
9
|
+
load 'lib/3scale/tasks/connectivity.rake'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if Environment.saas?
|
|
13
|
+
require '3scale/backend/logging/external'
|
|
14
|
+
|
|
15
|
+
ThreeScale::Backend::Logging::External.setup_rake
|
|
16
|
+
|
|
17
|
+
load 'lib/3scale/tasks/swagger.rake'
|
|
18
|
+
load 'lib/3scale/tasks/stats.rake'
|
|
19
|
+
|
|
20
|
+
if Environment.testable?
|
|
21
|
+
|
|
22
|
+
ENV['RACK_ENV'] = "test"
|
|
23
|
+
require 'rake/testtask'
|
|
24
|
+
|
|
25
|
+
task :default => [:test, :spec]
|
|
26
|
+
|
|
27
|
+
test_task_dependencies = ['test:unit', 'test:integration']
|
|
28
|
+
|
|
29
|
+
desc 'Run unit and integration tests'
|
|
30
|
+
task :test => test_task_dependencies
|
|
31
|
+
|
|
32
|
+
desc 'Benchmark'
|
|
33
|
+
task :bench, [:file] do |_, args|
|
|
34
|
+
require 'benchmark/ips'
|
|
35
|
+
require 'pathname'
|
|
36
|
+
require File.dirname(__FILE__) + '/test/test_helpers/configuration'
|
|
37
|
+
|
|
38
|
+
filelist = if args[:file]
|
|
39
|
+
"#{args[:file].sub(/\Abench\//, '')}"
|
|
40
|
+
else
|
|
41
|
+
'**/*_bench.rb'
|
|
42
|
+
end
|
|
43
|
+
FileList["#{File.dirname(__FILE__)}/bench/#{filelist}"].each do |f|
|
|
44
|
+
bench = Pathname.new(f).cleanpath
|
|
45
|
+
if bench.to_s.start_with?(File.dirname(__FILE__) + File::SEPARATOR)
|
|
46
|
+
puts "Running benchmark #{bench}"
|
|
47
|
+
load f
|
|
48
|
+
else
|
|
49
|
+
STDERR.puts "Ignoring path #{f} as it points outside the project"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
puts "Benchmarks finished"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
namespace :test do
|
|
57
|
+
Rake::TestTask.new(:unit) do |task|
|
|
58
|
+
task.test_files = FileList['test/unit/**/*_test.rb']
|
|
59
|
+
task.verbose = true
|
|
60
|
+
task.warning = false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Rake::TestTask.new(:integration) do |task|
|
|
64
|
+
task.test_files = FileList['test/integration/**/*_test.rb']
|
|
65
|
+
task.verbose = true
|
|
66
|
+
task.warning = false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
require 'rspec/core/rake_task'
|
|
71
|
+
spec_task_dependencies = [
|
|
72
|
+
'spec:unit', 'spec:integration', 'spec:acceptance', 'spec:api', 'spec:use_cases', 'spec:server'
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
desc 'Run RSpec tests'
|
|
76
|
+
task :spec => spec_task_dependencies
|
|
77
|
+
|
|
78
|
+
namespace :spec do
|
|
79
|
+
|
|
80
|
+
require 'rspec/core/rake_task'
|
|
81
|
+
desc 'Run all RSpec tests (unit, integration, acceptance, api, use_cases, server)'
|
|
82
|
+
task :all => spec_task_dependencies
|
|
83
|
+
|
|
84
|
+
desc 'Run RSpec unit tests'
|
|
85
|
+
RSpec::Core::RakeTask.new(:unit) do |task|
|
|
86
|
+
task.pattern = 'spec/unit/**/*_spec.rb'
|
|
87
|
+
#We require spec_helper because some tests
|
|
88
|
+
#do not include spec_helper by themselves
|
|
89
|
+
task.rspec_opts = '--require=spec_helper'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc 'Run RSpec integration tests'
|
|
93
|
+
RSpec::Core::RakeTask.new(:integration) do |task|
|
|
94
|
+
task.pattern = 'spec/integration/**/*_spec.rb'
|
|
95
|
+
task.rspec_opts = '--require=spec_helper'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
desc 'Run RSpec acceptance tests'
|
|
99
|
+
RSpec::Core::RakeTask.new(:acceptance) do |task|
|
|
100
|
+
task.pattern = 'spec/acceptance/**/*_spec.rb'
|
|
101
|
+
task.rspec_opts = '--require=spec_helper'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
desc 'Run RSpec api tests'
|
|
105
|
+
RSpec::Core::RakeTask.new(:api) do |task|
|
|
106
|
+
task.pattern = 'spec/api/**/*_spec.rb'
|
|
107
|
+
task.rspec_opts = '--require=spec_helper'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
desc 'Run RSpec use_cases tests'
|
|
111
|
+
RSpec::Core::RakeTask.new(:use_cases) do |task|
|
|
112
|
+
task.pattern = 'spec/use_cases/**/*_spec.rb'
|
|
113
|
+
task.rspec_opts = '--require=spec_helper'
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
desc 'Run Rspec server tests'
|
|
117
|
+
RSpec::Core::RakeTask.new(:server) do |task|
|
|
118
|
+
task.pattern = 'spec/server/**/*_spec.rb'
|
|
119
|
+
task.rspec_opts = '--require=spec_helper'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
desc 'Run RSpec test/s specified by input file pattern'
|
|
123
|
+
RSpec::Core::RakeTask.new(:specific, :test_name) do |task, task_args|
|
|
124
|
+
task.pattern = "#{task_args[:test_name]}"
|
|
125
|
+
task.rspec_opts = '--require=spec_helper'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
desc 'Generate API request documentation from API specs'
|
|
131
|
+
RSpec::Core::RakeTask.new('docs:generate') do |t|
|
|
132
|
+
t.pattern = 'spec/acceptance/**/*_spec.rb'
|
|
133
|
+
t.rspec_opts = ['--format RspecApiDocumentation::ApiFormatter']
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
desc 'Tag and push the current version'
|
|
137
|
+
task :release => ['release:tag', 'release:push']
|
|
138
|
+
|
|
139
|
+
namespace :release do
|
|
140
|
+
namespace :changelog do
|
|
141
|
+
task :shortlog do
|
|
142
|
+
version = `git describe --abbrev=0`.chomp
|
|
143
|
+
STDOUT.puts "Changes from #{version} to HEAD\n\n"
|
|
144
|
+
system "git shortlog --no-merges #{version}.."
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Link all issues and PRs in the changelog that have no link.
|
|
148
|
+
#
|
|
149
|
+
# By default links to PRs (althought GitHub redirects IIRC) but you can
|
|
150
|
+
# specify an issue link by preceding it with "issue"/"Issue" or specify
|
|
151
|
+
# a PR link (default) by preceding it with "PR".
|
|
152
|
+
task :link_prs, [:file] do |_, args|
|
|
153
|
+
file = args[:file] || File.join(File.dirname(__FILE__), 'CHANGELOG.md')
|
|
154
|
+
|
|
155
|
+
File.open file, File::RDWR do |f|
|
|
156
|
+
contents = f.read
|
|
157
|
+
contents.
|
|
158
|
+
# this regexp is not perfect but ok - ie. it would match issue(#5)
|
|
159
|
+
gsub!(/(\b|[^[:alnum]])([iI]ssue|PR)?([\([:space:]])#(\d+)/) do
|
|
160
|
+
|
|
161
|
+
# unfortunately gsub uses globals for groups :(
|
|
162
|
+
type_prefix, type, separator, number = $1, $2, $3, $4
|
|
163
|
+
|
|
164
|
+
link = case type.to_s.upcase
|
|
165
|
+
when 'ISSUE'
|
|
166
|
+
# even if quoted like this, remember that \ still escapes
|
|
167
|
+
%{https://github.com/3scale/apisonator/issues/%s}
|
|
168
|
+
else
|
|
169
|
+
# default to PR links
|
|
170
|
+
%{https://github.com/3scale/apisonator/pull/%s}
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
prefix = if type && separator == ' '
|
|
174
|
+
# remove "issue "
|
|
175
|
+
type_prefix
|
|
176
|
+
else
|
|
177
|
+
"#{type_prefix}#{separator}"
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
prefix << "[##{number}](#{link % number})"
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Overwrite the changelog
|
|
184
|
+
f.seek 0, IO::SEEK_SET
|
|
185
|
+
f.write contents
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
task :tag do
|
|
191
|
+
require File.dirname(__FILE__) + '/lib/3scale/backend/version'
|
|
192
|
+
version = "v#{ThreeScale::Backend::VERSION}"
|
|
193
|
+
STDOUT.puts "Creating tag #{version}"
|
|
194
|
+
system "git tag -sa #{version} -m \"#{version}\""
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
task :push do
|
|
198
|
+
system 'git push --tags'
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
desc 'Start the backend server in development'
|
|
203
|
+
task :start do
|
|
204
|
+
system "ruby -Ilib bin/3scale_backend start -p #{ENV['PORT'] || 3001}"
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
desc 'Start a backend_worker in development'
|
|
208
|
+
task :start_worker do
|
|
209
|
+
system 'ruby -Ilib bin/3scale_backend_worker --no-daemonize'
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
desc 'Stop a backend_worker in development'
|
|
213
|
+
task :stop_worker do
|
|
214
|
+
system 'ruby -Ilib bin/3scale_backend_worker stop'
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
desc 'Restart a backend_worker in development'
|
|
218
|
+
task :restart_worker do
|
|
219
|
+
system 'ruby -Ilib bin/3scale_backend_worker restart'
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
desc 'Check license compliance of dependencies'
|
|
223
|
+
task :license_finder do
|
|
224
|
+
STDOUT.puts "Checking license compliance\n"
|
|
225
|
+
unless system("license_finder --decisions-file=#{File.dirname(__FILE__)}" \
|
|
226
|
+
"/.dependency_decisions.yml")
|
|
227
|
+
STDERR.puts "\n*** License compliance test failed ***\n"
|
|
228
|
+
exit 1
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
namespace :license_finder do
|
|
233
|
+
namespace :report do
|
|
234
|
+
desc 'Generate an XML report for licenses'
|
|
235
|
+
task :xml do
|
|
236
|
+
require 'license_finder'
|
|
237
|
+
LicenseFinder::CLI::Main.start [
|
|
238
|
+
'report',
|
|
239
|
+
"--decisions-file=#{File.dirname(__FILE__)}/.dependency_decisions.yml",
|
|
240
|
+
'--format=xml',
|
|
241
|
+
'--quiet'
|
|
242
|
+
]
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
desc 'Reschedule failed jobs'
|
|
250
|
+
task :reschedule_failed_jobs do
|
|
251
|
+
reschedule_method = ThreeScale::Backend::FailedJobsScheduler.method(:reschedule_failed_jobs)
|
|
252
|
+
|
|
253
|
+
result = if Environment.using_async_redis?
|
|
254
|
+
Async { reschedule_method.call }.result
|
|
255
|
+
else
|
|
256
|
+
reschedule_method.call
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
puts "Rescheduled: #{result[:rescheduled]}. "\
|
|
260
|
+
"Failed and discarded: #{result[:failed_while_rescheduling]}. "\
|
|
261
|
+
"Pending failed jobs: #{result[:failed_current]}."
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
desc 'Delete stats of services marked for deletion'
|
|
265
|
+
namespace :stats do
|
|
266
|
+
task :cleanup, [:redis_urls, :log_deleted_keys] do |_, args|
|
|
267
|
+
redis_urls = args[:redis_urls] && args[:redis_urls].split(' ')
|
|
268
|
+
|
|
269
|
+
if redis_urls.nil? || redis_urls.empty?
|
|
270
|
+
puts 'No Redis URLs specified'
|
|
271
|
+
exit(false)
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
redis_clients = redis_urls.map do |redis_url|
|
|
275
|
+
parsed_uri = URI.parse(ThreeScale::Backend::Storage::Helpers.send(
|
|
276
|
+
:to_redis_uri, redis_url)
|
|
277
|
+
)
|
|
278
|
+
Redis.new(host: parsed_uri.host, port: parsed_uri.port)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
log_deleted = args[:log_deleted_keys] == 'true' ? STDOUT : nil
|
|
282
|
+
|
|
283
|
+
ThreeScale::Backend::Stats::Cleaner.delete!(
|
|
284
|
+
redis_clients, log_deleted_keys: log_deleted
|
|
285
|
+
)
|
|
286
|
+
end
|
|
287
|
+
end
|