Defined Type: cfwebapp::kibana

Defined in:
manifests/kibana.pp

Overview

Parameters:

  • ifaces (Array[String[1]]) (defaults to: ['local'])
  • app_dbaccess (CfWeb::DBAccess) (defaults to: { cluster => 'logsink' })
  • server_name (String[1]) (defaults to: $title)
  • auto_cert (Hash[String[1],Any]) (defaults to: {})
  • shared_cert (CfWeb::SharedCert) (defaults to: [])
  • is_backend (Boolean) (defaults to: false)
  • robots_noindex (Boolean) (defaults to: true)
  • memory_weight (Integer[1]) (defaults to: 100)
  • memory_min (Integer[128]) (defaults to: 512)
  • memory_max (Optional[Integer[128]]) (defaults to: 512)
  • plugins (Array[String[1]]) (defaults to: [])
  • kibana_tune (Hash[String[1], Any]) (defaults to: {})
  • site_params (Hash[String[1], Any]) (defaults to: {})


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'manifests/kibana.pp', line 5

define cfwebapp::kibana (
    Array[String[1]] $ifaces = ['local'],

    CfWeb::DBAccess $app_dbaccess = { cluster => 'logsink' },

    String[1] $server_name = $title,

    Hash[String[1],Any] $auto_cert = {},
    CfWeb::SharedCert $shared_cert = [],

    Boolean $is_backend = false,
    Boolean $robots_noindex = true,

    Integer[1] $memory_weight = 100,
    Integer[128] $memory_min = 512,
    Optional[Integer[128]] $memory_max = 512,

    Array[String[1]] $plugins = [],
    Hash[String[1], Any] $kibana_tune = {},

    Hash[String[1], Any] $site_params = {},
) {
    include cfweb::nginx

    $user = "app_${title}"
    $site_dir = "${cfweb::nginx::web_dir}/${user}"

    $kibana_tune_all = {
        'elasticsearch.pingTimeout' => 3000,
        'elasticsearch.preserveHost' => false,
        'elasticsearch.requestHeadersWhitelist' => [],
        'elasticsearch.requestTimeout' => 30000,
        'kibana.defaultAppId' => 'discover',
    } + $kibana_tune + {
        'server.name' => $server_name,
        'logging.json' => false,
    }

    include cfdb::elasticsearch

    # ---
    ensure_resource('package', 'kibana', { ensure => latest })
    ensure_resource('service', 'kibana', {
        ensure  => false,
        enable  => false,
        require => Package['kibana'],
    })

    if empty($plugins) {
        $migrate = []
    } else {
        $migrate = (
            ['action migrate'] +
            $plugins.map |$p| { "'@cid tool exec node -- --no-warnings src/cli_plugin ${p}'" }
        ).join(' ')
    }

    # ---
    $app_port = cfsystem::gen_port($user)
    $app_tune = {
        scalable   => false,
        socketType => 'tcp',
        socketPort => $app_port,
    }
    cfnetwork::describe_service{ $user:
        server => "tcp/${app_port}",
    }
    cfnetwork::service_port{ "local:${user}": }
    cfnetwork::client_port{ "local:${user}":
        user => $cfweb::nginx::user,
    }

    ensure_resource('cfweb::site', $title, $site_params + {
        server_name        => $server_name,
        ifaces             => $ifaces,
        auto_cert          => $auto_cert,
        shared_cert        => $shared_cert,
        is_backend         => $is_backend,
        robots_noindex     => $robots_noindex,
        dbaccess           => {
            app => $app_dbaccess + {
                config_prefix => 'DB_'
            },
        },
        apps               => {
            futoin => {
                memory_weight => $memory_weight,
                memory_min    => $memory_min,
                memory_max    => $memory_max,
            },
        },
        deploy             => {
            type          => 'rms',
            tool          => 'scp',
            url           => $site_dir,
            match         => 'kibana-*.tar',
            custom_script => @("EOT"/$)
                #!/bin/bash
                set -e
                source .env
                umask 027

                CONF_DIR=.runtime
                mkdir -p \$CONF_DIR

                # Create fake RMS package from source
                #---
                ver=$(/usr/bin/dpkg-query -f '\${Version}' -W kibana)
                pkg=kibana-\${ver}.tar
                [ -e \$pkg ] || (\
                    /bin/tar -cJf \${pkg}.tmp -C /usr/share/kibana . && \
                    /bin/mv -f \${pkg}.tmp \${pkg} )

                # Node.js
                #---
                cat >\$CONF_DIR/node_wrapper <<EOF
                #!/bin/dash
                app=\\\$1
                shift
                exec ../current/node/bin/node \\
                    "\\\$@" \\
                    \\\$app \\
                    -c ../.runtime/kibana.yml \\
                    -H \\\$HOST \\
                    -p \\\$PORT
                EOF
                chmod +x \$CONF_DIR/node_wrapper
                
                # DB
                #----
                cat >\$CONF_DIR/kibana.yml.tmp <<EOF
                ${to_yaml($kibana_tune_all)}
                elasticsearch.url: http://\${DB_HOST}:\${DB_PORT}
                EOF
                mv -f \$CONF_DIR/kibana.yml.tmp \$CONF_DIR/kibana.yml
                
                | EOT
                ,
            deploy_set    => [
                'env nodeVer 6',
                "env nodeBin ${site_dir}/.runtime/node_wrapper",
                'env CONFIG_PATH ../.runtime/kibana.yml',
                'persistent data',
                'writable optimize',
                "entrypoint kibana node src/cli \'${to_json($app_tune)}\'",
                'webcfg main kibana',
            ] + $migrate,
        },
        require => Package['kibana'],
    })
}