aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/yamas/YamasResponse.java
blob: 232978062b39d2344654a114c1eb683e817b1c25 (plain) (blame)
1
2
3
4
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.http.yamas;

import ai.vespa.metricsproxy.metric.model.MetricsPacket;
import ai.vespa.metricsproxy.metric.model.json.YamasJsonUtil;
import com.yahoo.container.jdisc.HttpResponse;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;


/**
 * @author olaa
 */
public class YamasResponse extends HttpResponse {

    private final List<MetricsPacket> metrics;
    private boolean useJsonl;

    public YamasResponse(int code, List<MetricsPacket> metrics, boolean useJsonl) {
        super(code);
        this.metrics = metrics;
        this.useJsonl = useJsonl;
    }

    @Override
    public String getContentType() {
        return "application/json";
    }

    @Override
    public void render(OutputStream outputStream) throws IOException {
        if (useJsonl)
            YamasJsonUtil.toJsonl(metrics, outputStream, false);
        else
            YamasJsonUtil.toJson(metrics, outputStream, false);
    }

}