This topic uses a DevOps scenario to demonstrate how to develop entity and relational data step-by-step based on business requirements.
Development flow overview
Developing entity and relational data follows a standard flow:
Step | Entity development | Relationship development |
1. Define the schema | Define an EntitySet | Define an EntitySetLink |
2. Implement data collection | Get entity data from a data source | Generate relationships from entity data or configurations |
3. Transform the data | Map fields and generate an entity_id | Match source and destination entity_ids |
4. Upload the data | Upload to the | Upload to the |
Example of DevOps scenario development
This section uses a common microservice DevOps scenario to demonstrate the complete development flow for entities and relationships.
Typical DevOps flow:
Development stage: Developers create and manage code repositories on the DevOps platform.
Release stage: After code is merged, a tag and a code release record are created.
Build stage: The Continuous Integration (CI) flow builds a container image based on the code release.
Storage stage: The container image is pushed to an ACR image repository.
Deployment stage: Kubernetes (K8s) pulls the image from the image repository and deploys pod instances.
Monitoring stage: The Application Performance Management (APM) system monitors the performance of running services.
The complete code for this scenario is available in umodel_and_codes.zip. The project directory is structured as follows:
├── devops_data_generator/ # Main directory for the data generator
│ ├── config/ # Configuration files
│ │ ├── app_config.yaml # Application configuration (API credentials, SLS configuration, etc.)
│ │ ├── data_mapping.yaml # Entity/relationship field mapping configuration
│ │ ├── static_topo.yaml # Static relationship configuration
│ │ └── repo_image_mapping.yaml # Code repository to image repository mapping
│ ├── tasks/ # Task implementations
│ │ ├── developer_task.py # Developer entity generation
│ │ ├── code_repository_task.py # Code repository entity generation
│ │ ├── code_release_task.py # Code release entity generation
│ │ ├── image_registry_task.py # Image repository entity generation
│ │ ├── image_task.py # Image entity generation
│ │ ├── kubernetes_pod_task.py # Pod entity generation
│ │ ├── developer_manages_code_repository_task.py # "manages" relationship generation
│ │ ├── code_release_sourced_from_code_repository_task.py # "sourced_from" relationship for releases
│ │ ├── image_sourced_from_code_release_task.py # "sourced_from" relationship for images
│ │ ├── image_registry_contains_image_task.py # "contains" relationship
│ │ ├── pod_uses_image_task.py # "uses" relationship generation
│ │ └── static_topo_task.py # Static relationship processing
│ ├── generator/ # Data generator
│ │ └── sls_data_generator.py # SLS data format transformation
│ ├── sender/ # Data sender
│ │ └── sls_data_sender.py # SLS data upload
│ ├── shared/ # Shared components
│ │ └── data_context.py # Data sharing between tasks
│ ├── orchestrator.py # Task orchestrator
│ ├── main.py # Command line entry point
│ ├── app.py # Flask API entry point
│ ├── Dockerfile # Docker build file
│ ├── Makefile # Quick operation commands
│ └── requirements.txt # Python dependencies
└── umodel/ # UModel schema definitions
├── entity_set/ # Entity definitions
│ ├── devops_devops.developer.yaml
│ ├── devops_devops.code_repository.yaml
│ ├── devops_devops.code_release.yaml
│ ├── devops_devops.image_registry.yaml
│ └── devops_devops.image.yaml
└── entity_set_link/ # Relationship definitions
├── devops.developer_manages_devops.code_repository.yaml
├── devops.code_release_sourced_from_devops.code_repository.yaml
├── devops.image_sourced_from_devops.code_release.yaml
├── devops.image_registry_contains_devops.image.yaml
└── k8s.pod_uses_devops.image.yamlA complete introduction to the development process for all entities and relationships in this scenario would be too long. Therefore, this topic uses the developer entity and the manages relationship as an example to demonstrate the full development process, from schema definition to data upload. The development flows for UModel entity modeling, relationship modeling, data collection, and upload policies are universal. For the specific implementation of other entities and relationships, see the code directory mentioned above.
Step 1: Define the schema
Define the developer entity schema.
Define the manages relationship schema.
Step 2: Implement data collection
Retrieve raw data for the developer entity from the data source, determine the upload policy, and write the code.
Data source and collection method: Collect data from the DevOps API.
Data source: Alibaba Cloud DevOps API - ListRepositoryMemberWithInherited.
Collection method: Traverse all code repositories, retrieve the members, and remove duplicates.
Upload policy: Because personnel changes are infrequent, the data volume is small (only a few hundred people), and the cost of a full upload is low, the recommended policy is a scheduled full upload.
Execution frequency: Because the data changes slowly, once a day is sufficient.
KeepAlive: 2 days (172,800 seconds). This is twice the full upload epoch to prevent data loss if a task fails.
Retrieve raw data for the manages relationship from the data source, determine the upload policy, and write the code.
Data source and collection method: Retrieve the relationship where developers manage code repositories.
Data source: A YAML configuration file that defines the relationship (developer to code repository).
Collection method: Associate static configurations using existing entity IDs.
Upload policy: Because the manages relationship is relatively stable, changes infrequently, and the data source is a manually maintained static configuration file, the recommended policy is a scheduled full upload.
Execution frequency: Once per hour to promptly sync configuration changes.
KeepAlive: 2 hours. This value is twice the full cycle period to prevent task failures.
Step 3: Transform the data
Write code to transform the raw data into the EntityStore format.
Step 4: Upload the data
Use the Simple Log Service (SLS) SDK to upload data to the destination Logstore.
Upload the entity and relationship data.
ImportantUpload data in batches to improve performance, for example, 1,000 records per batch.
All field values must be converted to strings.
Add exception handling and log recording.
Related reference
Data collection for other entities
The following table lists the entity types involved in the DevOps scenario demo. In a real project, you can select the appropriate entities and adjust the data sources and collection methods as needed.
The DevOps scenario includes multiple entity types. Different collection methods are used for different data sources:
DevOps entities (collected from the Alibaba Cloud DevOps API)
Entity type | Description | Data source | Collection method |
| Code repository | DevOps API | List all repositories in the organization |
| Code release | DevOps API | Get the list of repository tags |
| Developer | DevOps API | Traverse repository members and remove duplicates |
Container image entities (collected from Alibaba Cloud ACR)
Entity type | Description | Data source | Collection method |
| Image repository | ACR API | List image repositories |
| Container image | ACR API | Traverse repositories to get image tags |
K8s entities (collected from CloudMonitor (CMS))
Entity type | Description | Data source | Collection method |
| K8s pod | CMS metric query | Query pod entity data |
Generation methods for other relationships
The following tables list the relationship types involved in the DevOps scenario demo. In a real project, you can select the appropriate relationship types based on the business associations between entities and configure the corresponding generation rules.
Relationships in the DevOps scenario can be divided into static relationships and dynamic relationships based on their generation method:
Static relationships (based on configuration files)
Relationship type | Source entity | Target entity | Configuration method | Data source |
| Developer | Code repository | YAML configuration file |
|
| APM service | Code repository | YAML configuration file |
|
| APM service | Code release | Hybrid relationship (static + dynamic) |
|
| Developer | APM service | Hybrid relationship (static + dynamic) |
|
| Developer | Image repository | Dynamic to dynamic |
|
Dynamic relationships (based on data association)
Relationship type | Source entity | Destination entity | Join type | Matching rule |
| Code release | Code repository | Field matching | Associate by repo_id |
| Container image | Image repository | Field matching | Associate by registry_id |
| Container image | Code release | Tag matching | Match image tag with release tag |
| Image repository | Container image | Field matching | Associate by registry_id |
| K8s pod | Container image | Image name matching | Match pod container image with image entity |
Reference for entity and relationship upload policies
The following table shows example upload policy configurations for the DevOps scenario demo. In a real project, you can adjust the policy type, execution frequency, and KeepAlive time based on factors such as data change frequency, data volume, and real-time business requirements.
Entity/Relationship | Policy | Frequency | KeepAlive | Data source |
devops.developer | Scheduled full | Once per day | 2 days | DevOps API |
devops.code_repository | Scheduled full | 1 hour | 2 hours | DevOps API |
devops.code_release | Scheduled incremental | 5 minutes | 2 hours | DevOps API |
devops.image_registry | Scheduled full | 1 hour | 2 hours | ACR API |
devops.image | Scheduled incremental | 30 minutes | 2 hours | ACR API |
k8s.pod | Real-time query | 5 minutes | 10 minutes | K8s server |
developer manages code_repository | Scheduled full | Every hour | 2 hours | Configuration file |
code_release sourced_from code_repository | Scheduled incremental | 5 minutes | 2 hours | Field association |
image sourced_from image_registry | Scheduled incremental | 30 minutes | 2 hours | Field association |
image sourced_from code_release | Scheduled incremental | 30 minutes | 2 hours | Tag matching |
image_registry contains image | Scheduled incremental | 30 minutes | 2 hours | Field association |
pod uses image | Real-time query | 5 minutes | 10 minutes | Image name matching |
apm.service sourced_from code_repository | Scheduled full | 4 hours | 8 hours | Configuration file |