compat api per-revision (and non-revisioned) gives empty resources if charm was not released with resources explicitly

Bug #1971920 reported by Daniel Manrique
26
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Snap Store Server
Triaged
High
Unassigned

Bug Description

As an example, latest prometheus-ceph-exporter is -21:

$ curl -s "https://api.jujucharms.com/charmstore/v5/prometheus-openstack-exporter/meta/any"
{"Id":"cs:prometheus-openstack-exporter-21"}

trying to get resources for the revision gives borked stuff:

$ curl -s "https://api.jujucharms.com/charmstore/v5/prometheus-openstack-exporter/meta/resources" | jq
[
  {
    "Fingerprint": null,
    "Name": "core",
    "Path": "",
    "Revision": -1,
    "Size": 0,
    "Type": "file"
  },
  {
    "Fingerprint": null,
    "Name": "prometheus-openstack-exporter",
    "Path": "",
    "Revision": -1,
    "Size": 0,
    "Type": "file"
  }
]

So does hitting the revision directly:

 curl -s "https://api.jujucharms.com/charmstore/v5/prometheus-openstack-exporter-21/meta/resources" | jq
[
  {
    "Fingerprint": null,
    "Name": "core",
    "Path": "",
    "Revision": -1,
    "Size": 0,
    "Type": "file"
  },
  {
    "Fingerprint": null,
    "Name": "prometheus-openstack-exporter",
    "Path": "",
    "Revision": -1,
    "Size": 0,
    "Type": "file"
  }
]

The reason for this is that when releasing those revisions of the charm, the publisher did not specify the resources; so there are no resourcerevisionchannelmap records created.

As an example of how it should look, revision 11 is the last one that did have resources associated:

$ curl -s "https://api.jujucharms.com/charmstore/v5/prometheus-openstack-exporter-11/meta/resources" | jq
[
  {
    "Description": "Core snap, prerequisite of other snaps",
    "Fingerprint": "OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb",
    "Name": "core",
    "Path": "core.snap",
    "Revision": 0,
    "Size": 0,
    "Type": "file"
  },
  {
    "Description": "Prometheus OpenStack Exporter snap",
    "Fingerprint": "I13ObxYy8Lusl9LUo/cuA7F2Avlbj91KAhqpEwL9AvrJqEMr4IrMIjcUXczE6RGg",
    "Name": "prometheus-openstack-exporter",
    "Path": "prometheus-openstack-exporter.snap",
    "Revision": 1,
    "Size": 17420288,
    "Type": "file"
  }
]

We have seen that if a charm is released without specifying a resource, it ends up in the above situation:

charmcraft release openstack-service-checks --revision=9 --channel=stable

and the fix we've recommended is:

charmcraft release openstack-service-checks --revision=9 --channel=stable --resource=core18:1

to create the revisionresourcechannelmap entries as appropriate. This works well even specifying the same revision (it's just rereleasing same revision to same channel).

The main ask for this bug is to add the same behavior to compat API as we see in the native charmhub api: that is, if a charm with declared resources and at least one resource revision uploaded and ever released with a charm revision, should give that resource when queried via the compatibility API; this is effectively the old charmstore behavior "if a resource is not explicitly associated to a charm revision, we give out the latest resource available for that charm".

I have a vague recollection that behavior already works for the native API, as mentioned above, but it bears checking because I wasn't able to confirm this for the above charm.

Tags: charmhub
Daniel Manrique (roadmr)
tags: added: charmhub
Daniel Manrique (roadmr)
Changed in snapstore-server:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

The native charmhub API is also not returning resources:

❯ curl -X POST -H 'Content-Type: application/json' https://api.charmhub.io/v2/charms/refresh --data '{"context": [], "actions": [{"action": "install", "instance-key": "debug-lp-1971920-1", "id": "neyN3C9rov9kvST9H8iwdsj5nnkBRR4f", "base": {"name": "ubuntu", "channel": "20.04", "architecture": "amd64"}}]}' | jq
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 1061 100 856 100 205 1009 241 --:--:-- --:--:-- --:--:-- 1249
{
  "error-list": [],
  "results": [
    {
      "charm": {
        "created-at": "2022-03-17T16:21:16.904439+00:00",
        "download": {
          "hash-sha-256": "922589c904fa3990bd1b20d7972d41c8756e5b5d9eeebba21c9b0b773af3ad40",
          "size": 5334417,
          "url": "https://api.charmhub.io/api/v1/charms/download/neyN3C9rov9kvST9H8iwdsj5nnkBRR4f_21.charm"
        },
        "id": "neyN3C9rov9kvST9H8iwdsj5nnkBRR4f",
        "license": "",
        "name": "prometheus-openstack-exporter",
        "publisher": {
          "display-name": "Llama (LMA) Charmers",
          "id": "DmP1D2nqZmxqKFv5K5WOQERYKqV8qJuW",
          "username": "llama-charmers",
          "validation": "unproven"
        },
        "resources": [],
        "revision": 21,
        "summary": "Openstack exporter for Prometheus",
        "type": "charm",
        "version": "4456fe0"
      },
      "effective-channel": "stable",
      "id": "neyN3C9rov9kvST9H8iwdsj5nnkBRR4f",
      "instance-key": "this-is-a-test-1234",
      "name": "prometheus-openstack-exporter",
      "released-at": "2022-04-28T04:38:42.544691+00:00",
      "result": "install"
    }
  ]
}

Daniel Manrique (roadmr)
Changed in snapstore-server:
status: Confirmed → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.