GS2-Log Deploy/CDK リファレンス

GS2-Deployのスタックを作成する際に使用するテンプレートのフォーマットと、CDKによる各種言語のテンプレート出力の実装例

エンティティ

Deploy処理で操作の対象となるリソース

Namespace

ネームスペース

ネームスペースは、一つのプロジェクト内で同じサービスを異なる用途で複数利用するためのエンティティです。
GS2 の各サービスはネームスペース単位で管理されます。ネームスペースが異なれば、同じサービスでも完全に独立したデータ空間として扱われます。

そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。

Request

リソースの生成・更新リクエスト

有効化条件必須デフォルト値の制限説明
namestring
~ 128文字ネームスペース名
ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
descriptionstring~ 1024文字説明文
type文字列列挙型
enum {
  “gs2”,
  “bigquery”,
  “firehose”
}
“gs2”ログの書き出し方法
ログデータのエクスポート先を決定します。“gs2” はGS2のマネージドストレージにログを保存し、組み込みの検索・分析機能を利用できます。“bigquery” はGoogle BigQueryにログをエクスポートして高度な分析を行えます。“firehose” はAmazon Kinesis Data Firehoseにログをストリーミングし、S3やRedshiftなどのAWS送信先に配信します。
定義説明
“gs2”GS2による管理
“bigquery”BigQuery への書き出し
“firehose”Kinesis Firehose への書き出し
gcpCredentialJsonstring{type} == “bigquery”
✓※
~ 5120文字GCPのクレデンシャル
BigQueryへのログエクスポート時の認証に使用するGCPクレデンシャルJSONです。サービスアカウントには対象データセットに対するBigQuery Data Editor権限が必要です。
※ type が “bigquery” であれば必須
bigQueryDatasetNamestring{type} == “bigquery”
✓※
~ 1024文字BigQueryのデータセット名
ログデータのエクスポート先となるBigQueryデータセットの名前です。データセットは提供されたクレデンシャルに関連付けられたGCPプロジェクト内にあらかじめ存在している必要があります。
※ type が “bigquery” であれば必須
logExpireDaysint{type} in [“gs2”, “bigquery”]
✓※
0 ~ 3650ログの保存期間(日)
ログデータを保持する日数です。この期間を超えたログは自動的に削除されます。エクスポート方法が “gs2” または “bigquery” の場合に適用されます。最大3650日(約10年)まで設定可能です。
※ type が “gs2”,“bigquery"であれば 必須
awsRegionstring{type} == “firehose”
✓※
~ 256文字AWSのリージョン
Kinesis Data Firehose配信ストリームが存在するAWSリージョンです(例:us-east-1、ap-northeast-1)。
※ type が “firehose” であれば必須
awsAccessKeyIdstring{type} == “firehose”
✓※
~ 256文字AWSのアクセスキーID
Kinesis Data Firehoseへの認証に使用するAWSアクセスキーIDです。IAMユーザーには、指定されたFirehose配信ストリームへのレコード送信権限が必要です。
※ type が “firehose” であれば必須
awsSecretAccessKeystring{type} == “firehose”
✓※
~ 256文字AWSのシークレットアクセスキー
Kinesis Data Firehose認証のためにアクセスキーIDと対になるAWSシークレットアクセスキーです。
※ type が “firehose” であれば必須
firehoseStreamNamestring{type} == “firehose”
✓※
~ 256文字Kinesis Firehose のストリーム名
ログデータの送信先となるKinesis Data Firehose配信ストリームの名前です。
※ type が “firehose” であれば必須
firehoseCompressData文字列列挙型
enum {
  “none”,
  “gzip”
}
{type} == “firehose”“none”Kinesis Firehose に出力するデータを圧縮するか
Kinesis Data Firehoseに送信する前にログデータを圧縮するかどうかの設定です。Gzip圧縮によりデータ転送量とストレージコストを削減できます。
定義説明
“none”圧縮しない
“gzip”Gzip
※ type が “firehose” であれば必須

GetAttr

!GetAttrタグで取得可能なリソースの生成結果

説明
ItemNamespace作成したネームスペース

実装例

Type: GS2::Log::Namespace
Properties:
  Name: namespace-0001
  Description: null
  Type: gs2
  GcpCredentialJson: {"project_id": "gs2-dev"}
  BigQueryDatasetName: dataset_0001
  LogExpireDays: 3
  AwsRegion: awsRegion
  AwsAccessKeyId: awsAccessKeyId
  AwsSecretAccessKey: awsSecretAccessKey
  FirehoseStreamName: firehoseStreamName
  FirehoseCompressData: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/log"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
log.NewNamespace(
    &SampleStack,
    "namespace-0001",
    log.NamespaceOptions{
        Type: log.NamespaceTypeGs2,
        GcpCredentialJson: pointy.String("{\"project_id\": \"gs2-dev\"}"),
        BigQueryDatasetName: pointy.String("dataset_0001"),
        LogExpireDays: pointy.Int32(3),
        AwsRegion: pointy.String("awsRegion"),
        AwsAccessKeyId: pointy.String("awsAccessKeyId"),
        AwsSecretAccessKey: pointy.String("awsSecretAccessKey"),
        FirehoseStreamName: pointy.String("firehoseStreamName"),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Log\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Log\Model\Options\NamespaceOptions(
                type: \Gs2Cdk\Log\Model\Enums\NamespaceType::GS2,
                gcpCredentialJson: "{\"project_id\": \"gs2-dev\"}",
                bigQueryDatasetName: "dataset_0001",
                logExpireDays: 3,
                awsRegion: "awsRegion",
                awsAccessKeyId: "awsAccessKeyId",
                awsSecretAccessKey: "awsSecretAccessKey",
                firehoseStreamName: "firehoseStreamName"
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.log.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.log.model.options.NamespaceOptions()
                        .withType(io.gs2.cdk.log.model.enums.NamespaceType.GS2)
                        .withGcpCredentialJson("{\"project_id\": \"gs2-dev\"}")
                        .withBigQueryDatasetName("dataset_0001")
                        .withLogExpireDays(3)
                        .withAwsRegion("awsRegion")
                        .withAwsAccessKeyId("awsAccessKeyId")
                        .withAwsSecretAccessKey("awsSecretAccessKey")
                        .withFirehoseStreamName("firehoseStreamName")
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Log.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Log.Model.Options.NamespaceOptions
            {
                type = Gs2Cdk.Gs2Log.Model.Enums.NamespaceType.Gs2,
                gcpCredentialJson = "{\"project_id\": \"gs2-dev\"}",
                bigQueryDatasetName = "dataset_0001",
                logExpireDays = 3,
                awsRegion = "awsRegion",
                awsAccessKeyId = "awsAccessKeyId",
                awsSecretAccessKey = "awsSecretAccessKey",
                firehoseStreamName = "firehoseStreamName"
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import log from "@/gs2cdk/log";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new log.model.Namespace(
            this,
            "namespace-0001",
            {
                type: log.model.NamespaceType.GS2,
                gcpCredentialJson: "{\"project_id\": \"gs2-dev\"}",
                bigQueryDatasetName: "dataset_0001",
                logExpireDays: 3,
                awsRegion: "awsRegion",
                awsAccessKeyId: "awsAccessKeyId",
                awsSecretAccessKey: "awsSecretAccessKey",
                firehoseStreamName: "firehoseStreamName"
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, log

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        log.Namespace(
            stack=self,
            name='namespace-0001',
            options=log.NamespaceOptions(
                type=log.NamespaceType.GS2,
                gcp_credential_json='{"project_id": "gs2-dev"}',
                big_query_dataset_name='dataset_0001',
                log_expire_days=3,
                aws_region='awsRegion',
                aws_access_key_id='awsAccessKeyId',
                aws_secret_access_key='awsSecretAccessKey',
                firehose_stream_name='firehoseStreamName',
            ),
        )

print(SampleStack().yaml())  # Generate Template

Dashboard

ダッシュボード

ログデータとメトリクスを可視化するためのカスタマイズ可能なダッシュボードです。各ダッシュボードはレイアウトとウィジェット設定をJSONペイロードとして保存し、ログ分析のカスタマイズされたビューを作成できます。

Request

リソースの生成・更新リクエスト

有効化条件必須デフォルト値の制限説明
namespaceNamestring
~ 128文字ネームスペース名
ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
displayNamestring
~ 256文字表示用の名前
このダッシュボードの人間が読める名前で、ダッシュボード一覧やヘッダーに表示されます。
descriptionstring~ 1024文字説明文

GetAttr

!GetAttrタグで取得可能なリソースの生成結果

説明
ItemDashboard作成したダッシュボード

実装例

Type: GS2::Log::Dashboard
Properties:
  NamespaceName: namespace-0001
  DisplayName: Sample Dashboard 0001
  Description: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/log"
)


SampleStack := core.NewStack()
log.NewDashboard(
    &SampleStack,
    "namespace-0001",
    "Sample Dashboard 0001",
    log.DashboardOptions{},
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Log\Model\Dashboard(
            stack: $this,
            namespaceName: "namespace-0001",
            displayName: "Sample Dashboard 0001"
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.log.model.Dashboard(
                this,
                "namespace-0001",
                "Sample Dashboard 0001"
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Log.Model.Dashboard(
            stack: this,
            namespaceName: "namespace-0001",
            displayName: "Sample Dashboard 0001"
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import log from "@/gs2cdk/log";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new log.model.Dashboard(
            this,
            "namespace-0001",
            "Sample Dashboard 0001"
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, log

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        log.Dashboard(
            stack=self,
            namespace_name='namespace-0001',
            display_name='Sample Dashboard 0001',
        )

print(SampleStack().yaml())  # Generate Template

FacetModel

ファセットモデル

ログデータのフィルタリングと集計に使用できるファセットフィールドを定義します。ファセットにより、サービス名、メソッド、ステータス、カスタムフィールドなどの特定のディメンションでログ検索結果を絞り込めます。

Request

リソースの生成・更新リクエスト

有効化条件必須デフォルト値の制限説明
namespaceNamestring
~ 128文字ネームスペース名
ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
fieldstring
~ 128文字ファセットのフィールド名
このファセットが対象とするログフィールドの名前です(例:“service”、“method”、“status”)。
type文字列列挙型
enum {
  “string”,
  “double”,
  “measure”
}
ファセットのデータ型
ファセットフィールドのデータ型です。“string” は値のカウント付きカテゴリ値、“double” は範囲フィルタリング付き数値、“measure” は統計分析付き測定値に使用します。
定義説明
“string”文字列
“double”数値
“measure”測定値
displayNamestring
~ 128文字表示用の名前
このファセットの人間が読める名前で、ログ検索UIに表示されます。
orderint00 ~ 100000表示順
UIでこのファセットを表示する際の並び順です。値が小さいほど先に表示されます。

GetAttr

!GetAttrタグで取得可能なリソースの生成結果

説明
ItemFacetModel作成したファセットモデル

実装例

Type: GS2::Log::FacetModel
Properties:
  NamespaceName: namespace-0001
  Field: facet-model-0001
  Type: string
  DisplayName: Sample Facet Model 0001
  Order: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/log"
)


SampleStack := core.NewStack()
log.NewFacetModel(
    &SampleStack,
    "namespace-0001",
    "facet-model-0001",
    log.FacetModelTypeString,
    "Sample Facet Model 0001",
    log.FacetModelOptions{},
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Log\Model\FacetModel(
            stack: $this,
            namespaceName: "namespace-0001",
            field: "facet-model-0001",
            type: \Gs2Cdk\Log\Model\Enums\FacetModelType::STRING,
            displayName: "Sample Facet Model 0001"
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.log.model.FacetModel(
                this,
                "namespace-0001",
                "facet-model-0001",
                io.gs2.cdk.log.model.enums.FacetModelType.STRING,
                "Sample Facet Model 0001"
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Log.Model.FacetModel(
            stack: this,
            namespaceName: "namespace-0001",
            field: "facet-model-0001",
            type: Gs2Cdk.Gs2Log.Model.Enums.FacetModelType.String,
            displayName: "Sample Facet Model 0001"
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import log from "@/gs2cdk/log";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new log.model.FacetModel(
            this,
            "namespace-0001",
            "facet-model-0001",
            log.model.FacetModelType.STRING,
            "Sample Facet Model 0001"
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, log

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        log.FacetModel(
            stack=self,
            namespace_name='namespace-0001',
            field='facet-model-0001',
            type=log.FacetModelType.STRING,
            display_name='Sample Facet Model 0001',
        )

print(SampleStack().yaml())  # Generate Template