Skip to content

Commit

Permalink
Use splash instead of phantomjs to generate legacy offset.png's
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Dec 20, 2017
1 parent e3fd59c commit f08e2f7
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM quay.io/ntppool/base-os:v3.1.0
FROM quay.io/ntppool/base-os:v3.2.2

USER root

Expand Down
48 changes: 0 additions & 48 deletions bin/rrd_worker

This file was deleted.

6 changes: 3 additions & 3 deletions confd/templates/combust.conf.tmpl
Expand Up @@ -31,7 +31,7 @@ log_path = stdout
work_path = /var/ntppool/

# Gearman Job Servers
job_servers = {{ getenv "GEARMAND_SERVICE_HOST" }}:{{ getenv "GEARMAND_SERVICE_PORT" }}
#job_servers = {{ getenv "GEARMAND_SERVICE_HOST" }}:{{ getenv "GEARMAND_SERVICE_PORT" }}

use_cronolog = 0

Expand Down Expand Up @@ -65,7 +65,7 @@ keepalivetimeout = 30
{{ $names := split (getenv "web_hostname") "," }}
servername = {{ index $names 0 }}
{{ if gt (len $names) 1 }}
aliases = {{ range $names }}{{.}}, {{ end}}
aliases = {{ range $names }}{{.}}, {{ end}} web
{{ end }}

pool_domain = {{ getenv "pool_domain" }}
Expand All @@ -92,7 +92,7 @@ external_port = 443
[manage]
{{ $names := split (getenv "manage_hostname") "," }}
servername = {{ index $names 0 }}
aliases = {{ range $names }}{{.}}, {{ end}}
aliases = {{ range $names }}{{.}}, {{ end}} manage

deployment_mode = {{ $mode }}
static_base = {{ getenv "static_base" }}
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/static/css/content.css
Expand Up @@ -128,7 +128,7 @@ tr.deleted_server {
/* misc.prev */
.graph_explanation {
display: none;
width: 450px;
width: 400px;
margin-left: 30px;
margin-top: 10px;
padding: 9px;
Expand Down
2 changes: 1 addition & 1 deletion docs/shared/tpl/server_static_graph.html
@@ -1,6 +1,6 @@
[% page.style = "basic.html" %]

<div id="graph" class="graph" data-server-ip="[% server.ip %]" data-width="450" data-height="166"></div>
<div id="graph" class="graph" data-server-ip="[% server.ip %]" data-width="425" data-height="166"></div>
<div class="graph-legend"></div>

<script type="text/javascript">
Expand Down
26 changes: 0 additions & 26 deletions k8s/30-gearmand.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions k8s/31-gearmand-service.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions k8s/51-ntppool-service.yaml
Expand Up @@ -7,9 +7,9 @@ metadata:
app: ntppool
spec:
ports:
- port: 8980
- port: 80
protocol: TCP
#targetPort: 8980
targetPort: 8980
selector:
app: ntppool
tier: frontend
46 changes: 46 additions & 0 deletions k8s/52-splash.yaml
@@ -0,0 +1,46 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: splash
spec:
replicas: 2
revisionHistoryLimit: 3
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: ntppool
tier: splash
spec:
restartPolicy: Always
containers:
- name: splash
image: scrapinghub/splash:latest
imagePullPolicy: Always
resources:
requests:
cpu: 200m
memory: 450Mi
limits:
cpu: 1
memory: 700Mi
env:
ports:
- containerPort: 8050
---
apiVersion: v1
kind: Service
metadata:
name: splash
spec:
ports:
- name: http
port: 8050
protocol: TCP
targetPort: 8050
selector:
tier: splash
6 changes: 3 additions & 3 deletions k8s/tmpl/ingress-manage.tmpl
Expand Up @@ -6,7 +6,7 @@ metadata:
ingress.kubernetes.io/configuration-snippet: |
proxy_pass_header Server;
kubernetes.io/tls-acme: "true"
ingress.class: nginx
ingress.class: haproxy

spec:
rules:
Expand All @@ -17,8 +17,8 @@ spec:
- path: /
backend:
serviceName: web
servicePort: 8980
{{ end }}
servicePort: 80
{{ end }}

tls:
- hosts:
Expand Down
4 changes: 2 additions & 2 deletions k8s/tmpl/ingress-web.tmpl
Expand Up @@ -3,7 +3,7 @@ kind: Ingress
metadata:
name: ntpbeta-web
annotations:
ingress.class: nginx
ingress.class: haproxy
ingress.kubernetes.io/configuration-snippet: |
proxy_pass_header Server;
{{ if eq "$web_tls" "yes" }}
Expand All @@ -18,7 +18,7 @@ spec:
- path: /
backend:
serviceName: web
servicePort: 8980
servicePort: 80
{{ end }}

# web_tls: $web_tls
Expand Down
56 changes: 50 additions & 6 deletions lib/NTPPool/Control/Graph.pm
Expand Up @@ -2,10 +2,17 @@ package NTPPool::Control::Graph;
use strict;
use base qw(NTPPool::Control);
use Combust::Constant qw(OK DECLINED);
use Combust::Gearman::Client ();
use NP::Model;
use LWP::UserAgent qw();

my $gearman = Combust::Gearman::Client->new;
my $ua = LWP::UserAgent->new(
ssl_opts => {
SSL_verify_mode => 0x02,
SSL_ca_file => Mozilla::CA::SSL_ca_file()
}
);

my $url = URI->new(Combust::Config->new->base_url('ntppool'));

sub render {
my $self = shift;
Expand All @@ -28,18 +35,55 @@ sub render {

return $self->redirect('/graph/' . $server->ip . "/$type", 301) unless $p eq $server->ip;

my $graph =
eval { $gearman->do_task('update_graphs', $server->id, {uniq => 'graphs-' . $server->id}); };

my $graph = eval { get_graph($server) };
my $err = $@ || !$graph;
warn "update_graphs error: $err" if $err;
my $ttl = $err || length($graph)==0 ? 10 : 7200;
my $ttl = $err || length($graph) == 0 ? 10 : 7200;

my $mtime = time;
$self->request->update_mtime($mtime);

$self->cache_control(sprintf('max-age=%i, s-maxage=%i', $ttl, $ttl * 0.75));

if ($err) {
return 500, "Server error\n", "text/plain";
}

return OK, $graph, 'image/png';
}

sub get_graph {
my $server = shift;
# in kubernetes the hostname is 'web' and we might not be able to
# reach this service with the external name from the splash
# instance; todo: detect kubernetes and only change it then?
$url->host("web");
$url->path($server->url);
$url->query_form(graph_only => 1);

my $data = JSON::encode_json(
{ url => $url->as_string(),
timeout => 10,
viewport => "501x233",
height => 233,
resource_timeout => 5,
wait => 0.5,
scale_method => "vector",
}
);

my $resp =
$ua->post("http://splash:8050/render.png",
"Content-Type" => "application/json",
Content => $data,
);

unless ($resp->is_success) {
warn "could not get splash render: ", $resp->code;
warn "resp: ", $resp->decoded_content();
return undef;
}
return $resp->decoded_content();
}

1;

0 comments on commit f08e2f7

Please sign in to comment.