たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

Amplify/GraphQL@keyのcomposite sort keyが動く仕組み

"key2nd#key3rd"という属性を自動生成し、この属性に対して文字列比較を提供する

Composite sort keyとは

Given that DynamoDB limits you to query by at most two attributes at a time, the @key directive helps by streamlining the process of creating composite sort keys such that you can support querying by more than two attributes at a time.

仕組み

The primary @key with 3 fields performs a bit more magic than the 1 and 2 field variants.
The first field orderId will be the HASH key as expected, but the SORT key will be a new composite key named status#createdAt that is made of the status and createdAt fields on the @model.
 The @key directive creates the table structures and also generates resolvers that inject composite key values for you during queries and mutations.

実装

VTLリゾルバの自動生成.
key2nd や key3rd に対するクエリ(eq、gt/ge、between、beginsWithなど)を可能にしている.

ハマりどころ

文字列比較をしている

VTLで"S"の比較をしている.
keyを"#"でつないだものを比較に用いるので、文字列しか使えない.
桁をあわせる(ゼロパディング)すれば文字列で数字比較もできるが、クセが強い.

key3rdのみのクエリ不可

key2ndが必要.
内部実装としてconcatしたもののクエリしているだけなので、無はダメ

使いどころ

  1. 文字列の階層構造を持っている
  2. ゼロパディングができる数字属性

監視の目的

なんでバグがダメなのか
システムの品質を下げ、要求品質に届かなくする可能性を高めるから

監視の目的
品質の低下を検出する
品質改善方法の糸口を得る

「うちのシステムは最強なので常に最高の価値を提供し続けています」
=> 機能を発揮し価値を提供しているかの検証は不要

普通はそんな仮定をしないので、

  • 価値の実際の大きさ
  • 価値を生むシステムの働き具合(パフォーマンス)

をチェックする

価値を生んでるけどシステムは想定通りに動いていない
=> 思ったのと違う形で価値を生んでいる
システムは動いているけど価値がいまいち生まれていない
=> 価値創出の想定がおかしい可能性

利害関係とビジネス

利害関係者が利益を得る
顧客が満足して、提供者が満足して利益を得て、プラットフォーマーが利益を得る.

どういう分配かが大事.
顧客満足と提供者満足だけに終始すると提供者が赤字になって継続性がなくなる.

環境変数とコンテナ環境のベストプラクティス

  • とにかく気楽にenv使いたい: localEnvをセットするだけ
    • dev: process.envが読み取る (no special needs)
    • container: localEnvを挿入 docker run --env NAME=value <containerName>
    • web build: webpackでlocalEnvを挿入
  • localEnv汚染/名前衝突が嫌だ: ファイルに隔離 -> devContainerへファイルから挿入
    • dev: devContainerのcontainerEnvへファイルから挿入 devcontainer.json->runArgs
    • container: ファイルから挿入 devcontainer.json->mounts + docker run --env-file <mounted> <containerName>
    • web build: webpackでenv (devContainerEnv) を挿入

devcontainer.json

{
  "containerEnv": "set variables that should apply to the entire container",
  "remoteEnv": "set variables for VS Code and related sub-processes (terminals, tasks, debugging, etc)"
}

env挿入ref