villebro commented on code in PR #2577:
URL: 
https://github.com/apache/datafusion-ballista/pull/2577#discussion_r4251703420


##########
dev/docker/result-service-entrypoint.sh:
##########
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -e
+
+/root/ballista-result-service "$@"

Review Comment:
   Good catch, and thanks for the repro. d2d6a574 `exec`s the service, so it 
runs as PID 1 and its SIGTERM handler starts the drain. I've taken #2589 for 
the scheduler, executor and standalone images, and the PR description links to 
it.



##########
ballista/result-service/src/metrics.rs:
##########
@@ -0,0 +1,234 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Metrics for result fetches.
+
+use std::sync::Arc;
+use std::time::Duration;
+
+use ballista_core::error::Result;
+
+/// How a result fetch ended.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum FetchOutcome {
+    /// The whole stream was delivered.
+    Completed,
+    /// The executor or the stream returned an error.
+    Failed,
+    /// The client went away before the stream ended.
+    Cancelled,
+}
+
+/// Records result fetches.
+pub trait ResultMetricsCollector: Send + Sync {
+    /// A fetch started.
+    fn record_started(&self);
+
+    /// A fetch relayed `bytes` of Flight data to its client.
+    fn record_bytes(&self, bytes: u64);
+
+    /// A fetch ended after `elapsed`.
+    fn record_finished(&self, outcome: FetchOutcome, elapsed: Duration);
+
+    /// The metrics and their content type, or `None` if this collector exports
+    /// none.
+    fn gather_metrics(&self) -> Result<Option<(Vec<u8>, String)>>;
+}
+
+/// A collector that records nothing.
+#[cfg(any(test, not(feature = "prometheus-metrics")))]
+#[derive(Default)]
+pub struct NoopMetricsCollector;
+
+#[cfg(any(test, not(feature = "prometheus-metrics")))]
+impl ResultMetricsCollector for NoopMetricsCollector {
+    fn record_started(&self) {}
+
+    fn record_bytes(&self, _bytes: u64) {}
+
+    fn record_finished(&self, _outcome: FetchOutcome, _elapsed: Duration) {}
+
+    fn gather_metrics(&self) -> Result<Option<(Vec<u8>, String)>> {
+        Ok(None)
+    }
+}
+
+/// The Prometheus collector with the `prometheus-metrics` feature, otherwise
+/// one that records nothing.
+pub fn default_metrics_collector() -> Result<Arc<dyn ResultMetricsCollector>> {
+    #[cfg(feature = "prometheus-metrics")]
+    {
+        Ok(Arc::new(PrometheusMetricsCollector::new(

Review Comment:
   Good find. 77f0b6f4 adds `PrometheusMetricsCollector::current()`, which 
registers the metrics in the default registry once and shares the collector, 
like the scheduler's does. A new test checks that two calls return the same 
collector; without the cache it fails with `AlreadyReg`.



##########
ballista/result-service/src/lib.rs:
##########
@@ -0,0 +1,410 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Ballista Result Service: serves query results to clients by forwarding each

Review Comment:
   Done in c3983c05. Everything public was already documented, so it builds 
without warnings.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to