generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take over prometheus agent remote write config from PMO.
- Loading branch information
1 parent
2f6d694
commit 7bff1ba
Showing
13 changed files
with
327 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package password | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
) | ||
|
||
type Manager interface { | ||
GeneratePassword(length int) (string, error) | ||
} | ||
|
||
type SimpleManager struct { | ||
} | ||
|
||
func (m SimpleManager) GeneratePassword(length int) (string, error) { | ||
bytes := make([]byte, length) | ||
if _, err := rand.Read(bytes); err != nil { | ||
return "", err | ||
} | ||
return hex.EncodeToString(bytes), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package prometheusagent | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/pkg/errors" | ||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
||
"github.com/giantswarm/observability-operator/pkg/monitoring/mimir/querier" | ||
"github.com/giantswarm/observability-operator/pkg/monitoring/prometheusagent/shards" | ||
) | ||
|
||
func getPrometheusAgentRemoteWriteConfigName(cluster *clusterv1.Cluster) string { | ||
return fmt.Sprintf("%s-remote-write-config", cluster.Name) | ||
} | ||
|
||
func getServicePriority(cluster *clusterv1.Cluster) string { | ||
if servicePriority, ok := cluster.GetLabels()[servicePriorityLabel]; ok && servicePriority != "" { | ||
return servicePriority | ||
} | ||
return defaultServicePriority | ||
} | ||
|
||
// We want to compute the number of shards based on the number of nodes. | ||
func getShardsCountForCluster(ctx context.Context, cluster *clusterv1.Cluster, currentShardCount int) (int, error) { | ||
headSeries, err := querier.QueryTSDBHeadSeries(ctx, cluster.Name) | ||
if err != nil { | ||
// Verify that Prometheus is accessible. If not, return the default number of shards. | ||
var dnsError *net.DNSError | ||
if errors.As(err, &dnsError) { | ||
return shards.ComputeShards(currentShardCount, defaultShards), nil | ||
} | ||
return 0, errors.WithStack(err) | ||
} | ||
return shards.ComputeShards(currentShardCount, headSeries), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package prometheusagent | ||
|
||
import ( | ||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/giantswarm/observability-operator/pkg/monitoring/prometheusagent/remotewrite" | ||
) | ||
|
||
func readCurrentShardsFromConfig(configMap corev1.ConfigMap) (int, error) { | ||
remoteWriteConfig := remotewrite.RemoteWriteConfig{} | ||
err := yaml.Unmarshal([]byte(configMap.Data["values"]), &remoteWriteConfig) | ||
if err != nil { | ||
return 0, errors.WithStack(err) | ||
} | ||
|
||
return remoteWriteConfig.PrometheusAgentConfig.Shards, nil | ||
} | ||
|
||
func readRemoteWritePasswordFromSecret(secret corev1.Secret) (string, error) { | ||
remoteWriteConfig := remotewrite.RemoteWriteConfig{} | ||
err := yaml.Unmarshal(secret.Data["values"], &remoteWriteConfig) | ||
if err != nil { | ||
return "", errors.WithStack(err) | ||
} | ||
|
||
for _, rw := range remoteWriteConfig.PrometheusAgentConfig.RemoteWrite { | ||
if rw.Name == "prometheus-meta-operator" { | ||
return rw.Password, nil | ||
} | ||
} | ||
|
||
return "", errors.New("remote write password not found in secret") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package prometheusagent | ||
|
||
import ( | ||
"fmt" | ||
|
||
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" | ||
) | ||
|
||
func getPrometheusAgentRemoteWriteSecretName(cluster *clusterv1.Cluster) string { | ||
return fmt.Sprintf("%s-remote-write-secret", cluster.Name) | ||
} |
Oops, something went wrong.