From ca3d2f9257a2db80253037d629b41753b1403b72 Mon Sep 17 00:00:00 2001 From: Christophe Chaudier Date: Fri, 3 Aug 2018 18:01:41 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=93=88(datadog)=20add=20datadog=20APM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group_vars/all/main.yml | 6 ++++++ group_vars/env_type/staging.yml | 3 +++ tasks/delete_app.yml | 2 ++ tasks/get_objects_for_app.yml | 18 ++++++++++++++++++ tasks/manage_app.yml | 13 +++++++++++++ 5 files changed, 42 insertions(+) diff --git a/group_vars/all/main.yml b/group_vars/all/main.yml index 55ed1c812..f13393614 100644 --- a/group_vars/all/main.yml +++ b/group_vars/all/main.yml @@ -62,6 +62,12 @@ job_stamp: null # docs/developer_guide/secrets.md secret_id: "1.0.0" + +# ddtrace is set to true for enable the APM in all apps where the templates +# include the possibility to have a ddtrace APM agent +# defaul is set to False +ddtrace: false + # TODO: move the following settings to the redirect app # Ports aliases_port: 8999 diff --git a/group_vars/env_type/staging.yml b/group_vars/env_type/staging.yml index 452f92c87..dbccd7be2 100644 --- a/group_vars/env_type/staging.yml +++ b/group_vars/env_type/staging.yml @@ -1,2 +1,5 @@ # Variables specific to the staging environment richie_django_configuration: Staging + +# Activate APM +ddtrace: true diff --git a/tasks/delete_app.yml b/tasks/delete_app.yml index 29ccccd5d..bec228364 100644 --- a/tasks/delete_app.yml +++ b/tasks/delete_app.yml @@ -14,6 +14,8 @@ register: raw_selected_objects loop: - ConfigMap + - BuildConfig + - ImageStream - DeploymentConfig - Job - Route diff --git a/tasks/get_objects_for_app.yml b/tasks/get_objects_for_app.yml index f591f85ff..4cc08dd74 100644 --- a/tasks/get_objects_for_app.yml +++ b/tasks/get_objects_for_app.yml @@ -6,6 +6,16 @@ templates: "{{ app | json_query('services[*].templates[]') | list }}" tags: deploy +- name: Set OpenShift datadog objects to manage + set_fact: + images: "{{ templates | map('regex_search', '.*/is.yml.j2$') | select('string') | list }}" + builds: "{{ templates | map('regex_search', '.*/bc.yml.j2$') | select('string') | list }}" + when: ddtrace + tags: + - deploy + - image + - build + - name: Set OpenShift objects to manage set_fact: deployments: "{{ templates | map('regex_search', '.*/dc.*\\.yml\\.j2$') | select('string') | list }}" @@ -19,6 +29,14 @@ - job - route +- name: Display OpenShift's build for this app + debug: msg="{{ builds | to_nice_yaml}}" + when: builds is defined + when: ddtrace + tags: + - deploy + - build + - name: Display OpenShift's deployments for this app debug: msg: "{{ deployments | to_nice_yaml}}" diff --git a/tasks/manage_app.yml b/tasks/manage_app.yml index e6cc0bc72..954b2f886 100644 --- a/tasks/manage_app.yml +++ b/tasks/manage_app.yml @@ -7,6 +7,19 @@ # - "absent": all objects are deleted # deployment_stamp: the stamp of the object we are going to create or delete +- name: OpenShift datadog objects with deployment_stamp[{{ deployment_stamp }}] must be {{ deployment_state | default('present') }} + openshift_raw: + definition: "{{ lookup('template', item) | from_yaml }}" + state: "{{ deployment_state | default('present') }}" + with_items: + - "{{ images }}" + - "{{ builds }}" + when: ddtrace + tags: + - deploy + - image + - build + - name: OpenShift objects with deployment_stamp[{{ deployment_stamp }}] must be {{ deployment_state | default('present') }} openshift_raw: definition: "{{ lookup('template', item) | from_yaml }}" From 5e95eaf6a5139121728a29f2f9d9df3205934640 Mon Sep 17 00:00:00 2001 From: Christophe Chaudier Date: Fri, 3 Aug 2018 18:03:10 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7(secrets)=20add=20staging=20sec?= =?UTF-8?q?rets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../patient0/staging/secrets/edxapp.vault.yml | 46 +++++++++++++++++++ .../patient0/staging/secrets/richie.vault.yml | 24 ++++++++++ 2 files changed, 70 insertions(+) create mode 100644 group_vars/customer/patient0/staging/secrets/edxapp.vault.yml create mode 100644 group_vars/customer/patient0/staging/secrets/richie.vault.yml diff --git a/group_vars/customer/patient0/staging/secrets/edxapp.vault.yml b/group_vars/customer/patient0/staging/secrets/edxapp.vault.yml new file mode 100644 index 000000000..932766e71 --- /dev/null +++ b/group_vars/customer/patient0/staging/secrets/edxapp.vault.yml @@ -0,0 +1,46 @@ +$ANSIBLE_VAULT;1.1;AES256 +32383464343731303731643337633338333463636366306138343430336336383961353638326165 +6639623661623435383237626634653036316361323535390a653966386136366461343961663561 +63346637353036383837303964653438303564623739386334633763333866316637613138643435 +6162393439326261360a613062346330313663633363643434636464633530303435613738666137 +66336130663130393432343937663132623138636433313530313536383538323531333031346431 +32386534363538303562316566356232626635393163656662613662313466366661316266333066 +66353433336433363630393832633338656666366262353236646662366635626235396233353666 +62623437376566393465303962363632326130613930363338303862653837643137653337643961 +33633234616165336362323261623636313939393133646339626637363034623437356362326461 +64313939643163616263613534356336383138326466336664653339336165333062363365333930 +31356637643963373538313239343863343235383336636239306136373864333534366238616137 +32373733626331613263356639626461656632623637636530366633646539366237356161393866 +34633262626537636239313038313534663530393635383832643161656435373832306566653934 +34313166363330373633396333613037333363346630663531333062313735626665353566653037 +37303937323630613537316361373431373166613132356539633639393364343834326562356638 +38623135376435376331323938653234303332643132303533313035373830616365306263643362 +38363033373831323637643637653863306138646233316535666165643965346339333662306337 +33656232656663646262366333653838633565623138356664313930386464306364663863653963 +64393938363364653764656432373963363666636339613865636635633434313530376337386335 +35356262376536646665393535353939643535316131626437666136336562666334326533353632 +61346531623237666232366636376232613539323130633330313534313839366334646239613739 +61633636373034323139323939303263633861646263646139343566396362303465396662336564 +66616431613964383133346634363731356531383535313438653233366338363436383432343365 +33393030653263373964386231303561316136326231396130386335326235316630366662356138 +62303836343034373134373436346136323030376535383136663462616433366332613562343539 +32363035393261636365353662616438323635353439326561653439613165373534393139393139 +33383762386539336434636532613731643634383931383730646439346437656431363663373132 +37363165623831656630393561386632633466623239613439303339376634656231336561386266 +38313834626538613033626333323762316662306631656564346232326637613532663733343665 +65386137326363623238613637383464303232303333663462346264656666353832626437373761 +62333764323333343631373061653433646161653831346633326434386566353666363930616536 +36396637363138306163393262306138366537313233313166343837353335663462613861356266 +30616164313235313561383030313362656265353936646261363861613239663863663230663430 +37616466643738653035333063396536333663366462326436386433306233643938386538313331 +31336238653331396661623630343363626364326637373631643931313938393161303661303663 +38656465313338313665653631326639306165616330633735313836363463623262653461376639 +32306463323163326639313239336134636531666431663533666562646339616434386631646436 +36666432373132306266343230396436363435643032666166623561663438623235653132333631 +38336637393033663961663933396135386332383364356135353030323033336438656337383637 +61633662346233333634366435323261363238633362346436666465386534316631353633626263 +66386635393036326665373634303963383364653536393664316438663032303165376330336430 +39356166323538653534663566623638653538633838643666633731653663313062393764313965 +39333833336165303361643136656231323731623163353865366364623663313132396262326431 +31306534633834636334633964646635333366383066616665666337643435376236313937396261 +3435 diff --git a/group_vars/customer/patient0/staging/secrets/richie.vault.yml b/group_vars/customer/patient0/staging/secrets/richie.vault.yml new file mode 100644 index 000000000..c68695dc2 --- /dev/null +++ b/group_vars/customer/patient0/staging/secrets/richie.vault.yml @@ -0,0 +1,24 @@ +$ANSIBLE_VAULT;1.1;AES256 +33393739333530396262376134396462616166653566333130303762373863333235363033313930 +3261656534636363646638383830653736643239633661300a376161653464343531396163316539 +35623566616330616631383164653638663737656661363062653731373535316331646661303061 +3430663036326335650a353638646430353365303666636466343964616634663861373061363163 +63353361343336313435653931383036313463383035663638393630373431636130303232313265 +66333439343838383331626463353364616165393163363565336564303861373932623233323830 +36613632653833636236633963393237366461653366653037636339663631386661633737343966 +38646437333838633335336666393437323664646662653432653565663861363638396266663035 +63343531343136613834306434353061643362343166313163613432346234363963393163333336 +66636635303033633363643530613961373931366136353037363130316633623264633633326166 +38663837633239376234366138353664363836333631373639376164323838666133623737343032 +32626537396136383165353832363035656132333932393364356232663937363939313738366331 +64363661623562396235396232316531313935613161633439643537383165306234333334373330 +35313736353835616465623735306231373165313234666166626337343038666661383139383963 +30623030313666316638373832363139656463626534393930383838373962366562613136363164 +63663238323134353235343337363266613333373438613634323533333837343539306161346332 +31623763343363643466356231323532613537333532336533666364306631646331656262376230 +38326339313237366162356239343332663432313063663038303431373037326137643962656364 +33373163346633636135643137366163333137356464343631653436633637393633333032396630 +65303530366238653064663932376136646132313633623834393735663536663438613630396663 +38393962633165343837396532356433326366356237343632303764333532386632376163616131 +61383531333431383265626566626166396435323834343831316431393766323466616634343436 +643835306435653464303963306133636639 From 2beb94d99f3ea5f308e8126d5dad457964d9ecb6 Mon Sep 17 00:00:00 2001 From: Christophe Chaudier Date: Fri, 3 Aug 2018 18:06:29 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8(datadog)=20add=20APM=20to=20richi?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/richie/templates/app/bc.yml.j2 | 35 +++++++++++++++++++++++++++++ apps/richie/templates/app/dc.yml.j2 | 19 +++++++++++++++- apps/richie/templates/app/is.yml.j2 | 12 ++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 apps/richie/templates/app/bc.yml.j2 create mode 100644 apps/richie/templates/app/is.yml.j2 diff --git a/apps/richie/templates/app/bc.yml.j2 b/apps/richie/templates/app/bc.yml.j2 new file mode 100644 index 000000000..9fe6beece --- /dev/null +++ b/apps/richie/templates/app/bc.yml.j2 @@ -0,0 +1,35 @@ +{% if ddtrace is defined and ddtrace %} +apiVersion: v1 +kind: BuildConfig +metadata: + labels: + app: richie + service: richie + version: "{{ richie_image_tag }}" + deployment_stamp: "{{ deployment_stamp }}" + name: "richie-{{ deployment_stamp }}" + namespace: "{{ project_name }}" +spec: + successfulBuildsHistoryLimit: 5 + failedBuildsHistoryLimit: 2 + triggers: + - type: ImageChange + - type: ConfigChange + strategy: + type: Docker + source: + dockerfile: |- + FROM {{ richie_image_name }}:{{ richie_image_tag }} + # Switch back to the root user to install development dependencies + USER root:root + + RUN pip install --no-cache-dir --prefix=/usr/local ddtrace + CMD ddtrace-run gunicorn -c /usr/local/etc/gunicorn/richie.py richie.wsgi:application + + # Un-privileged user running the application + USER 10000 + output: + to: + kind: ImageStreamTag + name: "ddtrace-richie-{{ deployment_stamp }}:{{ richie_image_tag }}" +{% endif %} diff --git a/apps/richie/templates/app/dc.yml.j2 b/apps/richie/templates/app/dc.yml.j2 index ac2ac7a63..ce992abb3 100644 --- a/apps/richie/templates/app/dc.yml.j2 +++ b/apps/richie/templates/app/dc.yml.j2 @@ -20,8 +20,13 @@ spec: deployment_stamp: "{{ deployment_stamp }}" spec: containers: - - name: richie + - name: "richie" +{% if ddtrace is defined and ddtrace %} + image: "docker-registry.default.svc:5000/{{ project_name }}/ddtrace-richie-{{ deployment_stamp }}:{{ richie_image_tag }}" + #image: "ddtrace-richie-{{ deployment_stamp }}:{{ richie_image_tag }}" +{% else %} image: "{{ richie_image_name }}:{{ richie_image_tag }}" +{% endif %} imagePullPolicy: IfNotPresent env: - name: DJANGO_SETTINGS_MODULE @@ -38,6 +43,18 @@ spec: value: "{{ richie_host }}" - name: ES_CLIENT value: "richie-{{ richie_elasticsearch_host }}-{{ deployment_stamp }}" +{% if ddtrace is defined and ddtrace %} + - name: DATADOG_TRACE_AGENT_HOSTNAME + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: DD_AGENT_SERVICE_HOST + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: DD_AGENT_SERVICE_PORT + value: '8126' +{% endif %} envFrom: - secretRef: name: richie-{{ secret_id }} diff --git a/apps/richie/templates/app/is.yml.j2 b/apps/richie/templates/app/is.yml.j2 new file mode 100644 index 000000000..7a361337b --- /dev/null +++ b/apps/richie/templates/app/is.yml.j2 @@ -0,0 +1,12 @@ +{% if ddtrace is defined and ddtrace %} +apiVersion: v1 +kind: ImageStream +metadata: + labels: + app: richie + service: richie + version: "{{ richie_image_tag }}" + deployment_stamp: "{{ deployment_stamp }}" + name: "ddtrace-richie-{{ deployment_stamp }}" + namespace: "{{ project_name }}" +{% endif %}