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

fix: containerized ossfs metrics #931

Merged
merged 6 commits into from
Mar 4, 2024
Merged
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 build/fuse-clients/ossfs/install-ossfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "TARGETPLATFORM: $TARGETPLATFORM"
echo "installing ossfs"
case $TARGETPLATFORM in
linux/amd64)
yum install -y https://ack-csiplugin.oss-cn-hangzhou.aliyuncs.com/pre/ossfs/ossfs_1.88.3_centos8.0_x86_64.rpm
yum install -y https://ack-csiplugin.oss-cn-hangzhou.aliyuncs.com/pre/ossfs/ossfs_1.88.4_centos8.0_x86_64.rpm
Copy link
Contributor

Choose a reason for hiding this comment

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

we are not going to support metrics on arm64 platform?

Copy link
Member Author

Choose a reason for hiding this comment

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

We've never supported ossfs metrics on arm64 ever. It will be available after ossfs rebasing 1.91 version.

;;
linux/arm64)
yum install -y \
Expand Down
142 changes: 83 additions & 59 deletions pkg/metric/fuse_stat_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metric

import (
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -476,7 +477,7 @@ func NewFuseStatCollector() (Collector, error) {
}, nil
}

func getPodUID(fsClientPathPrefix string, fsClientType string) ([]string, error) {
func getSubDirArray(fsClientPathPrefix string, fsClientType string) ([]string, error) {
fsClientPath := fsClientPathPrefix + fsClientType
if !utils.IsFileExisting(fsClientPath) {
_ = os.MkdirAll(fsClientPath, os.FileMode(0755))
Expand Down Expand Up @@ -612,71 +613,94 @@ func (p *usFsStatCollector) Update(ch chan<- prometheus.Metric) error {
fsClientInfo := new(fuseInfo)
// foreach fuse client type
for _, fsClientType := range fsClientTypeArray {
// get pod uid
podUIDArray, err := getPodUID(fsClientPathPrefix, fsClientType)
// exclusive case: podid
// shared case: sha256(pvname)
subDirArray, err := getSubDirArray(fsClientPathPrefix, fsClientType)
if err != nil {
continue
}
//foreach pod uid
for _, podUID := range podUIDArray {
//get pod info
podInfoArray, err := readFirstLines(fsClientPathPrefix + fsClientType + "/" + podUID + "/" + podInfo)
if err != nil {
for _, subDir := range subDirArray {
//stat pod_info, if exists, updateExclusiveMetrics; else updateSharedMetrics
if utils.IsFileExisting(filepath.Join(fsClientPathPrefix, fsClientType, subDir, podInfo)) {
// subDir -> podUid
p.updateExclusiveMetrics(fsClientType, subDir, fsClientInfo, ch)
continue
}
//namespace pod_name uid top_number
if len(podInfoArray) < 4 {
continue
}
fsClientInfo.Namespace = podInfoArray[0]
fsClientInfo.PodName = podInfoArray[1]
fsClientInfo.PodUID = podInfoArray[2]
// list volume from pod
volumeArray, err := listDirectory(fsClientPathPrefix + fsClientType + "/" + podUID + "/")
if err != nil {
continue
}
// foreach volume
for _, volume := range volumeArray {
mountPointInfoArray, err := readFirstLines(fsClientPathPrefix + fsClientType + "/" + podUID + "/" + volume + "/" + mountPointInfo)
if err != nil {
continue
}
//fuse_client storage_type filesystem_id pv_name mount_point
if len(mountPointInfoArray) < 5 {
continue
}
fsClientInfo.ClientName = mountPointInfoArray[0]
fsClientInfo.BackendStorage = mountPointInfoArray[1]
fsClientInfo.BucketName = mountPointInfoArray[2]
fsClientInfo.PvName = mountPointInfoArray[3]
fsClientInfo.MountPoint = mountPointInfoArray[4]
// foreach counter metrics
for _, counterType := range counterTypeArray {
metricsArray, err := readFirstLines(fsClientPathPrefix + fsClientType + "/" + podUID + "/" + volume + "/" + counterType)
if err != nil {
continue
}
p.postCounterMetrics(counterType, fsClientInfo, metricsArray, ch)
}
// foreach hot_top_file metrics
for _, hotSpotType := range hotSpotArray {
metricsArray, err := readFirstLines(fsClientPathPrefix + fsClientType + "/" + podUID + "/" + volume + "/" + hotSpotType)
if err != nil {
continue
}
p.postHotTopFileMetrics(hotSpotType, fsClientInfo, metricsArray, ch)
}
// foreach backend counter metrics
for _, backendCounterType := range backendCounterTypeArray {
metricsArray, err := readFirstLines(fsClientPathPrefix + fsClientType + "/" + podUID + "/" + volume + "/" + backendCounterType)
if err != nil {
continue
}
p.postBackendCounterMetrics(backendCounterType, fsClientInfo, metricsArray, ch)
}
}
// subDir -> shaVol
p.updateSharedMetrics(fsClientType, subDir, fsClientInfo, ch)
}
}
return nil
}

func (p *usFsStatCollector) updateExclusiveMetrics(fsClientType, podUid string, fsClientInfo *fuseInfo, ch chan<- prometheus.Metric) {
//get pod info
podInfoArray, err := readFirstLines(filepath.Join(fsClientPathPrefix, fsClientType, podUid, podInfo))
if err != nil {
return
}
//namespace pod_name uid top_number
if len(podInfoArray) < 4 {
return
}
fsClientInfo.Namespace = podInfoArray[0]
fsClientInfo.PodName = podInfoArray[1]
fsClientInfo.PodUID = podInfoArray[2]
// list volume from pod
volumeArray, err := listDirectory(filepath.Join(fsClientPathPrefix, fsClientType, podUid))
if err != nil {
return
}
// foreach volume
for _, volume := range volumeArray {
volPath := filepath.Join(fsClientPathPrefix, fsClientType, podUid, volume)
p.postVolMetrics(volPath, fsClientInfo, ch)
}
}

func (p *usFsStatCollector) updateSharedMetrics(fsClientType, subDir string, fsClientInfo *fuseInfo, ch chan<- prometheus.Metric) {

volPath := filepath.Join(fsClientPathPrefix, fsClientType, subDir)
p.postVolMetrics(volPath, fsClientInfo, ch)
}

func (p *usFsStatCollector) postVolMetrics(volPath string, fsClientInfo *fuseInfo, ch chan<- prometheus.Metric) {
mountPointInfoArray, err := readFirstLines(filepath.Join(volPath, mountPointInfo))
if err != nil {
return
}
//fuse_client storage_type filesystem_id pv_name mount_point
if len(mountPointInfoArray) < 5 {
return
}
fsClientInfo.ClientName = mountPointInfoArray[0]
fsClientInfo.BackendStorage = mountPointInfoArray[1]
fsClientInfo.BucketName = mountPointInfoArray[2]
fsClientInfo.PvName = mountPointInfoArray[3]
fsClientInfo.MountPoint = mountPointInfoArray[4]
// foreach counter metrics
for _, counterType := range counterTypeArray {
metricsArray, err := readFirstLines(filepath.Join(volPath, counterType))
if err != nil {
continue
}
p.postCounterMetrics(counterType, fsClientInfo, metricsArray, ch)
}
// foreach hot_top_file metrics
for _, hotSpotType := range hotSpotArray {
metricsArray, err := readFirstLines(filepath.Join(volPath, hotSpotType))
if err != nil {
continue
}
p.postHotTopFileMetrics(hotSpotType, fsClientInfo, metricsArray, ch)
}
// foreach backend counter metrics
for _, backendCounterType := range backendCounterTypeArray {
metricsArray, err := readFirstLines(filepath.Join(volPath, backendCounterType))
if err != nil {
continue
}
p.postBackendCounterMetrics(backendCounterType, fsClientInfo, metricsArray, ch)
}
}
2 changes: 1 addition & 1 deletion pkg/mounter/ossfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/utils/pointer"
)

var defaultOssfsImageTag = "36f22e0-aliyun"
var defaultOssfsImageTag = "4af1b0e-aliyun"

const (
hostPrefix = "/host"
Expand Down
13 changes: 11 additions & 2 deletions pkg/oss/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
JindoFsType = "jindofs"
// metricsPathPrefix
metricsPathPrefix = "/host/var/run/ossfs/"
// defaultMetricsTop
defaultMetricsTop = "10"
)

const (
Expand Down Expand Up @@ -117,7 +119,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
opt := &Options{}
opt.UseSharedPath = true
opt.FuseType = OssFsType
opt.MetricsTop = "10"
for key, value := range req.VolumeContext {
key = strings.ToLower(key)
if key == "bucket" {
Expand Down Expand Up @@ -322,6 +323,10 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return nil, status.Errorf(codes.Aborted, "NodePublishVolume operation on shared path of volume %s already exists", req.VolumeId)
}
defer ns.sharedPathLock.Release(req.VolumeId)
utils.WriteSharedMetricsInfo(metricsPathPrefix, req, OssFsType, "oss", opt.Bucket, sharedPath)
if opt.MetricsTop != "" {
mountOptions = append(mountOptions, fmt.Sprintf("metrics_top=%s", opt.MetricsTop))
}
if err := doMount(ossMounter, sharedPath, *opt, mountOptions); err != nil {
log.Errorf("NodePublishVolume: failed to mount")
return nil, err
Expand All @@ -336,7 +341,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}
} else {
if opt.FuseType == OssFsType {
utils.WriteMetricsInfo(metricsPathPrefix, req, opt.MetricsTop, OssFsType, "oss", opt.Bucket)
metricsTop := defaultMetricsTop
if opt.MetricsTop != "" {
metricsTop = opt.MetricsTop
}
utils.WriteMetricsInfo(metricsPathPrefix, req, metricsTop, OssFsType, "oss", opt.Bucket)
}
if err := doMount(ossMounter, mountPath, *opt, mountOptions); err != nil {
return nil, err
Expand Down
17 changes: 17 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package utils

import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -911,6 +912,22 @@ func IsPathAvailiable(path string) error {
return nil
}

func WriteSharedMetricsInfo(metricsPathPrefix string, req *csi.NodePublishVolumeRequest, clientName string, storageBackendName string, fsName string, sharedPath string) {
mountPointPath := filepath.Join(metricsPathPrefix, fmt.Sprintf("%x", sha256.Sum256([]byte(req.GetVolumeId()))))
mountPointName := "mount_point_info"
if !IsFileExisting(mountPointPath) {
_ = os.MkdirAll(mountPointPath, os.FileMode(0755))
}
if !IsFileExisting(filepath.Join(mountPointPath, mountPointName)) {
info := clientName + " " +
storageBackendName + " " +
fsName + " " +
req.GetVolumeId() + " " +
sharedPath
_ = WriteAndSyncFile(filepath.Join(mountPointPath, mountPointName), []byte(info), os.FileMode(0644))
}
}

func WriteMetricsInfo(metricsPathPrefix string, req *csi.NodePublishVolumeRequest, metricsTop string, clientName string, storageBackendName string, fsName string) {
podUIDPath := metricsPathPrefix + req.VolumeContext["csi.storage.k8s.io/pod.uid"] + "/"
mountPointPath := podUIDPath + req.GetVolumeId() + "/"
Expand Down