The Empty Sign That Erased The Real One - the cover: Pickle peels a blank sign off an enclosure and the real sign underneath reads Miso; inside sit two identical cats, Miso and Echo, the twin with a small stand badge; visitors are puzzled and Pip shrugs

The Empty Sign That Erased The Real One

Someone hung a blank sign over the real one, and visitors stopped knowing who lives in the enclosure. Now a blank sign says nothing and the real one stays. And when the twin from the stand demanded new names, the names stayed too.

👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: github.com/brilliant-almazov.

This part is about two tested fixes in the shared library and one stand that went into a restart loop. Both stories are real; how many services had a value erased by an empty key is not counted here.

This is part 15 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.

In real life

Nora stops at Miso's enclosure and asks: "Who lives here?" The sign is blank. Miso, inside, is not amused: "Me! The sign is empty." Somebody hung an empty board right over the real one - not to change anything, just because an empty board was part of the set - and the empty board won.

A four-panel comic: Nora by a blank sign asks who lives here and Miso, angry, says me, the sign is empty; Pickle by a sign that reads Miso says empty means nothing, the real sign stays; Echo and Miso, two identical cats, both say I'm Miso; Echo, angry, says rename your keys or I won't wake up, and Nora says names stay, we fix you

Pickle takes the empty board down and makes a rule: empty means nothing; the real sign stays. Then this part brings in a new resident: Echo, Miso's twin. Echo lives on the stand - the copy of the zoo where everything is tried before it reaches visitors - and looks exactly like Miso. The two of them say "I'm Miso" at the same time, and nobody can tell them apart. That is the point of a stand, and also its trap. One morning Echo refused to wake up until the keepers renamed three of Miso's signs. Nora's answer is the second story of this part: the names stay; we fix the one who reads them.

An empty key is not a value

A service in our platform reads its settings from two places. The config file carries every key with a default. The environment can override any key. The question this part is about is small and old: what should an environment variable that is set but empty mean?

Before the fix, it meant "the value is empty". A key that a stand or a hosting panel listed with no value - for whatever reason the field was left blank - erased the default from the config file. The service started with an empty string where a real address or a real limit should be, and whatever broke next broke far from its cause.

Three tiles with faces: environment, happy; config.yaml, proud; the value read, happy; labels read set and not empty wins, and else the file's value; a pill reads tested

Now an empty environment value does not override the config file. A key that is set and not empty still wins, a key that is absent still falls back to the file, and the one case that changed is the blank sign. In the shape of the rule:

ENV absent -> config.yaml value (before and after) ENV set, not empty -> ENV value (before and after) ENV set to "" -> before: "" erased the config.yaml value -> after: config.yaml value stays 

A sign scene, no code: three cases side by side - no note, the config.yaml sign shows; an empty note, highlighted, slides aside so the config.yaml value stays after the fix; a filled note wins; a plaque says a same-name sign belongs to the first declared resource; a pill reads tested

Columns: when config.yaml survives, out of three cases - before 1 of 3, after 2 of 3; Pickle, happy, says empty is not a value; a pill reads cases: absent, empty, set

The one-line difference

In Go the whole story fits in the difference between two standard calls. os.Getenv returns an empty string both when a variable is absent and when it is set to nothing, so code built on it cannot tell a blank sign from no sign. os.LookupEnv returns the value and whether the variable exists at all, and a loader built on it has to decide what the third case means. In the shape of that decision - a form, not the library's code:

v, ok := os.LookupEnv(key) switch { case !ok: // absent: the file's value return fileValue case v == "": // set but empty: before the fix, "" won; now the file's value return fileValue default: // set and not empty: the environment wins return v } 

The middle branch is the entire fix. It is one line, and it is the kind of line that every service would otherwise write for itself - or, more likely, not write, and learn about on a stand. Putting it in the shared loader means one decision, made once, for every key of every service.

The same fix settled two smaller questions of ownership in the config file, and both are the same kind of blank sign. When two resources of a service have a node with the same name in the config file, the node now belongs to the first declared resource, so the second one cannot silently overwrite it. And the scope of a setting can now be a list of daemons, not one, so a key that matters to the server and the worker does not have to be declared twice.

Situation Before After
key set but empty on a stand erased the file's value the file's value stays
two resources, same node name whoever came last the first declared resource
a setting for two daemons declared per daemon one scope, a list of daemons

What went wrong

The second story is the stand, and it is the more instructive one. After a library upgrade, the gateway on its stand went into a restart loop. The new library version rejected the gateway's config file and demanded that three environment keys be renamed. The stand kept restarting, and the obvious fix was right there in the error message: rename three keys.

The keys were not renamed. The fix went into the library: the next version read the old names again, and the stand came up with the same environment it had before. I count that as the right outcome for a reason that has nothing to do with the stand. A key name is a contract with everything outside the service - hosting panels, stand files, other people's runbooks. Renaming a key on the service side leaves every one of those places pointing at a name nobody reads anymore.

Bars: keys the stand was asked to rename 3; keys renamed 0; guards added so it does not repeat 1; Echo, bored, says I woke up with old names; a pill reads counted from the fix

The library also got a guard so the class does not come back: a test that every key the shipped config file carries is still read by the platform. If a future version stops reading a key that services ship, that test fails in the library, before any stand restarts.

Both stories have the same shape, and I only noticed it while writing this part. In each, the outside world - a blank field, an old key name - was treated as a mistake to be corrected, when it was a fact to be read. The library was the thing that had to bend.

An animation: a letter travels under four tiles - new library, stand config, service, up - and the pill changes from config.yaml rejected: rename three keys, to restart, restart, restart, to next library version: keys untouched, to up, with the old names

Echo is the reason this story belongs in a zoo. The stand looks exactly like production, and that is why its complaint sounded like an order: if the twin cannot start, the real one will not either. But the twin was asking for the wrong fix. The reader changed; the names were fine. When a stand demands that you change the world to fit a new library, check the library first.

Before and after: an empty key wins - erased, the value from config.yaml; blank, the service reads nothing - and an empty key is skipped - kept, the value from config.yaml; set, a real value still wins; a pill reads tested

Service tiles with faces: config.yaml proud, a set ENV value happy, an empty ENV value bored, the service happy; the stand happy, production happy, old key names proud, the guard test proud; pills read tested, and keys not renamed

What I do not claim

  • Not how many services had a value erased by an empty key. That is not counted.
  • Not that an empty value can never be meant. If a service needs "empty on purpose", that is a different setting, not a blank key.
  • Not how long the stand stayed in its loop. That is not measured here.
  • Not that the stand is production. Echo looks like Miso; that is all.
  • Not the exact rule text. The block above is a form.
  • Not the library's loader code. The Go above shows the decision, not the implementation.
  • Not that renaming a key is always wrong. It is a decision with owners outside the service, not a fix for a loop.

What of this is method

  • Empty is not a value. A blank key should not erase a real default.
  • Fix the reader, not the names. A key name is a contract with the world outside the service.
  • Guard the class. A test that every shipped key is still read stops the next loop in the library.

Zoo keeping, built in - Part 15. Next: Every Door Must Open.

If your services read settings from a file and the environment, what does an empty variable mean to them? If a stand of yours demanded a rename, did you rename or fix the reader? If you keep a twin of production, how do you tell its complaints from the real ones? Which blank sign is hanging in your zoo?