<commit_before># API

## Incidents

API server can perform several types of tasks against a subset of instances in several deployments. Types of tasks and selection of instances is represented by an incident.

See 'Incident Types' section below for details on which task types are available.

Instance selection is based on `Deployments` (array of hashes; required) configuration. An incident may affect one or deployments from which one or more jobs can be selected. For each job selected, its instances are filtered via `Indices` (array of ints) or `Limit` (string) keys. Limit value may be one of the following:

- `10`: kill 10 *random* instances
- `5-10`: kill 5-10 *random* instances
- `10%`: kill random 10% of instances
- `5%-10%`: kill random 5% to 10% of instances

Endpoints:

- `POST /api/v1/incidents`
- `GET /api/v1/incidents`
- `GET /api/v1/incidents/:id`

```
$ curl -vvv -k -X POST https://user:pass@10.244.8.2:8080/api/v1/incidents -H 'Accept: application/json' -d@example.json
```

See [docs/kill.sh](kill.sh) for live example.

Create request:

```json
{
	"Tasks": [{
		"Type": "stress",
		"Timeout": "10m",

		"NumCPUWorkers": 1
	}],

	"Selector": {
		"Deployment": {
			"Name": "cf"
		},
		"Group": {
			"Name": "postgres",
		},
		"ID": {
			"Limit": "30%"
		}
	}
}
```

Response:

```json
{
  "ID": "d77adc3b-1de4-4e12-4bee-b325adfbecbd",

  "Tasks": [ ... ],
  "Selector": { ... },

  "ExecutionStartedAt": "0001-01-01T00:00:00Z",
  "ExecutionCompletedAt": "",

  "Events": null
}
```

Available selector rules:

- AZ
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- Deployment
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- Group
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- ID
  - set `In` (array of strings; optional)
  - set `Limit` (string; optional)

Limits default to 100%. Name defaults to '*' and wildcard matches are supported.

```json
{
	"AZ": {
		"Name": "z1",
		"Limit": "5"
	},
	"Deployment": {
		"Name": "cf-*",
		"Limit": "5"
	},
	"Group": {
		"Name": "postgres",
		"Limit": "5"
	},
	"ID": {
		"In": ["53c5ae69-4622-4103-9766-230adcf3baef"],
		"Limit": "5"
	}
}
```

---<commit_msg>It is ID.Values, not ID.In<commit_after># API

## Incidents

API server can perform several types of tasks against a subset of instances in several deployments. Types of tasks and selection of instances is represented by an incident.

See 'Incident Types' section below for details on which task types are available.

Instance selection is based on `Deployments` (array of hashes; required) configuration. An incident may affect one or deployments from which one or more jobs can be selected. For each job selected, its instances are filtered via `Indices` (array of ints) or `Limit` (string) keys. Limit value may be one of the following:

- `10`: kill 10 *random* instances
- `5-10`: kill 5-10 *random* instances
- `10%`: kill random 10% of instances
- `5%-10%`: kill random 5% to 10% of instances

Endpoints:

- `POST /api/v1/incidents`
- `GET /api/v1/incidents`
- `GET /api/v1/incidents/:id`

```
$ curl -vvv -k -X POST https://user:pass@10.244.8.2:8080/api/v1/incidents -H 'Accept: application/json' -<EMAIL>
```

See [docs/kill.sh](kill.sh) for live example.

Create request:

```json
{
	"Tasks": [{
		"Type": "stress",
		"Timeout": "10m",

		"NumCPUWorkers": 1
	}],

	"Selector": {
		"Deployment": {
			"Name": "cf"
		},
		"Group": {
			"Name": "postgres",
		},
		"ID": {
			"Limit": "30%"
		}
	}
}
```

Response:

```json
{
  "ID": "d77adc3b-1de4-4e12-4bee-b325adfbecbd",

  "Tasks": [ ... ],
  "Selector": { ... },

  "ExecutionStartedAt": "0001-01-01T00:00:00Z",
  "ExecutionCompletedAt": "",

  "Events": null
}
```

Available selector rules:

- AZ
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- Deployment
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- Group
  - set `Name` (string; optional)
  - set `Limit` (string; optional)

- ID
  - set `Values` (array of strings; optional)
  - set `Limit` (string; optional)

Limits default to 100%. Name defaults to '*' and wildcard matches are supported.

```json
{
	"AZ": {
		"Name": "z1",
		"Limit": "5"
	},
	"Deployment": {
		"Name": "cf-*",
		"Limit": "5"
	},
	"Group": {
		"Name": "postgres",
		"Limit": "5"
	},
	"ID": {
		"Values": ["53c5ae69-4622-4103-9766-230adcf3baef"],
		"Limit": "5"
	}
}
```

---
{'fraction_non_alphanumeric': 0.17709750566893423, 'fraction_numerical': 0.04308390022675737, 'mean_word_length': 3.4465725806451615, 'pattern_counts': {'":': 58, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604374', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1626, 'n_words': 498}