Use fixed size integers

Created by: ash2k

I've noticed that a lot of the structs for JSON/API types use int. int is 32 bits on 32 bit systems and will not fit 64 bit values that are used for some fields (i.e. bigint in the DB). Also note that Rails by default uses 64 bit bigint for primary (and hence foreign) keys since 5.1.

I think there are at least these ways to address this issue:

  • Change all ints to int64.
    • Pro: simple to implement the change
    • Pro: simple to maintain consistency - all integer columns are always represented as int64 type, even if they are 32 bit in the DB.
    • Pro (minor): future-proof. If GitLab updates the schema to use 64 bit instead of 32 bit for a field, code does not need to change.
    • Con: More memory consumption (does not matter as it's negligible)
  • Change specific fields to int32 or int64 depending on the DB schema GitLab uses.
    • Con: it's hard to figure out how many bits each field needs from the DB schema because the schema is gigantic and is hard to navigate. Also, API response may not necessarily map to DB schema directly.
    • Con (minor): not future-proof.
  • Use OpenAPI to generate structs for Go. I don't know if GitLab exposes an OpenAPI definition of its API, I've only found this issue gitlab-org/gitlab#16023 (closed)

p.s. Kubernetes API conventions is relevant here - https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types. It states:

All public integer fields MUST use the Go (u)int32 or Go (u)int64 types, not (u)int (which is ambiguous depending on target platform). Internal types may use (u)int.

Edited by 🤖 GitLab Bot 🤖
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information