Skip to content

Commit db11544

Browse files
committed
Add prometheus dataset support
This fix adds prometheus dataset support, with prometheus library in golang. Signed-off-by: Yong Tang <[email protected]>
1 parent f76d965 commit db11544

File tree

20 files changed

+527
-3
lines changed

20 files changed

+527
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ wheelhouse
3030

3131
# Lint
3232
.pylint
33+
34+
# Prometheus
35+
.coredns
36+
.prometheus

.kokorun/io_cpu.sh

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bash -x -e tests/test_ignite/start_ignite.sh
5050
bash -x -e tests/test_kafka/kafka_test.sh start kafka
5151
bash -x -e tests/test_kinesis/kinesis_test.sh start kinesis
5252
bash -x -e tests/test_pubsub/pubsub_test.sh start pubsub
53-
53+
bash -x -e tests/test_prometheus/prometheus_test.sh start
5454

5555
export TENSORFLOW_INSTALL="$(python setup.py --package-version)"
5656
PYTHON_VERSION=$(python -c 'import sys; print(str(sys.version_info[0]))')
@@ -59,6 +59,11 @@ if [[ $PYTHON_VERSION == "2" ]]; then
5959
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:14.04 bash -x -e .travis/python.release.sh "${TENSORFLOW_INSTALL}" python
6060

6161
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:16.04 bash -x -e .travis/wheel.test.sh python
62+
63+
## Stop then restart prometheus
64+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
65+
bash -x -e tests/test_prometheus/prometheus_test.sh start
66+
6267
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:18.04 bash -x -e .travis/wheel.test.sh python
6368

6469
## R
@@ -69,21 +74,48 @@ if [[ $PYTHON_VERSION == "2" ]]; then
6974
## TF 2.0
7075
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:14.04 bash -x -e .travis/python.release.sh "tensorflow==2.0.0b1" --preview ${KOKORO_BUILD_NUMBER} python
7176

77+
## Stop then restart prometheus
78+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
79+
bash -x -e tests/test_prometheus/prometheus_test.sh start
80+
7281
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:16.04 bash -x -e .travis/wheel.test.sh python
82+
83+
## Stop then restart prometheus
84+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
85+
bash -x -e tests/test_prometheus/prometheus_test.sh start
86+
7387
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:18.04 bash -x -e .travis/wheel.test.sh python
7488
else
7589
## Python 2
7690
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:14.04 bash -x -e .travis/python.release.sh "${TENSORFLOW_INSTALL}" python3.5 python3.6
7791

92+
## Stop then restart prometheus
93+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
94+
bash -x -e tests/test_prometheus/prometheus_test.sh start
95+
7896
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:16.04 bash -x -e .travis/wheel.test.sh python3.5
97+
98+
## Stop then restart prometheus
99+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
100+
bash -x -e tests/test_prometheus/prometheus_test.sh start
101+
79102
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:18.04 bash -x -e .travis/wheel.test.sh python3.6
80103

81104
sudo rm -rf dist wheelhouse
82105

83106
## TF 2.0
84107
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:14.04 bash -x -e .travis/python.release.sh "tensorflow==2.0.0b1" --preview ${KOKORO_BUILD_NUMBER} python3.5 python3.6
85108

109+
## Stop then restart prometheus
110+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
111+
bash -x -e tests/test_prometheus/prometheus_test.sh start
112+
86113
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:16.04 bash -x -e .travis/wheel.test.sh python3.5
114+
115+
## Stop then restart prometheus
116+
bash -x -e tests/test_prometheus/prometheus_test.sh stop
117+
bash -x -e tests/test_prometheus/prometheus_test.sh start
118+
87119
docker run -i --rm -v $PWD:/v -w /v --net=host buildpack-deps:18.04 bash -x -e .travis/wheel.test.sh python3.6
88120
fi
89121

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ install:
1616
bash -x -e tests/test_kafka/kafka_test.sh start kafka
1717
bash -x -e tests/test_kinesis/kinesis_test.sh start kinesis
1818
bash -x -e tests/test_pubsub/pubsub_test.sh start pubsub
19+
bash -x -e tests/test_prometheus/prometheus_test.sh start
1920
- sudo -H python -m pip install -q -U twine --ignore-installed six
2021
- twine --version
2122
- export TENSORFLOW_INSTALL="$(python setup.py --package-version)"

.travis/bazel.configure.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ python get-pip.py -q
1313
python -m pip --version
1414
if [[ $(uname) == "Darwin" ]]; then
1515
python -m pip install -q -U matplotlib numpy --ignore-installed six
16+
else
17+
apt-get -y -qq install git
1618
fi
1719
python -m pip install -q --ignore-installed six "${TENSORFLOW_INSTALL}"
1820
python -c 'import tensorflow as tf; print(tf.version.VERSION)'

.travis/python3.7+.release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set -e -x
2121

2222
apt-get -y -qq update && apt-get -y -qq install \
2323
software-properties-common \
24-
gcc g++ make patch \
24+
gcc g++ make patch git \
2525
unzip curl patchelf
2626

2727
add-apt-repository -y ppa:deadsnakes/ppa

.travis/wheel.test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if [[ "$#" -gt 0 ]]; then
1717
fi
1818
if [[ $(uname) == "Linux" ]]; then
1919
apt-get -y -qq update
20-
apt-get -y -qq install $PYTHON_VERSION ffmpeg
20+
apt-get -y -qq install $PYTHON_VERSION ffmpeg dnsutils
2121
curl -sSOL https://bootstrap.pypa.io/get-pip.py
2222
$PYTHON_VERSION get-pip.py -q
2323
fi

WORKSPACE

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,49 @@ http_archive(
436436
"https://download.savannah.gnu.org/releases/freetype/freetype-2.10.0.tar.gz",
437437
],
438438
)
439+
440+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
441+
442+
# Note: patch is needed as we need to resolve multiple zlib dependencies.
443+
# Patch was created with:
444+
# diff -Naur a b > rules_go.patch
445+
http_archive(
446+
name = "io_bazel_rules_go",
447+
patch_args = ["-p1"],
448+
patches = [
449+
"//third_party:rules_go.patch",
450+
],
451+
sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d",
452+
urls = [
453+
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz",
454+
"https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz",
455+
],
456+
)
457+
458+
http_archive(
459+
name = "bazel_gazelle",
460+
sha256 = "3c681998538231a2d24d0c07ed5a7658cb72bfb5fd4bf9911157c0e9ac6a2687",
461+
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.17.0/bazel-gazelle-0.17.0.tar.gz"],
462+
)
463+
464+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
465+
466+
go_rules_dependencies()
467+
468+
go_register_toolchains()
469+
470+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
471+
472+
gazelle_dependencies()
473+
474+
go_repository(
475+
name = "com_github_prometheus_common",
476+
importpath = "github.com/prometheus/common",
477+
tag = "v0.4.1",
478+
)
479+
480+
go_repository(
481+
name = "com_github_prometheus_client_golang",
482+
importpath = "github.com/prometheus/client_golang",
483+
tag = "v0.9.3",
484+
)

tensorflow_io/core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ cc_binary(
6363
"//tensorflow_io/hdf5:hdf5_ops",
6464
"//tensorflow_io/lmdb:lmdb_ops",
6565
"//tensorflow_io/mnist:mnist_ops",
66+
"//tensorflow_io/prometheus:prometheus_ops",
6667
"//tensorflow_io/text:text_ops",
6768
"@libarchive",
6869
"@local_config_tf//:libtensorflow_framework",

tensorflow_io/prometheus/BUILD

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
licenses(["notice"]) # Apache 2.0
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
cc_library(
6+
name = "prometheus_ops",
7+
srcs = [
8+
#"//tensorflow_io/prometheus/go:prometheus.a",
9+
#"//tensorflow_io/prometheus/go:prometheus.h",
10+
"kernels/prometheus_input.cc",
11+
"ops/prometheus_ops.cc",
12+
],
13+
copts = [
14+
"-pthread",
15+
"-std=c++11",
16+
"-DNDEBUG",
17+
],
18+
includes = [
19+
".",
20+
],
21+
linkstatic = True,
22+
deps = [
23+
"//tensorflow_io/core:dataset_ops",
24+
"//tensorflow_io/prometheus/go:prometheus.cc",
25+
],
26+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""PrometheusInput
16+
17+
@@PrometheusDataset
18+
"""
19+
20+
from __future__ import absolute_import
21+
from __future__ import division
22+
from __future__ import print_function
23+
24+
from tensorflow_io.prometheus.python.ops.prometheus_ops import PrometheusDataset
25+
26+
from tensorflow.python.util.all_util import remove_undocumented
27+
28+
_allowed_symbols = [
29+
"PrometheusDataset",
30+
]
31+
32+
remove_undocumented(__name__, allowed_exception_list=_allowed_symbols)

0 commit comments

Comments
 (0)