Skip to content

Commit

Permalink
Updates (digitalocean#28)
Browse files Browse the repository at this point in the history
Updates

* Adding .clang-format to keep formatting consistent
* Adding regression test for prom_histogram_buckets
* Added format command to auto
* Formatted project

Co-authored-by: Demitri Swan <[email protected]>
  • Loading branch information
miroswan and Demitri Swan authored Sep 28, 2020
1 parent b013d62 commit 4f8b88e
Show file tree
Hide file tree
Showing 90 changed files with 1,099 additions and 1,356 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
ColumnLimit: 120
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ttyrecord
_CPack_Packages/
*deb
*tar.gz
*vgcore*
*vgcore*
*.o
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ project directory and execute `make`. This process will build the development co
run the unit tests and execute the smoke tests.

The stages of the development workflow are automated via `auto` which can be found in the root of this project directory.
Execute `./auto -h` for information regarding the different subcommands. Information for each subcommand can be
obtained by executing `./auto CMD -h`.
Execute `bash auto -h` for information regarding the different subcommands. Information for each subcommand can be
obtained by executing `bash auto CMD -h`.

## Contributing

Expand All @@ -54,7 +54,7 @@ communication process so please do not be shy. Speak up!
### Coding Rules for Contribution

* Please follow the general coding style already present in the project.
* clang-format your code with style Google.
* clang-format your code by executing `bash auto format` before submitting a PR.
* Every struct must have a constructor function and destructor function.
* Every method must pass a pointer to the target struct as the first argument.
* Every function that is not a constructor or destructor and does not return a value must return an int to signify
Expand Down
2 changes: 1 addition & 1 deletion auto
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ main(){
usage
exit 0
} ;;
( build | dev | test | package | docs | clean | smoke ) {
( build | dev | test | package | docs | clean | smoke | format ) {
shift
exec "${lib}/cmd/${cmd}" $@ || exit $?
} ;;
Expand Down
2 changes: 1 addition & 1 deletion autolib/cmd/dev
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ run(){
pushd docker > /dev/null || return $?
make || {
r=$?
outlib_output_error "Docker Build Failure"
autolib_output_error "Docker Build Failure"
return $r
}
popd > /dev/null
Expand Down
73 changes: 73 additions & 0 deletions autolib/cmd/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

########################################################################################################################
# Meta
########################################################################################################################

# Propagate environment variables
if [[ "$AUTO_DEBUG" == "1" ]]; then
set -x
export AUTO_DEBUG=1
fi

PROGRAM_NAME=$(basename $0)

short="Format the project"
read -d '' long <<EOF
You SHOULD execute this command within the development container.
EOF

usage(){
cat <<EOF
$PROGRAM_NAME [-h]
$short
EOF
}

########################################################################################################################
# End Meta
########################################################################################################################

source "$(dirname ${BASH_SOURCE[0]})/../autolib.sh"

main(){
declare -i return_value=0

while getopts "h" opt; do
case $opt in
( h ) {
usage && exit 0
} ;;
esac
done

while read file_path; do
local temp
temp=$(mktemp) || {
return_value=$?
autolib_output_error "failed to create temp file"
exit $return_code
}

{
clang-format --style=file $file_path > $temp &&
sed -i 's/Copyright 2019-2020/Copyright 2019-2020/g' $temp &&
mv $temp $file_path
} || {
return_value=$?
autolib_output_error "failed to format project"
exit $return_code
}
done < <(find ${PWD} -regextype posix-extended -type f -regex ".*/prom[[:alnum:]_-]+\.[c|h]" ! -regex '.*CPack.*') || {
return_value=$?
autolib_output_error "failed to find relevant C project files"
exit $return_code
}
}

[[ $BASH_SOURCE == $0 ]] && main $@
42 changes: 40 additions & 2 deletions autolib/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FROM __DOCKER_IMAGE__
RUN set -x && \
apt-get update && \
apt-get install -y apt-utils software-properties-common && \
apt-get install -y apt-utils software-properties-common clang-format && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update -y && \
apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc-10 libmicrohttpd-dev doxygen graphviz && \
Expand Down Expand Up @@ -43,6 +43,36 @@ FROM __DOCKER_IMAGE__
ENV GCC_VERSION 10.1.0
RUN set -x && \
apt-get update && \
apt-get install -y apt-utils clang-format && \
apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc libmicrohttpd-dev doxygen graphviz && \
curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt && \
cp /opt/cmake-3.14.5-Linux-x86_64/bin/* /usr/local/bin/ && \
cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/ && \
curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz 2> /dev/null | tar xzf - -C /usr/local && \
mkdir -p /gopath/{src,bin} && \
printf 'export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n' > /root/.bash_profile && \
printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint && \
chmod +x /entrypoint && \
GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json && \
GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json && \
GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog && \
GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
ENTRYPOINT ["/entrypoint"]
EOF
}

autolib_debian_jessie_template() {
cat <<EOF
FROM __DOCKER_IMAGE__
ENV GCC_VERSION 10.1.0
RUN set -x && \
apt-get update && \
apt-get install -y apt-utils && \
Expand All @@ -64,6 +94,7 @@ RUN set -x && \
WORKDIR /code
ENTRYPOINT ["/entrypoint"]
EOF
}

Expand All @@ -78,13 +109,20 @@ autolib_write_dockerfile(){
return $r
}
} ;;
( ubuntu:16.04 | debian:buster | debian:stretch | debian:jessie ) {
( ubuntu:16.04 | debian:buster | debian:stretch ) {
autolib_old_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || {
r=$?
autolib_output_error "failed to generate dockerfile"
return $r
}
} ;;
( debian:jessie ) {
autolib_debian_jessie_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || {
r=$?
autolib_output_error "failed to generate dockerfile"
return $r
}
} ;;
( * ) {
r=1
autolib_output_error "unsupported DOCKER_IMAGE: $docker_image"
Expand Down
Binary file added example/example
Binary file not shown.
4 changes: 2 additions & 2 deletions prom/include/prom_alloc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 DigitalOcean Inc.
Copyright 2019-2020 DigitalOcean Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,4 +45,4 @@ limitations under the License.
*/
#define prom_free free

#endif // PROM_ALLOC_H
#endif // PROM_ALLOC_H
10 changes: 5 additions & 5 deletions prom/include/prom_collector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 DigitalOcean Inc.
Copyright 2019-2020 DigitalOcean Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,14 +40,14 @@ typedef struct prom_collector prom_collector_t;
* @param self The target prom_collector_t*
* @return The prom_map_t* containing the collected metrics
*/
typedef prom_map_t* prom_collect_fn(prom_collector_t* self);
typedef prom_map_t *prom_collect_fn(prom_collector_t *self);

/**
* @brief Create a collector
* @param name The name of the collector. The name MUST NOT be default or process.
* @return The constructed prom_collector_t*
*/
prom_collector_t* prom_collector_new(const char *name);
prom_collector_t *prom_collector_new(const char *name);

/**
*@brief Construct a prom_collector_t* which includes the default process metrics
Expand All @@ -57,7 +57,7 @@ prom_collector_t* prom_collector_new(const char *name);
* by the host environment. Otherwise, pass a string to said path.
* @return The constructed prom_collector_t*
*/
prom_collector_t* prom_collector_process_new(const char *limits_path, const char *stat_path);
prom_collector_t *prom_collector_process_new(const char *limits_path, const char *stat_path);

/**
* @brief Destroy a collector. You MUST set self to NULL after destruction.
Expand Down Expand Up @@ -97,4 +97,4 @@ int prom_collector_add_metric(prom_collector_t *self, prom_metric_t *metric);
*/
int prom_collector_set_collect_fn(prom_collector_t *self, prom_collect_fn *fn);

#endif // PROM_COLLECTOR_H
#endif // PROM_COLLECTOR_H
13 changes: 6 additions & 7 deletions prom/include/prom_collector_registry.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 DigitalOcean Inc.
Copyright 2019-2020 DigitalOcean Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,7 @@ int prom_collector_registry_default_init(void);
* @param name The name of the collector registry. It MUST NOT be default.
* @return The constructed prom_collector_registry_t*
*/
prom_collector_registry_t* prom_collector_registry_new(const char *name);
prom_collector_registry_t *prom_collector_registry_new(const char *name);

/**
* @brief Destroy a collector registry. You MUST set self to NULL after destruction.
Expand All @@ -74,7 +74,7 @@ int prom_collector_registry_enable_process_metrics(prom_collector_registry_t *se
* @param metric The metric to register on PROM_DEFAULT_COLLECTOR_REGISTRY*
* @return The registered prom_metric_t*
*/
prom_metric_t* prom_collector_registry_must_register_metric(prom_metric_t *metric);
prom_metric_t *prom_collector_registry_must_register_metric(prom_metric_t *metric);

/**
* @brief Registers a metric with the default collector on PROM_DEFAULT_COLLECTOR_REGISTRY. Returns an non-zero integer
Expand Down Expand Up @@ -104,7 +104,7 @@ int prom_collector_registry_register_collector(prom_collector_registry_t *self,
* @param self The target prom_collector_registry_t*
* @return The string int he default metric exposition format.
*/
const char* prom_collector_registry_bridge(prom_collector_registry_t *self);
const char *prom_collector_registry_bridge(prom_collector_registry_t *self);

/**
*@brief Validates that the given metric name complies with the specification:
Expand All @@ -117,7 +117,6 @@ const char* prom_collector_registry_bridge(prom_collector_registry_t *self);
* @param metric_name The metric name to validate
* @return A non-zero integer value upon failure
*/
int prom_collector_registry_validate_metric_name(prom_collector_registry_t *self,
const char *metric_name);
int prom_collector_registry_validate_metric_name(prom_collector_registry_t *self, const char *metric_name);

#endif // PROM_H
#endif // PROM_H
12 changes: 3 additions & 9 deletions prom/include/prom_counter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 DigitalOcean Inc.
Copyright 2019-2020 DigitalOcean Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/


#ifndef PROM_COUNTER_H
#define PROM_COUNTER_H

Expand Down Expand Up @@ -54,10 +53,7 @@ typedef prom_metric_t prom_counter_t;
* // An example without labels
* prom_counter_new("foo", "foo is a counter without labels", 0, NULL);
*/
prom_counter_t* prom_counter_new(const char *name,
const char *help,
size_t label_key_count,
const char **label_keys);
prom_counter_t *prom_counter_new(const char *name, const char *help, size_t label_key_count, const char **label_keys);

/**
* @brief Destroys a prom_counter_t*. You must set self to NULL after destruction. A non-zero integer value will be
Expand All @@ -67,7 +63,6 @@ prom_counter_t* prom_counter_new(const char *name,
*/
int prom_counter_destroy(prom_counter_t *self);


/**
* @brief Increment the prom_counter_t by 1. A non-zero integer value will be returned on failure.
* @param self The target prom_counter_t*
Expand All @@ -86,7 +81,6 @@ int prom_counter_destroy(prom_counter_t *self);
*/
int prom_counter_inc(prom_counter_t *self, const char **label_values);


/**
* @brief Add the value to the prom_counter_t*. A non-zero integer value will be returned on failure.
* @param self The target prom_counter_t*
Expand All @@ -106,4 +100,4 @@ int prom_counter_inc(prom_counter_t *self, const char **label_values);
*/
int prom_counter_add(prom_counter_t *self, double r_value, const char **label_values);

#endif // PROM_COUNTER_H
#endif // PROM_COUNTER_H
Loading

0 comments on commit 4f8b88e

Please sign in to comment.