Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service-config and expose metrics #97

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate-ipfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: ["main"]

env:
GO_VERSION: "1.18"
GO_VERSION: "1.19"
GO111MODULE: "on"
OPERATOR_IMAGE: "quay.io/redhat-et-ipfs/ipfs-operator"
BUNDLE_IMAGE: "quay.io/redhat-et-ipfs/ipfs-operator-bundle"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.19 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/circuitrelay_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ma "github.com/multiformats/go-multiaddr"
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/ipfscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type IpfsClusterSpec struct {
// should use when reproviding content.
// +optional
Reprovider ReprovideSettings `json:"reprovider,omitempty"`
// stats determines whether metrics should be enabled.
// +optional
Stats bool `json:"stats"`
}

type IpfsClusterStatus struct {
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/cluster.ipfs.io_ipfsclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ spec:
- roots
type: string
type: object
stats:
description: stats determines whether metrics should be enabled.
type: boolean
required:
- clusterStorage
- follows
Expand Down
4 changes: 2 additions & 2 deletions controllers/circuitrelay_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
relaydaemon "github.com/libp2p/go-libp2p-relay-daemon"
"github.com/libp2p/go-libp2p/core/crypto"
peer "github.com/libp2p/go-libp2p/core/peer"
relayv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay"
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
"github.com/redhat-et/ipfs-operator/controllers/utils"
Expand Down
20 changes: 20 additions & 0 deletions controllers/ipfs_cluster_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controllers

import (
"github.com/ipfs-cluster/ipfs-cluster/cmdutils"
ma "github.com/multiformats/go-multiaddr"
)

func GetDefaultServiceConfig() *cmdutils.ConfigHelper {
cfgHelper := cmdutils.NewConfigHelper("", "", "crdt", "badger")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use flatfs for the datastore so that should also be set here. Maybe this can be parameterized?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coryschwartz Does IPFS Cluster maintain its own blockstore or does this value need to be in sync with what we use for the IPFS nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have copied this from ipfs-cluster project. Default value is badger.
From the code - here I can see flatfs is not a valid value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsanjuan We would need to use flatfs here as well correct? ipfs-cluster/cmdutils doesn't seem to support flatfs as a valid value for the datastore, will we need to add support for it?

err := cfgHelper.Manager().Default()
if err != nil {
return nil
}
return cfgHelper
}

func EnableMetrics(serviceConfig *cmdutils.Configs) {
serviceConfig.Metrics.EnableStats = true
serviceConfig.Metrics.PrometheusEndpoint, _ = ma.NewMultiaddr("/ip4/0.0.0.0/tcp/8888")
}
4 changes: 2 additions & 2 deletions controllers/ipfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/hex"
"fmt"

ci "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
ci "github.com/libp2p/go-libp2p/core/crypto"
peer "github.com/libp2p/go-libp2p/core/peer"
)

func newClusterSecret() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/ipfscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
"github.com/redhat-et/ipfs-operator/controllers/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion controllers/ipfscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var _ = Describe("IPFS Reconciler", func() {
// should not have errored
Expect(fn()).NotTo(HaveOccurred())
// the configmap should be populated with the following scripts
Expect(len(configMapScripts.Data)).To(Equal(2))
Expect(len(configMapScripts.Data)).To(Equal(3))

expectedKeys := []string{
controllers.ScriptConfigureIPFS,
Expand Down
14 changes: 13 additions & 1 deletion controllers/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/alecthomas/units"
"github.com/ipfs/kubo/config"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
clusterv1alpha1 "github.com/redhat-et/ipfs-operator/api/v1alpha1"
"github.com/redhat-et/ipfs-operator/controllers/scripts"
Expand Down Expand Up @@ -101,6 +101,17 @@ func (r *IpfsClusterReconciler) ConfigMapScripts(
string(reproviderStrategy),
)

serviceConfig := GetDefaultServiceConfig()
if m.Spec.Stats {
EnableMetrics(serviceConfig.Configs())
}

serviceConfigFile, err := serviceConfig.Manager().ToJSON()
if err != nil {
log.Error(err, "could not marshal service config file")
return utils.ErrFunc(fmt.Errorf("error converting serviceConfig to JSON: %w", err)), ""
}

expected := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: cmName,
Expand All @@ -109,6 +120,7 @@ func (r *IpfsClusterReconciler) ConfigMapScripts(
Data: map[string]string{
"entrypoint.sh": scripts.IPFSClusterEntrypoint,
"configure-ipfs.sh": configScript,
"service.json": string(serviceConfigFile),
},
}
expected.DeepCopyInto(cm)
Expand Down
9 changes: 7 additions & 2 deletions controllers/scripts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/alecthomas/units"
"github.com/ipfs/kubo/config"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p/core/peer"
)

type configureIpfsOpts struct {
Expand Down Expand Up @@ -92,6 +92,8 @@ run_ipfs_cluster() {
log "🔍 reading hostname"
PEER_HOSTNAME=$(cat /proc/sys/kernel/hostname)
log "starting ipfs-cluster on ${PEER_HOSTNAME}"
cp /custom/service.json /data/ipfs-cluster/
sed -i '/peername/c\ \"peername\" : \"'$PEER_HOSTNAME'\",' /data/ipfs-cluster/service.json

grep -q ".*-0$" /proc/sys/kernel/hostname
if [ $? -eq 0 ]; then
Expand Down Expand Up @@ -236,7 +238,10 @@ func applyIPFSClusterK8sDefaults(conf *config.Config, storageMax string, peers [
conf.Bootstrap = config.DefaultBootstrapAddresses
conf.Addresses.API = config.Strings{"/ip4/0.0.0.0/tcp/5001"}
conf.Addresses.Gateway = config.Strings{"/ip4/0.0.0.0/tcp/8080"}
conf.Swarm.ConnMgr.HighWater = 2000
highWater := &config.OptionalInteger{}
if err := highWater.UnmarshalJSON([]byte("2000")); err == nil {
conf.Swarm.ConnMgr.HighWater = highWater
}
conf.Datastore.BloomFilterSize = 1048576
conf.Datastore.StorageMax = storageMax
conf.Addresses.Swarm = []string{"/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001"}
Expand Down
2 changes: 1 addition & 1 deletion controllers/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
// ipfsMountPath Defines where the IPFS volume is mounted.
ipfsMountPath = "/data/ipfs"
// ipfsImage Defines which image we should pull when running IPFS containers.
ipfsImage = "docker.io/ipfs/kubo:v0.14.0"
ipfsImage = "docker.io/ipfs/kubo:v0.17.0"
)

// StatefulSet Returns a mutate function that creates a StatefulSet for the
Expand Down
Loading