question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feedback when app-config.yaml is filtered at runtime

See original GitHub issue

Feature Suggestion

Working on the frontend, I added a key to app-config.yaml that was being filtered out when using a ConfigReader to read it in my browser for apparently no reason. Having missing keys without any feedback, I asked for help and was told I needed to:

  1. Add a type definition for this key to packages/app/config.d.ts.
  2. Add @visibility frontend in a comment directly above it.

While this is covered in the docs, I feel the developer experience could be improved by console.warning or console.infoing in a browser’s console when keys are being filtered out from a read app-config.yaml with a link to relevant documentation and suggestions to adjust visibility then and there.

Possible Implementation

At the time of filtering out keys, add a console.warn statement similar to

Key [key] is not marked as visible to the frontend, so it will be omitted from ConfigReader's output. 
Please add `@visibility frontend` to your app's config.d.ts to adjust it.

More info: https://backstage.io/docs/conf/defining#visibility

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
OrkoHuntercommented, Jul 6, 2021

At the time of filtering out keys

Since a looot of config keys will not be available on frontend, it might be too many console warnings for an average user of Backstage.

I was thinking that a console error or warning should be printed only when you run config.get* API in the frontend and if the key is missing visibility frontend.


Quoting @freben

Could perhaps store all of the “potential” keys to read, even ones that were pruned - enough info for the frontend to learn that as you attempt to read a key, it failed because it has been pruned. Discern between “missing because it was never there” vs “missing because it’s been cut out”

3reactions
Rugvipcommented, Jul 23, 2021

I think adding a warning/error when filtered config values are accessed in the frontend is a great idea, I might have a look at if I can get that in. Probably just do it for development mode though, as I wouldn’t want to bloat production builds with all of that extra information. Pretty much all of the confusion that we’ve seen is during development anyway, as in “why doesn’t this config value that I just added show up in the frontend?”

@joaomilho

Adding to @TejasQ , as a short term improvement, I feel we could go further and break the build, as console warns are not obviously noticeable. It is a better DX to get the error before the confusion ensues.

The build doesn’t know what config values are being accessed, just like we can’t break the build if a certain global variable isn’t accessed at runtime. It’s actually one of the reasons the config schema exists, as it lets us break the build early when values are missing in config.

  1. I wonder if conflating backend and frontend config together is the source of the problem here. The design limitations here revolve around avoiding backend secrets to leak to the frontend and if these are more clearly separated we could avoid the issue altogether and relying on comments, warning or throwing, exposing __prunedKeys, etc…

Yeah the mixing of frontend and backend config undeniably comes with its set of problems, just like mixing frontend and backend packages in the same repo. I do still think it’s worth it though, as the problem space has quite a big overlap with the problem of managing config from a bunch of different plugins. I see config schema as helping both problems, with the only extra addition needed to handle the mix being the config visibility, which we also use to filter secrets. I’m also quite happy with the security aspect of the existing solution, as it takes a conscious decision to make something available in the frontend.

The main contender of the current solution in my mind is to completely split frontend and backend schema and config, essentially having both frontend-config.yaml and backend-config.yaml, as well as frontend-config.d.ts and backend-config.d.ts. That’s the main thing I’m comparing to anyway, but please do add more ideas to the table if possible.

You don’t need to use comments btw, you can use plain old JSON Schema if you want, it’s just not what most people prefer 😅

  1. webpack has its own ways of expanding env vars in the bundle and then eliminating dead code with terser. This breaks when all config is parsed from a single variable.

A big benefit of the current config system is that it’s possible to override values per deployment, allowing for example just the app.baseUrl to be tweaked for a preview build. That ofc is not possible if substitution happens at build time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is AWS AppConfig? - AWS AppConfig
AWS AppConfig, a capability of AWS Systems Manager, helps you manage, store, and safely deploy application configurations to your hosts at runtime.
Read more >
Tutorial: Use dynamic configuration in an ASP.NET Core app
In the Filter by name box, enter the name of your resource group. In the result list, select the resource group name to...
Read more >
App Builder Configuration Files - Adobe Developer
app.config.yaml is the main configuration file, defining the application's behavior and implementation. .env is used to store secrets and environment ...
Read more >
App.Config: Basics and Best Practices - SubMain Blog
config file can contain more than that. Remember how a default app.config contained this: This is where we define which .NET runtime(s) the ......
Read more >
app.yaml configuration file - Google Cloud
It is required to contain at least a runtime entry. Each service in your app has its own app.yaml file, which acts as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found