Skip to content

Commit 1e8a8b0

Browse files
committed
Rebuild SARA around generic Analysis pipeline
Replace per-handler legacy services and per-domain notification controllers with a generic three-tier model: Analysis (use-case), Workflow (step), AnalysisRun (execution attempt). Inspections become first-class InspectionRecord entities. Result handlers move into WorkflowResultHandlers and AnalysisResultHandlers folders. The Argo trigger payload carries a stable core (workflowId, inputBlobStorageLocations, outputBlobStorageLocation) plus an extras object populated by ITriggerPayloadEnricher implementations matched on WorkflowType (empty when no enricher matches). This lets analyzer images extend their per-workflow schema without coordinated changes to analytics-infrastructure WorkflowTemplates and Sensors. Workflow chains are supported via appsettings.json (e.g. ["anonymizer", "thermal-reading"]); each step's output becomes the next step's input by default. The anonymizer enricher emits preProcessedBlobStorageLocation (TIFF on the anon storage account), and AnonymizerResultHandler rewires the next workflow's inputs to that TIFF when the next step is thermal-reading; otherwise the chain is left untouched. Add correlation IDs (workflow_id, analysis_run_id, analysis_id) to the SaraVisualizationAvailable and SaraAnalysisResult MQTT messages. Mirror the Pose/Position model with Flotilla. Rewrite workflow-notifier as a generic CLI with started, result, and exited subcommands; drop the per-domain commands. The exited subcommand now takes error_message as a third positional so {{workflow.failures}} can be passed verbatim. Drop the dead Error value from WorkflowExitStatus on both Python and C# sides. Add an integration test suite using Postgres Testcontainers with per-test isolation. Add EF migration for the new schema. Implements: #353
1 parent e9aca54 commit 1e8a8b0

148 files changed

Lines changed: 13322 additions & 9596 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ api/wwwroot/
4444

4545
AGENTS.md
4646

47+
# Throwaway local fixtures (DB dumps used by ad-hoc migration tests)
48+
api.Tests/tmp/
49+
4750
# macOS
4851
.DS_Store
4952

README.md

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,84 @@
11
# Storage and Analysis of Robot Acquired plant data
22

3-
SARA (Storage and Analysis of Robot Acquired plant data) is a web service that facilitates
4-
the processing of incoming plant data from autonomous robots. Various workflows will be
5-
triggered to analyse the plant data, based on metadata provided. The workflows themselves
6-
are not in the scope of this solution. This solution only needs to have an overview of
7-
which workflows are available and how to call them with their API.
8-
9-
SARA is responsible for indexing the incoming data, including information on where the
10-
raw data is stored, which analysis are to be run, the status on these, where to
11-
temporarily store artifacts and where to store the finalized results and visualizations.
12-
SARA can then be queried later from other solutions and use the indexing to look up data and
13-
generate a response.
14-
15-
Examples of plant data are pictures, videos, thermal pictures, thermal videos and audio.
16-
17-
The resulting service is available in three environments (development, staging and production).
18-
19-
When running locally the endpoint can be reached at https://localhost:8100.
20-
21-
## Services
22-
23-
SARA uses several services to upload data to other sources for storage or analysis.
24-
A list of these services can be found below.
25-
26-
- [Sara Timeseries](https://github.com/equinor/sara-timeseries/)
27-
- [Sara Anonymizer](https://github.com/equinor/sara-anonymizer/)
28-
29-
## Workflow
30-
31-
There will be several analysis available for SARA. These are triggered through an
32-
Argo Workflow which can have a conditional flow based on the type of inspection.
33-
34-
```
35-
anonymizer-->constant-level-oiler
36-
\-->stid-uploader
3+
SARA (Storage and Analysis of Robot Acquired plant data) is an ASP.NET Core
4+
Web API that indexes inspection data published by ISAR and orchestrates
5+
Argo-based analysis workflows on it, exposing the results to Flotilla. Each
6+
incoming inspection becomes an `InspectionRecord`; one or more records are
7+
grouped into an `Analysis` (the use-case), which executes as an `AnalysisRun`
8+
made up of one or more sequential `Workflow` steps.
9+
10+
When running locally the endpoint is reachable at https://localhost:8100
11+
(`/` redirects to Swagger).
12+
13+
## Architecture at a glance
14+
15+
- `InspectionRecord` -- one row per ISAR inspection result, persisted on
16+
receipt of an `isar/+/inspection_result` MQTT message.
17+
- `Analysis` -> `AnalysisRun` -> `Workflow` -- three-tier model where an
18+
Analysis describes the use-case, an AnalysisRun is one execution attempt,
19+
and each Workflow is a single Argo step.
20+
- `AnalysisGroup` -- lets a single Analysis span multiple InspectionRecords.
21+
The group is buffered until all expected records arrive or
22+
`AnalysisGroupTimeoutMinutes` elapses.
23+
- Workflow chains run sequentially. By default each step's output blob
24+
becomes the next step's input; per-workflow rewiring lives in the matching
25+
`IWorkflowResultHandler`.
26+
- The Argo trigger payload has a stable core (`workflowId`,
27+
`inputBlobStorageLocations`, `outputBlobStorageLocation`) plus an `extras`
28+
object populated by `ITriggerPayloadEnricher` implementations matched on
29+
workflow type.
30+
- Result handling is split: `WorkflowResultHandlers/` runs per step,
31+
`AnalysisResultHandlers/` runs once the whole Analysis is done.
32+
33+
## Run locally
34+
35+
```bash
36+
make run # or: dotnet run --project api
3737
```
3838

39-
## Analysis Mapping
4039

41-
Which analysis pipeline is run is chosen by the analysis mapping. A tag + an insepction descripts maps to an analysis type.
42-
To add a new analysis type, add a value to the [AnalysisType](api/Database/Models/Analysis.cs) enum. Then add which tag + inspection description should map to the new AnalysisType. This can be done through the [AddOrCreateAnalysisMapping](api/Controllers/AnalysisMappingController.cs) endpoint. Then include code in the [MqttEventHandler](api/MQTT/MqttEventHandler.cs) to run the desiered pipeline for you AnalysisType. At the moment the supported analysis types are:
40+
## Test & format
4341

44-
- Anonymizer
45-
- ConstantLevelOiler
46-
- ThermalReading
47-
48-
At the moment Anonymizer is configured to always run on IsarInspectionResultMessage
49-
50-
## Run
51-
52-
To build and run SARA, run the following command in the root folder:
53-
54-
```
55-
dotnet run --project api
42+
```bash
43+
make test # xUnit; integration tests use Postgres Testcontainers (Docker required)
44+
make format # CSharpier
5645
```
5746

58-
## Running the argo workflow mock
5947

60-
`python mocks/argo_workflow_mock.py`
48+
## Creating a new workflow
49+
50+
1. Register the workflow under `Analysis:Workflows` in `appsettings.json`
51+
with its `TriggerUrl`, `OutputStorageAccount`, `OutputBlobContainer` and
52+
(optionally) `OutputFileExtension`.
53+
2. Reference it from one or more chains under `Analysis:Analyses`, e.g.
54+
`"my-analysis": { "Workflows": ["anonymizer", "my-workflow"] }`.
55+
3. Add an `IWorkflowResultHandler` in
56+
`api/Services/ResultHandlers/WorkflowResultHandlers/` that matches the
57+
new workflow type.
58+
4. If the analyzer needs per-workflow parameters in the Argo trigger
59+
payload, add an `ITriggerPayloadEnricher` that populates `extras`.
60+
5. Add the matching Argo `WorkflowTemplate` + `Sensor` in
61+
[analytics-infrastructure](https://github.com/equinor/analytics-infrastructure)
62+
and an analyzer image repo that implements the generic CLI contract
63+
(`--input-blob-storage-locations`, `--output-blob-storage-location`,
64+
`--extras`).
65+
66+
## workflow-notifier
67+
68+
`workflow-notifier/` is a standalone Python CLI, shipped as its own Docker
69+
image and invoked from inside Argo `WorkflowTemplate` steps. It exposes
70+
three subcommands -- `started`, `result` and `exited` -- each of which
71+
performs an authenticated `PUT` against `/api/workflow/{id}/...` so SARA can
72+
track workflow progress and persist results.
73+
74+
## Analyzer services
75+
76+
- [sara-anonymizer](https://github.com/equinor/sara-anonymizer/) -- anonymizes images
77+
- [sara-thermal-reading](https://github.com/equinor/sara-thermal-reading/) -- extracts temperatures from thermal images
78+
- [sara-fence-detection](https://github.com/equinor/sara-fence-detection/) -- detects fence breaches
79+
- [sara-constant-level-oiler](https://github.com/equinor/sara-constant-level-oiler/) -- reads constant-level oiler spherical glasses
80+
- [sara-timeseries](https://github.com/equinor/sara-timeseries/) -- timeseries ingestion
81+
- [sara-sap](https://github.com/equinor/sara-sap/) -- SAP integration
6182

6283
## Deployments
6384

@@ -68,13 +89,3 @@ We currently have 3 environments (Development, Staging, and Production) deployed
6889
| Development | [Backend](https://shared.dev.aurora.equinor.com/sara-dev-backend/swagger/index.html) |
6990
| Staging | [Backend](https://shared.aurora.equinor.com/sara-staging-backend/swagger/index.html) |
7091
| Production | [Backend](https://shared.aurora.equinor.com/sara-prod-backend/swagger/index.html) |
71-
72-
## More documentation
73-
74-
See the `/docs` folder for more documentation, for example
75-
76-
- [Deploying resources](docs/deploying_resources.md)
77-
- [Database and migrations](docs/database_and_migrations.md)
78-
- [Formatting](docs/formatting.md)
79-
80-

api.Tests/Controller/AnalysisMappingController.cs

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)