Skip to content

Commit

Permalink
Merge pull request juju#17919 from amandahla/add-charm-rev-status
Browse files Browse the repository at this point in the history
juju#17919

<!-- 
The PR title should match: <type>(optional <scope>): <description>.

Please also ensure all commits in this PR comply with our conventional commits specification:
https://docs.google.com/document/d/1SYUo9G7qZ_jdoVXpUVamS5VCgHmtZ0QA-wZxKoMS-C0 
-->

With this change will be possible get the revision from an Application.

Note: I'm targeting 3.1 since per CONTRIBUTING it should be targeted at the lowest version affected. Please let me know if a different one should be targeted instead.

## Checklist

<!-- If an item is not applicable, use `~strikethrough~`. -->
- [x] Code style: imports ordered, good names, simple structure, etc
- [ ] Comments saying why design decisions were made
- [ ] Go unit tests, with comments saying what you're testing
- [ ] [Integration tests](https://github.com/juju/juju/tree/main/tests), with comments saying what you're testing
- [ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages

## QA steps

While creating a third-party client, is possible to get charm revision like this:
```
func (r *registry) parseStatus(status *params.FullStatus) {
 for applicationName, application := range status.Applications {
 r.jujuApplications.With(prometheus.Labels{
 "name": applicationName,
 "status": application.Status.Status,
 "channel": application.CharmChannel,
 "revision": application.CharmRev,
 }).Set(checkStatus(application.Status.Status, []string{"active"}))
...
```

## Documentation changes

No changes.

## Links

To be used in https://github.com/neoaggelos/juju_exporter

**Launchpad bug:** https://bugs.launchpad.net/juju/+bug/

**Jira card:** JUJU-
  • Loading branch information
jujubot authored Oct 18, 2024
2 parents f3ab32c + f66323f commit 218a596
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apiserver/facades/client/client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ var scenarioStatus = &params.FullStatus{
},
Applications: map[string]params.ApplicationStatus{
"logging": {
Charm: "local:quantal/logging-1",
Base: params.Base{Name: "ubuntu", Channel: "12.10/stable"},
Charm: "local:quantal/logging-1",
CharmRev: 1,
Base: params.Base{Name: "ubuntu", Channel: "12.10/stable"},
Relations: map[string][]string{
"logging-directory": {"wordpress"},
},
Expand All @@ -212,6 +213,7 @@ var scenarioStatus = &params.FullStatus{
},
"mysql": {
Charm: "local:quantal/mysql-1",
CharmRev: 1,
Base: params.Base{Name: "ubuntu", Channel: "12.10/stable"},
Relations: map[string][]string{},
SubordinateTo: []string{},
Expand All @@ -229,8 +231,9 @@ var scenarioStatus = &params.FullStatus{
},
},
"wordpress": {
Charm: "local:quantal/wordpress-3",
Base: params.Base{Name: "ubuntu", Channel: "12.10/stable"},
Charm: "local:quantal/wordpress-3",
CharmRev: 3,
Base: params.Base{Name: "ubuntu", Channel: "12.10/stable"},
Relations: map[string][]string{
"logging-dir": {"logging"},
},
Expand Down
1 change: 1 addition & 0 deletions apiserver/facades/client/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ func (context *statusContext) processApplication(application *state.Application)
Charm: applicationCharm.URL(),
CharmVersion: applicationCharm.Version(),
CharmProfile: charmProfileName,
CharmRev: applicationCharm.Revision(),
CharmChannel: channel,
Base: params.Base{
Name: base.OS,
Expand Down
3 changes: 3 additions & 0 deletions apiserver/facades/client/client/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,12 +1124,15 @@ func (s *CAASStatusSuite) TestStatusCloudContainerSet(c *gc.C) {

func (s *CAASStatusSuite) assertUnitStatus(c *gc.C, appStatus params.ApplicationStatus, status, info string) {
curl, _ := s.app.CharmURL()
parsedCurl, err := charm.ParseURL(*curl)
c.Assert(err, jc.ErrorIsNil)
workloadVersion := ""
if info != "installing agent" && info != "blocked" {
workloadVersion = "gitlab/latest"
}
c.Assert(appStatus, jc.DeepEquals, params.ApplicationStatus{
Charm: *curl,
CharmRev: parsedCurl.Revision,
Base: params.Base{Name: "ubuntu", Channel: "20.04/stable"},
WorkloadVersion: workloadVersion,
Relations: map[string][]string{},
Expand Down
3 changes: 3 additions & 0 deletions apiserver/facades/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16238,6 +16238,9 @@
"charm-profile": {
"type": "string"
},
"charm-rev": {
"type": "integer"
},
"charm-version": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions rpc/params/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type ApplicationStatus struct {
CharmVersion string `json:"charm-version"`
CharmProfile string `json:"charm-profile"`
CharmChannel string `json:"charm-channel,omitempty"`
CharmRev int `json:"charm-rev,omitempty"`
Base Base `json:"base"`
Exposed bool `json:"exposed"`
ExposedEndpoints map[string]ExposedEndpoint `json:"exposed-endpoints,omitempty"`
Expand Down

0 comments on commit 218a596

Please sign in to comment.