summaryrefslogtreecommitdiff
path: root/python-sla-runner.spec
blob: d51db63b353bebb63e9d136671a0389727cee725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
%global _empty_manifest_terminate_build 0
Name:		python-sla-runner
Version:	0.0.21
Release:	1
Summary:	A continuous test runner for gathering SLA data
License:	MIT
URL:		https://github.com/billtrust/sla-monitor-runner
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/e6/9f/34b1e159011925a92995f21475ccfcbd05d787a139a003c764c2f60064f1/sla-runner-0.0.21.tar.gz
BuildArch:	noarch


%description
# SLA Monitor Worker

This is the test runner portion of the SLA monitor/reporter. It performs tests (or any command you want) repeatedly, and publishes success/failure to an SNS topic for external processing (for example, using lambda to write to a custom cloudwatch metric), as well as optionally uploading logs to an S3 bucket.

TODO: Unit tests not working

## Installing

To install simply install via pip

```bash
pip install --user sla-runner
```

Highly recommended is iam-docker run:

```bash
pip install --user iam-docker-run
```

This project assumes you are using role based authentication, as would be used in a production environment in AWS. This mimics that environment by running with an actual role.

## Terraform

Excute the following in the root folder to run terraform. Obviously, have Terraform installed. Set the bucket and table variables to existing backend resources for remote state.

```shell
# pip install iam-starter
cd terraform
export AWS_ENV="dev"
export TF_DATA_DIR="./.$AWS_ENV-terraform/"
export AWS_DEFAULT_REGION="us-east-1"
export TF_STATE_REGION="us-east-1"
export TF_STATE_BUCKET="mycompany-tfstate-$AWS_ENV"
export TF_STATE_TABLE="tfstate_$AWS_ENV"

iam-starter \
    --profile $AWS_ENV \
    --command \
        "terraform init \
        -backend-config=\"region=$TF_STATE_REGION\" \
        -backend-config=\"bucket=$TF_STATE_BUCKET\" \
        -backend-config=\"dynamodb_table=$TF_STATE_TABLE\" && \
        terraform apply \
        -var \"aws_env=$AWS_ENV\" \
        -var \"aws_region=$AWS_DEFAULT_REGION\""
```

## Using

Use iam-docker-run outside of AWS to run tests. In real life scenarios on ECS, instead install sla-runner via pypi in your service container, and set `--image` to the image of the service container which contains your test.

```bash
docker build -t sla-monitor/sla-runner:latest .

export AWS_ENV="dev"
iam-docker-run \
    -e SLARUNNER_COMMAND="/bin/bash /src/test-scripts/run-tests.sh" \
    -e SLARUNNER_SERVICE=example-service \
    -e SLARUNNER_GROUPS="dev-team,critical" \
    -e SLARUNNER_DELAY=30 \
    -e SLARUNNER_SNSTOPICNAME="sla-monitor-result-published-$AWS_ENV" \
    -e SLARUNNER_S3BUCKETNAME="sla-monitoring-logs-$AWS_ENV" \
    --full-entrypoint "sla-runner" \
    --region us-east-1 \
    --profile $AWS_ENV \
    --role sla-monitor-runner-role-$AWS_ENV \
    --image sla-monitor/sla-runner:latest
```

In ECS, add these as environment variables in the task definition or load from ssm via ssm-starter:

```
--full-entrypoint "ssm-starter --ssm-name slarunner --command 'sla-runner'"
```

## Variables

The runner takes the following values which are provided by environment variable. 

### Global variables

When loading variables via SSM and ssm-starter, you can define default variables by adding a globals path before the service path.

For example, in your task definition in terraform:

```json
    "entryPoint": ["ssm-starter"],
    "command": [
        "--ssm-name", "sla-monitor-globals",
        "--ssm-name", "${var.application}",
        "--command", "sla-runner" // or script that runs sla-runner
    ]
```

#### command

$SLARUNNER_COMMAND

Command to be run repeatedly. Pretty straightforward. If there is an interrupt, the runner will attempt to finish the command gracefully before exit.

#### service

$SLARUNNER_SERVICE

Name of the component service you're testing. This will be used as the prefix for s3 uploads, and will be passed in the JSON event as "service" to SNS.

#### groups

$SLARUNNER_GROUPS

Name of the grouping of components you're testing, in csv format. This will be passed in the JSON event as "groups" to SNS as a list, and is meant to provide secondary statistics if multiple services are part of the same component.

#### delay

$SLARUNNER_DELAY

How long to wait between commands being run in seconds.

#### disabled

$SLARUNNER_DISABLED

To disable sla-runner at startup.

#### sns-topic-arn

$SLARUNNER_SNSTOPICARN

SNS topic arn to publish results to. It will be published as a JSON object. For example, the command above would produce the following:

```json
{
    "service": "example-service",
    "group": ["dev-team", "critical"],
    "succeeded": true,
    "timestamp": "1574515200",
    "testExecutionSecs": "914"
}
```

#### s3-bucket-name

$SLARUNNER_S3BUCKETNAME

Bucket to write logs to. This is an optional parameter. The object will be named as the timestamp followed by the result for easily searching by result, and will be prefixed by the service name. For example "example-service/1574514000_SUCCESS"

#### dry-run

$SLARUNNER_DRYRUN

If there is any value at all in this variable, the test will run once, output the sns topic it would publish to, the result message, the log output of the command, and the name of the object that would be written to the bucket. It will NOT publish to sns or write the object to s3. Only for testing purposes.

## Development and Testing

```bash
docker build -t sla-runner:latest .
```

```bash
iam-docker-run \
    --image sla-runner:latest \
    --role sla-monitor-runner-role \
    --profile dev \
    --region us-east-1 \
    --host-source-path . \
    --container-source-path /src \
    --shell
```

## Publishing Updates to PyPi

For the maintainer - to publish an updated version of ssm-search, increment the version number in version.py and run the following:

docker build -t sla-runner . && \
docker run --rm -it --entrypoint make sla-runner publish

At the prompts, enter the username and password to the pypi.org repo.



%package -n python3-sla-runner
Summary:	A continuous test runner for gathering SLA data
Provides:	python-sla-runner
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-sla-runner
# SLA Monitor Worker

This is the test runner portion of the SLA monitor/reporter. It performs tests (or any command you want) repeatedly, and publishes success/failure to an SNS topic for external processing (for example, using lambda to write to a custom cloudwatch metric), as well as optionally uploading logs to an S3 bucket.

TODO: Unit tests not working

## Installing

To install simply install via pip

```bash
pip install --user sla-runner
```

Highly recommended is iam-docker run:

```bash
pip install --user iam-docker-run
```

This project assumes you are using role based authentication, as would be used in a production environment in AWS. This mimics that environment by running with an actual role.

## Terraform

Excute the following in the root folder to run terraform. Obviously, have Terraform installed. Set the bucket and table variables to existing backend resources for remote state.

```shell
# pip install iam-starter
cd terraform
export AWS_ENV="dev"
export TF_DATA_DIR="./.$AWS_ENV-terraform/"
export AWS_DEFAULT_REGION="us-east-1"
export TF_STATE_REGION="us-east-1"
export TF_STATE_BUCKET="mycompany-tfstate-$AWS_ENV"
export TF_STATE_TABLE="tfstate_$AWS_ENV"

iam-starter \
    --profile $AWS_ENV \
    --command \
        "terraform init \
        -backend-config=\"region=$TF_STATE_REGION\" \
        -backend-config=\"bucket=$TF_STATE_BUCKET\" \
        -backend-config=\"dynamodb_table=$TF_STATE_TABLE\" && \
        terraform apply \
        -var \"aws_env=$AWS_ENV\" \
        -var \"aws_region=$AWS_DEFAULT_REGION\""
```

## Using

Use iam-docker-run outside of AWS to run tests. In real life scenarios on ECS, instead install sla-runner via pypi in your service container, and set `--image` to the image of the service container which contains your test.

```bash
docker build -t sla-monitor/sla-runner:latest .

export AWS_ENV="dev"
iam-docker-run \
    -e SLARUNNER_COMMAND="/bin/bash /src/test-scripts/run-tests.sh" \
    -e SLARUNNER_SERVICE=example-service \
    -e SLARUNNER_GROUPS="dev-team,critical" \
    -e SLARUNNER_DELAY=30 \
    -e SLARUNNER_SNSTOPICNAME="sla-monitor-result-published-$AWS_ENV" \
    -e SLARUNNER_S3BUCKETNAME="sla-monitoring-logs-$AWS_ENV" \
    --full-entrypoint "sla-runner" \
    --region us-east-1 \
    --profile $AWS_ENV \
    --role sla-monitor-runner-role-$AWS_ENV \
    --image sla-monitor/sla-runner:latest
```

In ECS, add these as environment variables in the task definition or load from ssm via ssm-starter:

```
--full-entrypoint "ssm-starter --ssm-name slarunner --command 'sla-runner'"
```

## Variables

The runner takes the following values which are provided by environment variable. 

### Global variables

When loading variables via SSM and ssm-starter, you can define default variables by adding a globals path before the service path.

For example, in your task definition in terraform:

```json
    "entryPoint": ["ssm-starter"],
    "command": [
        "--ssm-name", "sla-monitor-globals",
        "--ssm-name", "${var.application}",
        "--command", "sla-runner" // or script that runs sla-runner
    ]
```

#### command

$SLARUNNER_COMMAND

Command to be run repeatedly. Pretty straightforward. If there is an interrupt, the runner will attempt to finish the command gracefully before exit.

#### service

$SLARUNNER_SERVICE

Name of the component service you're testing. This will be used as the prefix for s3 uploads, and will be passed in the JSON event as "service" to SNS.

#### groups

$SLARUNNER_GROUPS

Name of the grouping of components you're testing, in csv format. This will be passed in the JSON event as "groups" to SNS as a list, and is meant to provide secondary statistics if multiple services are part of the same component.

#### delay

$SLARUNNER_DELAY

How long to wait between commands being run in seconds.

#### disabled

$SLARUNNER_DISABLED

To disable sla-runner at startup.

#### sns-topic-arn

$SLARUNNER_SNSTOPICARN

SNS topic arn to publish results to. It will be published as a JSON object. For example, the command above would produce the following:

```json
{
    "service": "example-service",
    "group": ["dev-team", "critical"],
    "succeeded": true,
    "timestamp": "1574515200",
    "testExecutionSecs": "914"
}
```

#### s3-bucket-name

$SLARUNNER_S3BUCKETNAME

Bucket to write logs to. This is an optional parameter. The object will be named as the timestamp followed by the result for easily searching by result, and will be prefixed by the service name. For example "example-service/1574514000_SUCCESS"

#### dry-run

$SLARUNNER_DRYRUN

If there is any value at all in this variable, the test will run once, output the sns topic it would publish to, the result message, the log output of the command, and the name of the object that would be written to the bucket. It will NOT publish to sns or write the object to s3. Only for testing purposes.

## Development and Testing

```bash
docker build -t sla-runner:latest .
```

```bash
iam-docker-run \
    --image sla-runner:latest \
    --role sla-monitor-runner-role \
    --profile dev \
    --region us-east-1 \
    --host-source-path . \
    --container-source-path /src \
    --shell
```

## Publishing Updates to PyPi

For the maintainer - to publish an updated version of ssm-search, increment the version number in version.py and run the following:

docker build -t sla-runner . && \
docker run --rm -it --entrypoint make sla-runner publish

At the prompts, enter the username and password to the pypi.org repo.



%package help
Summary:	Development documents and examples for sla-runner
Provides:	python3-sla-runner-doc
%description help
# SLA Monitor Worker

This is the test runner portion of the SLA monitor/reporter. It performs tests (or any command you want) repeatedly, and publishes success/failure to an SNS topic for external processing (for example, using lambda to write to a custom cloudwatch metric), as well as optionally uploading logs to an S3 bucket.

TODO: Unit tests not working

## Installing

To install simply install via pip

```bash
pip install --user sla-runner
```

Highly recommended is iam-docker run:

```bash
pip install --user iam-docker-run
```

This project assumes you are using role based authentication, as would be used in a production environment in AWS. This mimics that environment by running with an actual role.

## Terraform

Excute the following in the root folder to run terraform. Obviously, have Terraform installed. Set the bucket and table variables to existing backend resources for remote state.

```shell
# pip install iam-starter
cd terraform
export AWS_ENV="dev"
export TF_DATA_DIR="./.$AWS_ENV-terraform/"
export AWS_DEFAULT_REGION="us-east-1"
export TF_STATE_REGION="us-east-1"
export TF_STATE_BUCKET="mycompany-tfstate-$AWS_ENV"
export TF_STATE_TABLE="tfstate_$AWS_ENV"

iam-starter \
    --profile $AWS_ENV \
    --command \
        "terraform init \
        -backend-config=\"region=$TF_STATE_REGION\" \
        -backend-config=\"bucket=$TF_STATE_BUCKET\" \
        -backend-config=\"dynamodb_table=$TF_STATE_TABLE\" && \
        terraform apply \
        -var \"aws_env=$AWS_ENV\" \
        -var \"aws_region=$AWS_DEFAULT_REGION\""
```

## Using

Use iam-docker-run outside of AWS to run tests. In real life scenarios on ECS, instead install sla-runner via pypi in your service container, and set `--image` to the image of the service container which contains your test.

```bash
docker build -t sla-monitor/sla-runner:latest .

export AWS_ENV="dev"
iam-docker-run \
    -e SLARUNNER_COMMAND="/bin/bash /src/test-scripts/run-tests.sh" \
    -e SLARUNNER_SERVICE=example-service \
    -e SLARUNNER_GROUPS="dev-team,critical" \
    -e SLARUNNER_DELAY=30 \
    -e SLARUNNER_SNSTOPICNAME="sla-monitor-result-published-$AWS_ENV" \
    -e SLARUNNER_S3BUCKETNAME="sla-monitoring-logs-$AWS_ENV" \
    --full-entrypoint "sla-runner" \
    --region us-east-1 \
    --profile $AWS_ENV \
    --role sla-monitor-runner-role-$AWS_ENV \
    --image sla-monitor/sla-runner:latest
```

In ECS, add these as environment variables in the task definition or load from ssm via ssm-starter:

```
--full-entrypoint "ssm-starter --ssm-name slarunner --command 'sla-runner'"
```

## Variables

The runner takes the following values which are provided by environment variable. 

### Global variables

When loading variables via SSM and ssm-starter, you can define default variables by adding a globals path before the service path.

For example, in your task definition in terraform:

```json
    "entryPoint": ["ssm-starter"],
    "command": [
        "--ssm-name", "sla-monitor-globals",
        "--ssm-name", "${var.application}",
        "--command", "sla-runner" // or script that runs sla-runner
    ]
```

#### command

$SLARUNNER_COMMAND

Command to be run repeatedly. Pretty straightforward. If there is an interrupt, the runner will attempt to finish the command gracefully before exit.

#### service

$SLARUNNER_SERVICE

Name of the component service you're testing. This will be used as the prefix for s3 uploads, and will be passed in the JSON event as "service" to SNS.

#### groups

$SLARUNNER_GROUPS

Name of the grouping of components you're testing, in csv format. This will be passed in the JSON event as "groups" to SNS as a list, and is meant to provide secondary statistics if multiple services are part of the same component.

#### delay

$SLARUNNER_DELAY

How long to wait between commands being run in seconds.

#### disabled

$SLARUNNER_DISABLED

To disable sla-runner at startup.

#### sns-topic-arn

$SLARUNNER_SNSTOPICARN

SNS topic arn to publish results to. It will be published as a JSON object. For example, the command above would produce the following:

```json
{
    "service": "example-service",
    "group": ["dev-team", "critical"],
    "succeeded": true,
    "timestamp": "1574515200",
    "testExecutionSecs": "914"
}
```

#### s3-bucket-name

$SLARUNNER_S3BUCKETNAME

Bucket to write logs to. This is an optional parameter. The object will be named as the timestamp followed by the result for easily searching by result, and will be prefixed by the service name. For example "example-service/1574514000_SUCCESS"

#### dry-run

$SLARUNNER_DRYRUN

If there is any value at all in this variable, the test will run once, output the sns topic it would publish to, the result message, the log output of the command, and the name of the object that would be written to the bucket. It will NOT publish to sns or write the object to s3. Only for testing purposes.

## Development and Testing

```bash
docker build -t sla-runner:latest .
```

```bash
iam-docker-run \
    --image sla-runner:latest \
    --role sla-monitor-runner-role \
    --profile dev \
    --region us-east-1 \
    --host-source-path . \
    --container-source-path /src \
    --shell
```

## Publishing Updates to PyPi

For the maintainer - to publish an updated version of ssm-search, increment the version number in version.py and run the following:

docker build -t sla-runner . && \
docker run --rm -it --entrypoint make sla-runner publish

At the prompts, enter the username and password to the pypi.org repo.



%prep
%autosetup -n sla-runner-0.0.21

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-sla-runner -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.21-1
- Package Spec generated