タイトルは英語のままなのは、日本語にしようとしても結局全部カタカナになるので放置。さてre-frameは俺的にClojureScriptでウェブのフロントエンド作るにあたって標準装備になっているが、ものによっては完全動的に生成されるReactのアプリよりも、検索エンジンなどでも絶対拾える静的HTMLを返した方がいいという場合もある。今回は流行り言葉をいっぱい使えるように、Denoを活かしてClojureScriptアプリのサーバーサイドレンダリングを実現しようと思います。動くコードはGithubにて。
Frontend/backend shared routing with reitit
Commonly frontend and backend are separate beasts. Backend written in Ruby using Rails for example, its routing written in its own DSL. Frontend written in TypeScript using Vue.js for example, its routing written in its own DSL. Of course the frontend will call some backend endpoints, so it should definitely know about those backend endpoints too, while there may be some frontend “paths” that don’t correspond to any single API endpoint, yet you might want to generate absolute URLs for those pages on the backend. This results in a nasty mess and duplication of routing and adjacent logic.
Elasticsearch aggregation to find most popular tags over time
Finding popular keywords or tags is what twitter’s trends are (other than a means to manipulate public opinion and introduce artificial trends by paying good cash). While I think having a “trends” feature tends to introduce more problems than the value it provides for discovery, I wanted to figure out how I’d do it before deciding not to.
Dealing with circular dependencies in Clojure
While working on stuff (of course in Clojure), I kept running into problems with namespaces having circular dependencies. For example I’d have an app.router
namespace that defines the, uh, routes. I’d have an app.url
namespace that contains helper functions to generate absolute URLs based on route data (so it depends on app.router
). I’d have an app.views
namespace that uses those URL helpers (thus depending on app.url
), and these views would be referenced in the routes so app.router
would require app.views
.
This completes the dependency circle and is the beginning of my journey. There are a bunch of ways to deal with circular dependencies in Clojure, but I won’t go in-depth about all of them.
Adding Grafana annotations based on Flux CD events
Earlier this year I wrote about adding Grafana annotations based on Argo CD events. Since this year I actually got around testing out Flux some more, it was natural to follow up with adding some Grafana annotations based on Flux events.
Clojure multimethods and derivation
I’ve known about Clojure multimethods of course, but I never really used them much. I didn’t really have data that I’d need polymorphism like multimethods to handle, and when I did need something like that I’d use protocols. However protocols dispatch based on class, so when I faced the problem of handling ActivityPub objects that are all maps, it was time for defmulti
to save the day.
Structured logging in Clojure
The first time I ran into “structured logging” was way, way back when I first started working on kitsune. Back then I went with the approach of using a Logback Formatter (the JacksonJsonFormatter) to log Clojure maps as JSON. This was nice because I didn’t have to do anything to “transform” the logs further, but had the quite significant downside that logs weren’t really human readable anymore. This plus that that log processors like Loki and CloudWatch can easily parse huge amounts of “traditional” text logs made me pretty much forget about structured logging until recently.
That is until in a thread on the clojurians slack about logging someone mentioned mulog, a structured logging library that caught my attention. I guess maybe from a traditional Clojure background it would’ve been natural to end up with taoensso/timbre at this point, but I never did that bit (though I do have it as an indirect dependency).
The Weave GitOps UI for Flux
Unlike Argo, Flux has no built-in UI. CD tools should be invisible most of the time, just quietly running in the back, getting changes in the cluster. This is fine for “most of the time” when there are no changes to the applications I’m making myself or the cluster itself. It can just look at the various helm charts and other (git) sources and deploying the changes as configured. It’s nice that I can be sure that my cluster has the latest possible versions of everything running within 10-15 minutes of release (depending on the Flux interval
configured) without ever touching kubectl
.
How do foreign keys work in MariaDB system versioned tables?
When I read about the system versioned (and bitemporal) tables in MariaDB, I was both surprised and delighted. This kind of data versioning is thought of as standard in the “immutable” databases that are big in Clojureland, such as Datomic and XTDB. On the other hand, these databases in Clojureland are usually EAVT based and not the “usual” relational kind. After a little thinking I could think of a bunch of really tricky issues that could arise from system versioning (eg having a by-default immutable log of all changes to some piece of data) in a relational context. The first being foreign keys.
If you create a foreign key in MariaDB without any further specifiers, it assumes ON UPDATE RESTRICT ON DELETE RESTRICT
, meaning no referenced key could be changed and no referenced row could be deleted. Just consider this: if there’s a row in some table referencing a row in another, system versioned table, can the row in the system versioned “parent” table be deleted? After all the referenced version of the row will still exist… Or in a similar scenario if the “child” row is system versioned and updated to now reference a different row, will both of those referenced rows be RESTRICT
ed? After all, both referencing rows will still exist… Of course I had to try.
-
Recent Posts
Tags
ale anime art beer blog clojure code coffee deutsch emo english fansub filozófia food gaming gastrovale geek hegymász jlc kaja kubernetes kultúra language literature live magyar movie másnap politika rant sport suli szolgálati közlemény travel társadalom ubuntu university weather work zene 日本 日本語 百名山 艦これ 軽音-
Recent Posts
Tags
ale anime art beer blog clojure code coffee deutsch emo english fansub filozófia food gaming gastrovale geek hegymász jlc kaja kubernetes kultúra language literature live magyar movie másnap politika rant sport suli szolgálati közlemény travel társadalom ubuntu university weather work zene 日本 日本語 百名山 艦これ 軽音七大陸最高峰チャレンジ