Skip to content

Commit

Permalink
Add entity status structs (#50)
Browse files Browse the repository at this point in the history
Backstage _may_ export information on entity Status, this PR adds
support for that.
  • Loading branch information
tdabasinskas committed Jun 10, 2024
2 parents 0d69e40 + ac853e2 commit ecf92c3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
43 changes: 43 additions & 0 deletions backstage/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type Entity struct {

// Relations that this entity has with other entities.
Relations []EntityRelation `json:"relations,omitempty"`

// The current status of the entity, as claimed by various sources.
Status *EntityStatus `json:"status,omitempty"`
}

// EntityMeta represents metadata fields common to all versions/kinds of entity.
Expand Down Expand Up @@ -108,6 +111,46 @@ type EntityRelationTarget struct {
Namespace string `json:"namespace"`
}

// EntityStatus informs current status of the entity, as claimed by various sources.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatus struct {
// A specific status item on a well known format.
Items []EntityStatusItem `json:"items,omitempty"`
}

// EntityStatusItem contains a specific status item on a well known format.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatusItem struct {
// The item type
Type string `json:"type"`

// The status level / severity of the status item.
// Either ["info", "warning", "error"]
Level string `json:"level"`

// A brief message describing the status, intended for human consumption.
Message string `json:"message"`

// An optional serialized error object related to the status.
Error *EntityStatusItemError `json:"error"`
}

// EntityStatusItemError has aA serialized error object.
// https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/shared/common.schema.json
type EntityStatusItemError struct {
// The type name of the error"
Name string `json:"name"`

// The message of the error
Message string `json:"message"`

// An error code associated with the error
Code *string `json:"code"`

// An error stack trace
Stack *string `json:"stack"`
}

// ListEntityOrder defines a condition that can be used to order entities.
type ListEntityOrder struct {
// Direction is the direction to order by.
Expand Down
39 changes: 39 additions & 0 deletions backstage/testdata/entities.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,44 @@
"relations":[

]
},
{
"metadata":{
"namespace":"default",
"annotations":{
"backstage.io/managed-by-location":"file:/private/tmp/back/examples/org.yaml",
"backstage.io/managed-by-origin-location":"file:/private/tmp/back/examples/org.yaml"
},
"name":"generated-aa156660b91ff3cfa0819c08e413581e6d4e4136",
"uid":"f5e4edef-f547-430d-8fee-13f4919888b7",
"etag":"d9b5d5f05fe7901d90c68b62a9b2d30b3f9f0f87"
},
"apiVersion":"backstage.io/v1alpha1",
"kind":"Location",
"spec":{
"type":"file",
"target":"/private/tmp/back/examples/org.yaml"
},
"relations":[

],
"status": {
"items": [
{
"type": "backstage.io/catalog-processing",
"level": "error",
"message": "SomeError: it broke",
"error": {
"name": "SomeError",
"message": "Error message",
"cause": {
"name": "Error",
"message": "error message",
"stack": "stack trace"
}
}
}
]
}
}
]

0 comments on commit ecf92c3

Please sign in to comment.