Working with Backstage Software Templates

I like learning new stuff - anything, including technology. I love tinkering with new tools, systems and services, especially open source projects
Search for a command to run...

I like learning new stuff - anything, including technology. I love tinkering with new tools, systems and services, especially open source projects
No comments yet. Be the first to comment.
inodes is a concept in Linux. Oh waitβ¦no Fun fact that I learned while experimenting on my macOS - I can see that the term and concept of inodes exists in the context of macOS too Looks like itβs a βUnixβ thing and Linux and Darwin, both are Unix bas...

You can look for Kubernetes Preemption Events in your observability system assuming you are exporting your Kubernetes Events to some store like some time series DB or similar In our case, we use Prometheus and we have an exporter for exporting the Ku...

Recently, when I discovered the py-spy profiler took for Python, I also discovered Speedscope, which is visualization tool for visualizing performance data (performance profile etc). This is a flamegraph Visualization. I have something of this sort w...

So, today, we had an issue in one of our internal systems called API Tester. It was very slow. Only today it was slow, and the CPU usage was very high according to our monitoring systems, especially since today morning. Before noticing the CPU usage,...

If you have Prometheus running and scraping metrics - You can find Kubernetes list of features enabled information for every feature using kubernetes_feature_enabled metric which gives build information kubernetes_feature_enabled{} The name of the f...

Recently I have been working with https://backstage.io/ , specifically the Backstage Software Templates feature
I noticed a few things and learned a lot of things too
Here are some short notes ποΈ π on what I noticed and also what I learned
Great Developer Experience (DevEx) when building Backstage Software Templates
Error handling is done really well in Backstage :)
I noticed that it was hard to do the testing
I noticed that it was hard to define constants or variables of sorts that I can reuse
steps in the Backstage Software Template, then you can use a custom action, a custom plugin, like this - https://www.npmjs.com/package/@gabtec/backstage-action-var-set , which helps you set variables. Not sure if the variable values support all kinds of values, like number, string, object, array etcI didn't disable the authentication and authorization feature and this was making development harder
I didn't know how to do this. I'm yet to figure this out. I'm stubborn in not asking my colleagues who probably already know something or figured it out already and have implemented it too for their local development. But it's not part of any "Contributing Guide"
In our custom production Backstage instance, we have of course enabled Authentication and Authorization and we use Keycloak for it and Single Sign On enabled in Keycloak ππ. The thing is, somewhere there's some timeout / session expiry / token expiry which causes the session to get expired and it then causes errors showing up in the front end - saying that Auth failed. This is pretty annoying. Ideally, for local development, unless you are working on Authentication and Authorization, Auth can be disabled, so that it's not bugging you and hindering you. I have had to refresh my page and login multiple times. The main issue is not even refreshing and logging in multiple times, the main issue is, I have a big form, with multiple stages and each stage getting a lot of data - so, once this auth error happens, I just lose all this data on refresh. And no, if I use a separate tab to login and retry stuff without refresh, it doesn't work, I don't know why. For each new π tab, I need to login. For some reason the login session / token is not stored I think π€π, say, in the browser storage, for it to work across browser tabs. And no, I'm not using something like Firefox containers (or any Chrome stuff) with separate containers and different container tabs to open the Backstage UI causing it to be oblivious about the other tabs / be isolated from other tabs and the storage of other containers and their tabs. Due to this auth error, I end up having to type in and key in all the data again to the form and keep clicking "Next" and then click "Create" to run the Software Template's steps
I noticed there was also a LOT of code repetition in the Software Template. Some ideas I thought π of for fixing this are
Try to use YAML language features, like Anchors and Alias
Try to codify things
Use a templating language to generate the Backstage Software Template
Use programming language to generate the Backstage Software Template.
So, kind of like using a transpiler or some processor of sorts to process some easy to understand thing to the complex Backstage Software Template which has lot of repetition. Since it's hard to work with repetitive code, you can work with non-repetitive code which is easy to understand and modify without any errors
With programming languages, we can write tests too π ;) And do configuration testing
Problems / Drawbacks
Harder and Complex, but sounds pretty awesome ππ€©π and powerful πͺ to me. It might make life just easier, or just harder or very much harder, lol
We need tools βοΈπ§°π οΈ for this or else it would still be hard to use whatever new tool/system πͺπ¨ we use. If it's a existing programming language or some existing configuration language like YAML etc, then fine. If we create some Domain Specific Language, gotta be careful about it!
It was easier to make UI changes in the Backstage Software Template form once it became clear that the forms use react-jsonschema-form library for the form creation and working. The official website for that project is https://rjsf-team.github.io/react-jsonschema-form/ and it has a playground and there are docs at https://rjsf-team.github.io/react-jsonschema-form/docs/ . But you may not be able to use all the feature in https://rjsf-team.github.io/react-jsonschema-form/ . Why? I don't know, gotta check. For example, you can't use definitions from what I understand till now.
What I'm yet to try/do etc
Validation of Form fields
Consider checking Configuration Testing Tools and see if they can be used here for any testing
For an End to End Test, we need to run a Backstage instance, and then use the Backstage Software Template and execute it after giving it all the inputs. For this, we can use multiple automation. One automation to just simply run the Backstage instance. Another automation to mimic user behaviour, a user who is using a browser and interacting with the Backstage Software Template. For this mimicing behaviour, we can use Browser automation tools π§°π οΈβοΈ, libraries, frameworks, systems and services. For example, Selenium, Appium etc
For an easier and faster test, especially for the local and also for the CI, and also to have more test cases without losing out on time when using End to End test, we can look for unit test and integration test kind of stuff
For unit test, we need to look at the unit we are trying to test. The subject under test (SUT) basically. For example, one unit to test is - the list of steps to run once the Backstage Software Template form is completed by the user βοΈβ
βοΈ. For testing the steps or processes that happen once the form is submitted, we can look at what actions are used in the steps. If the steps are fetch:template etc, it should be easy, but others should also be easy. So, basically, we are not trying to test the step itself, we are just trying to ensure that the output of the step is correct and what we want. So, basically, the subject under test is the template that you write βοΈποΈβοΈβοΈποΈ which is a templatized thing. DO NOT end up testing the steps - steps need to tested by the creator of the actions in the action source code etc. If that's you, then since you are creating the action, you need to test it. Now, so, what do you do to test the template? Take the template and run it through the sequence of steps that you have defined and see if it does exactly what you expected it to do. For example, if you wanted it to create files after templatizing, then have an expected set of files and compare the actual output of files to the expected. Now, how do you run the sequence of steps? Well, we need the actual Backstage runner to run these steps and also need to ensure that all the required actions are available and installed. One thing we can do is - instead of running the whole Backend server of Backstage, you could just create a tool to get the parts of Backstage that does this - running of the workflow of steps. I don't think such a tool already exists, so, you need to create one. I plan to create one. If I do, I'll share it in my blog :) :D ππππ You could import the Backstage repo libraries etc as it's all open source and then use it to do what Backstage backend itself does :) This way, you can just use a CLI like tool, which is lightweight and faster and easier to use and test your code π§βπ»π©βπ»π¨βπ» instead of using slow browser based testing
Based on the above idea π‘, you can extrapolate it and try to do the same for integration testing