Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(units): state methods for unit agent/workload/container status #18138

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

wallyworld
Copy link
Member

@wallyworld wallyworld commented Sep 25, 2024

Adds state methods for saving and deleting status for:

  • unit agents
  • unit workloads
  • unit cloud container

Due to the transition towards using UUID, the status methods take a unit UUID to work with. So a GetUnitUUID method is added to lookup UUID from the unit name - this will be used when the service logic is implemented.

Also adds a missing unit agent status enum for error.

QA steps

Just unit tests

Links

Jira card: JUJU-6777
Jira card: JUJU-6803

@hpidcock hpidcock added the 4.0 label Sep 25, 2024
// and associated information.
type CloudContainerStatusStatusInfo struct {
StatusID CloudContainerStatusType
Message string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make these last three fields into a type that is embedded in the different status types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the plan eventually. I wanted to let things like machine status, storage status etc emerge first so that we could make a more informed call if we wanted to introduce a top level domain status package with the aforementioned core type and any other required artefacts. Since this is the first cab off the rank, I was ok with doing it this way initially; it's only 3 attributes with no behaviour attached to them. I can introduce a suitable type here pending subsequent refactoring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would only be useful if there is common logic around status that is useful when decomposed without StatusID.

I'd prefer this to become a generic type. All statues should have the same shape.

type StatusInfo[StatusType any] struct {
	StatusID StatusType
	Message  string
	Data     map[string]string
	Since    time.Time
}

type CloudContainerStatusStatusInfo = StatusInfo[CloudContainerStatusType]
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was deliberately avoiding optimising too much and introducing a generic status type until we had more use cases outside this domain. We already have status in core. The types that are defined here are purely to act as parameters to the calls to state. They are not used outside the application package. They are just DTOs with no behaviour. Any changes to how status is used outside this package needs to start with core status and be done holistically.

// saveStatusData saves the status key value data for the specified unit in the specified table.
// It's called from each different SaveStatus method which previously has confirmed the unit UUID exists.
func (st *ApplicationState) saveStatusData(ctx context.Context, tx *sqlair.TX, table, unitUUID string, data map[string]string) error {
unit := coreUnit{ID: unitUUID}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name for this type is poor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming is hard. The struct holds just "core" or minimal attributes of a unit - uuid, name, life, net node uuid. Maybe "minimalUnit". I'll have a think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coreUnit is terrible because it clashes with similarly named coreunit (which you have as an aliased package in this very file) and the concept of "core" when it comes to juju.

Something like:

  • basicUnit
  • minimalUnit
  • unitIntrinsics

IDK. I wouldn't think about it to hard, it is an unexported concept.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already changed to minimalUnit

Copy link
Member

@hpidcock hpidcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank-you for the changes. Happy to be second +1.

@wallyworld
Copy link
Member Author

/merge

@jujubot jujubot merged commit c5cc78d into juju:main Sep 26, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants